Home > Software engineering >  Vb6 operation image files
Vb6 operation image files

Time:09-27

How to realize the computer image files in vb6 clockwise and anti-clockwise rotate 90 degrees and then save the rotated image file does not change the file size you just rotate

CodePudding user response:

For reference only (although is a c + +) :
 # include & lt; Math. H> 
#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 (& amp; Num, & amp; The 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 & lt; num; + + 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 (argc<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 (& amp; Gdiplustoken, & amp; 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", & amp; 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 (& amp; Img);
Bitmap BMP ((UINT) size, (UINT) size, & amp; The TGP);//Let BMP Resolution equal to img Resolution
Graphics gp (& amp; BMP);
Gp. SetTransform (& amp; Mat);
Gp. DrawImage (& amp; Img, pfTL);
REAL xmin, ymin, xmax, ymax, x, y, rw, rh;
Mat. TransformPoints (& amp; PfTL);
Xmin=xmax=pfTL. X;
Ymin=ymax=pfTL. Y;
Mat. TransformPoints (& amp; PfTR);
If (xmin> Xmin pfTR. X)=pfTR. X;
If (xmaxIf (ymin> Ymin pfTR. Y)=pfTR. Y;
If (ymaxMat. TransformPoints (& amp; PfBL);
If (xmin> Xmin pfBL. X)=pfBL. X;
If (xmaxIf (ymin> Ymin pfBL. Y)=pfBL. Y;
If (ymaxMat. TransformPoints (& amp; PfBR);
If (xmin> Xmin pfBR. X)=pfBR. X;
If (xmaxIf (ymin> Ymin pfBR. Y)=pfBR. Y;
If (ymaxX=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 & lt;=GetEncoderClsid (formats [I], & amp; EncoderClsid)) {
If (Ok==clone - & gt; Save (argv [2], & amp; 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