When an image is flipped, how can I erase the previous image first?

Source: Internet
Author: User
How can I erase the previous figure Delphi/Windows SDK/API when I flip the image?
Http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061026103637202.html
For example, I want to flip the image, but after turning it over, the original image is still in progress, and the original image is stacked with the new image, Code As follows:


For I: = 0 to image1.width do
Begin
With rect1 do
Begin
Left: = I;
Top: = 0;
Right: = I + 1;
Bottom: = image1.height;
End;
With rect2 do
Begin
Left: = (image1.width)-i-1;
Top: = 0;
Right: = (image1.width)-I;
Bottom: = image1.height;
End;
Image1.canvas. copyrect (rect2, image1.canvas, rect1 );
End;

Shouldn't this problem be too difficult ~~~ Top again

Procedure tform1.bmp _ rotate (srcbmp, destbmp: tbitmap; angle: Extended );
VaR
C1x, c1y, c2x, c2y: integer;
P1x, p1y, P2x, p2y: integer;
Radius, N: integer;
ALPHA: extended;
C0, C1, C2, C3: tcolor;
Begin
If srcbmp. width> srcbmp. Height then
Begin
Destbmp. Width: = srcbmp. width;
Destbmp. Height: = srcbmp. width;
End
Else
Destbmp. Width: = srcbmp. height;
Destbmp. Height: = srcbmp. height;
// Convert the angle to the PI value
Angle: = (angle/180) * PI;
// Calculate the center point. You can modify it.
C1x: = srcbmp. Width Div 2;
C1y: = srcbmp. Height Div 2;
C2x: = destbmp. Width Div 2;
C2y: = destbmp. Height Div 2;
// Step number
If c2x <c2y then
N: = c2y
Else
N: = c2x;
Dec (n, 1 );
// Start Rotation
For P2x: = 0 to n do
Begin
For p2y: = 0 to n do
Begin
If P2x = 0 then
ALPHA: = PI/2
Else
ALPHA: = arctan2 (p2y, P2x );
RADIUS: = round (SQRT (P2x * P2x) + (p2y * p2y )));
P1x: = round (radius * Cos (angle + alpha ));
P1y: = round (radius * sin (angle + alpha ));

C0: = srcbmp. Canvas. pixels [c1x + p1x, c1y + p1y];
C1: = srcbmp. Canvas. pixels [c1x-p1x, c1y-p1y];
C2: = srcbmp. Canvas. pixels [c1x + p1y, c1y-p1x];
C3: = srcbmp. Canvas. pixels [c1x-p1y, c1y + p1x];

Destbmp. Canvas. pixels [c2x + P2x, c2y + p2y]: = C0;
Destbmp. Canvas. pixels [c2x-P2x, c2y-p2y]: = C1;
Destbmp. Canvas. pixels [c2x + p2y, c2y-P2x]: = c2;
Destbmp. Canvas. pixels [c2x-p2y, c2y + P2x]: = C3;
End;
Application. processmessages
End;
End;


Procedure tform1.button1click (Sender: tobject );
VaR
Newbmp: tbitmap;
Bitmap: tbitmap;
Angle: integer;
Begin
Bitmap: = tbitmap. Create;
Newbmp: = tbitmap. Create;
Screen. cursor: = crhourglass;
Newbmp. Assign (image1.picture. Bitmap );

Angle: = strtoint (inputbox ('rotate bitmap ', 'Enter the rotation angular', '90 '));
BMP _rotate (newbmp, bitmap, angle );
Image1.picture. bitmap. Assign (Bitmap );
Image1.left: = (self. Width Div 2)-(bitmap. Width Div 2 );
Image1.top: = (self. Height Div 2)-(bitmap. Height Div 2 );
Screen. cursor: = crdefault;
Newbmp. Free;
Bitmap. Free;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.