Home > Back-end >  How to let the image 90 degrees counterclockwise, or rotate it 270 degrees? Thank you very much!
How to let the image 90 degrees counterclockwise, or rotate it 270 degrees? Thank you very much!

Time:10-01

Found a piece of code on the net, this should be the fastest (do not use GDI +), especially for a larger version, but it is rotated 90 degrees, how to make it spin - 90 degrees, tall person to give directions, thank you first!

Procedure Rotate270 (Bitmap: TBitmap);
Var
AStream: TMemorystream;
//memory flow
Header: TBITMAPINFO;
Dc: hDC.
P: ^ THelpRGB;
X, y, w, h: Integer;//w width, height h
RowOut: pRGBArray;
The begin
//create a memory stream
AStream:=TMemoryStream. Create;
//set size, must be in multiples of 4
AStream. SetSize (Bitmap. The Bitmap Height *. Width * 4);
With the header. The bmiHeader do//bitmap file
The begin
BiSize:=SizeOf (TBITMAPINFOHEADER);//size
BiWidth:=Bitmap. The Width;//bitmap width
BiHeight:=Bitmap. The Height;//bitmap high
BiPlanes:=1;
BiBitCount:=32;
//no compression
BiCompression:=0;
BiSizeimage:=aStream. Size;
BiXPelsPerMeter:=1;//horizontal resolution
BiYPelsPerMeter:=1;//vertical resolution
BiClrUsed:=0;
BiClrImportant:=0;
end;
Dc:=GetDC (0);
P:=aStream. The Memory;
GetDIBits (dc, Bitmap. The Handle, 0, Bitmap. The Height, P, header, dib_RGB_Colors);
ReleaseDC (0, dc);
H:=bitmap. The Height;//source high figure
W:=bitmap. The Width;//source map width
//specify to create bitmap size
Bitmap. Width:=h;
Bitmap. Height:=w;
For: y=0 to (w - 1) do
The begin
RowOut:=Bitmap. ScanLine [y];//get the new bitmap information
P:=aStream. The Memory;//set the file pointer
Inc (p, y);//pointer shift
For: x=0 to (h - 1) do
The begin
Rowout [x] :=p ^. RGB.//data transfer
Inc (p, w);
end;
end;
AStream. Free;//release resources
end;

CodePudding user response:

Procedure TForm1. Button1Click (Sender: TObject);
Var
WicImg: TWICImage;
The Factory: IWICImagingFactory; {class factory interface}
FlipRotator: IWICBitmapFlipRotator; {rotation transformation interface}
The begin
{establish TWICImage first class and load the picture}
WicImg:=TWICImage. Create;
WicImg. LoadFromFile (' c: \ temp \ test. JPG); {get class factory interface}
The Factory:=WicImg. ImagingFactory; {let plants rotation transformation interface}
Factory. CreateBitmapFlipRotator (FlipRotator); {perform rotation transformation, here is the rotation Angle of 90 degrees; Note data after the rotation in FlipRotator}

FlipRotator. The Initialize (WicImg. Handle, WICBitmapTransformRotate270); The image in {update TWICImage}
WicImg. Handle:=IWicBitmap (FlipRotator); {at}
Canvas. The Draw (0, 0, WicImg); Released {}
FlipRotator:=nil; The Factory:=nil; WicImg. Free;
end;//or the above procedures, gave some return value judgment procedure TForm1. Button2Click (Send

CodePudding user response:

USES Wincodec

CodePudding user response:

Thank you for your reply, upstairs haven't read it, slowly study,

In addition I the above code Rotate270 (Bitmap: TBitmap), 270 should be 90, forget to change, I am want to change on the original code to rotate 270 degrees, the result not to get into,

CodePudding user response:

Remember there are directly under the Windows API for image deformation of the API

CodePudding user response:

According to the file format to manipulate files directly,

CodePudding user response:

Use gdi +, otherwise very trouble,

CodePudding user response:

Good learning how to learn
  • Related