Home > Back-end >  The C program how to run?
The C program how to run?

Time:09-20

H # include
# include
# include
# include
# include
# pragma comment (lib, "gdiplus. Lib")
Using the namespace Gdiplus;
Would be formats [5] [11]={
L "image/BMP,"
L "image/jpeg",
L "image/GIF",
L "image/tiff,"
L "image/PNG,"
};
Would be exts [5] [5]={
L ". BMP, "
L "JPG",
L ". GIF ",
L ". Tif, "
L "PNG",
};
Int GetEncoderClsid (const WCHAR * format, clsids * pClsid) {
UINT num=0;//number of image encoders
UINT size=0;//the size of the image encoder array in bytes
ImageCodecInfo * pImageCodecInfo=NULL;
GetImageEncodersSize (& num, & size);
If (size==0) return 1;//Failure
PImageCodecInfo=(ImageCodecInfo *) (malloc (size));
If (pImageCodecInfo==NULL) return 1;//Failure
GetImageEncoders (num, size, pImageCodecInfo);
For (UINT j=0; J If (WCSCMP (pImageCodecInfo [j]. Journal of MimeType, format)==0) {
* pClsid=pImageCodecInfo [j]. Journal of clsids;
Free (pImageCodecInfo);
Return j;//Success
}
}
Free (pImageCodecInfo);
return -1;//Failure
}
Int wmain (int arg c, would be * argv []) {
Int r=1;
If (arg c <4) {
USAGE:
Srcimg wprintf (L "% s. {BMP | JPG | | GIF tif | PNG | WMF | emf | ico} desimg. {BMP | JPG | | GIF tif | PNG} Angle \ n", argv [0]).
return r;
}
int i;
for (i=0; i<5; I++) {
If (0==_wcsicmp (argv [1] + wcslen (argv [1]) - 4, exts [I])) break;
}
If (I>=5) goto the USAGE;
for (i=0; i<5; I++) {
If (0==_wcsicmp (argv [2] + wcslen (argv [2]) - 4, exts [I])) break;
}
If (I>=5) goto the USAGE;
The GdiplusStartupInput GdiplusStartupInput;
ULONG_PTR gdiplustoken;
GdiplusStartup (& gdiplustoken, & gdiplusstartupinput, NULL);
{
The Image of img (argv [1]);
If (Ok==img. GetLastStatus ()) {
UINT height=img. GetHeight ();
UINT width=img. GetWidth ();
The REAL Angle;
If (1==swscanf_s (argv [3], L "% f", & Angle)) {
REAL size.
Size=(REAL) SQRT (1.0 * width * height width + 1.0 * * height);
Matrix mat;
Mat. Translate (size/2.0 f, size/2.0 f);
Mat. Rotate (- Angle, MatrixOrderAppend);
Mat. Translate (size/2.0 f, size/2.0 f, MatrixOrderAppend);
PointF pfTL (/2.0 f (size - the width), (f) 2.0/size - height);
PointF pfTR ((f + width 2.0/size - the width), (f) 2.0/size - height);
PointF pfBL ((size - the width) f/2.0, (the size - height)/2.0 f + height);
PointF pfBR ((size - the width)/2.0 f + width, (size - height)/2.0 f + height);
Graphics TGP (& img);
Bitmap BMP ((UINT) size, (UINT) size, & TGP);//Let BMP Resolution equal to img Resolution
Graphics gp (& BMP);
Gp. SetTransform (& mat);
Gp. DrawImage (& img, pfTL);
REAL xmin, ymin, xmax, ymax, x, y, rw, rh;
Mat. TransformPoints (& pfTL);
Xmin=xmax=pfTL. X;
Ymin=ymax=pfTL. Y;
Mat. TransformPoints (& pfTR);
If (xmin> pfTR. X) xmin=pfTR. X.
If (xmax If (ymin> pfTR. Y) ymin=pfTR. Y;
If (ymax Mat. TransformPoints (& pfBL);
If (xmin> pfBL. X) xmin=pfBL. X.
If (xmax If (ymin> pfBL. Y) ymin=pfBL. Y;
If (ymax Mat. TransformPoints (& pfBR);
If (xmin> pfBR. X) xmin=pfBR. X.
If (xmax If (ymin> pfBR. Y) ymin=pfBR. Y;
If (ymax X=xmin;
Y=ymin;
Rw=xmax - x;
Rh=ymax - y;
Bitmap * clone;
Clone=BMP. Clone (x, y, rw, rh, PixelFormat24bppRGB);//BMP. GetPixelFormat ()
Clsids encoderClsid;
If (0 <=GetEncoderClsid (formats [I], & encoderClsid)) {
If (Ok==clone -> Save (argv [2], & encoderClsid)) {
Wprintf (L "OK" % s % s to % s % s \ n ", argv [0], argv [1], argv [2], argv [3]).
R=0;
} else {
Wprintf (L "Error to save % s \ n", argv [2]).
R=4;
}
} else {
Wprintf (L "Error to GetEncoderClsid (% s,... ) \ n ", formats [I]);
R=3;
}
The delete clone;
} else {
Wprintf (L "Error to get Angle % s \ n", argv [3]).
R=2;
}
} else {
Wprintf (L "Error to the load % s \ n", argv [1]).
R=5;
}
}
GdiplusShutdown (gdiplustoken);
return r;
}
  • Related