Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <GdiPlusFlat.h>
  3.  
  4. #define CHECK(x) do { if (x != 0) { fprintf(stderr, "Got %d\n", x); } } while (0)
  5.  
  6. int
  7. main(int argc, char **argv)
  8. {
  9.     FILE *f, *out;
  10.     float f_width, f_height;
  11.     int width, height, x, y, pos;
  12.     int *data;
  13.     BYTE *scan0;
  14.     GpStatus st;
  15.     GpImage *img;
  16.     GpBitmap *bitmap;
  17.     GpGraphics *graphics;
  18.     GpRect rect;
  19.     BitmapData bmpdata;
  20.  
  21.     if (argc != 3) {
  22.         return 1;
  23.     }
  24.  
  25.     if (!(f = fopen(argv[1], "r"))) {
  26.         return 1;
  27.     }
  28.     st = gdip_load_emf_image_from_file(f, &img);
  29.     fprintf(stderr, "status = %d, %s\n", st, argv[1]);
  30.     if (st == 0) {
  31.         fprintf(stderr, "Loaded.\n");
  32.         CHECK(GdipGetImageDimension(img, &f_width, &f_height));
  33.         fprintf(stderr, "%f %f\n", f_width, f_height);
  34.  
  35.         /* XXX Scale down image. */
  36.         width = f_width * 0.01;
  37.         height = f_height * 0.01;
  38.  
  39.         scan0 = GdipAlloc(width * height * 4);
  40.         CHECK(GdipCreateBitmapFromScan0(width, height, width * 4,
  41.                     PixelFormat32bppARGB, scan0, &bitmap));
  42.         CHECK(GdipGetImageGraphicsContext(bitmap, &graphics));
  43.  
  44.         if (!GdipDrawImageRect(graphics, img, 0, 0, (float)width, (float)height)) {
  45.             if (!(out = fopen(argv[2], "wb"))) {
  46.                 return 1;
  47.             }
  48.             CHECK(gdip_save_bmp_image_to_file(out, img));
  49.             fclose(out);
  50.         }
  51.  
  52.         GdipDisposeImage(bitmap);
  53.         GdipFree(scan0);
  54.         GdipDisposeImage(img);
  55.     }
  56.     fclose(f);
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement