Implement the rotation of the picture in Delphi

zhaozj2021-02-16  46

I haven't been written for a long time, not because of many cherry tomatoes and eggs, but I don't have any real things to give you reference. But recently, when I gave a friend to make a project, I met the simple handling of the image in Delphi, so I kept finding information from the Internet, looking at the post of 9cbs, from my search results, many people will be in each A similar picture processing problem is encountered, but most of the received answers seems incomplete (because there are many no nature, maybe a personal habit, huh, I hope everyone can read this article, can be home Normal post rate). So I wrote the questions and solutions I have encountered below for everyone to refer, and you will welcome everyone to continue to shoot.

Write the problem I have to solve before formal content, and also makes the reader have a good positioning, which will not be annoyed because I am in the process of dealing. The main solution here is to rotate 90 degrees with the picture scanned by the scanner in Delphi, thereby obtaining a picture suitable for use, and because the picture is not properly grasped, it is necessary to make a simple scaling. My solution is entirely based on this request, because of the efficiency, the sharpness after the picture is considered, the benefits of bringing the benefits are that the program looks simple.

First of all, I have no scanner, so I don't know what the picture obtained using the scanner (already provided) is in the format, and in the help of Delphi, "A Bitmap is a Powerful Graphics Object Used to Create, Manipulate (Scale, Scroll, Rotate, And Paint), And Store Images in Memory and as Files On A Disk, so my first step is to turn my slice into Tbitmap. At the same time in the conversion format, I change the actual size of the picture to suit the need for partial images. The function is as follows:

procedure TMainForm.ChangeImageFormate; var Bitmap: TBitmap; Zoom: Integer; begin Bitmap: = TBitmap.Create; // 1 try with ImageCert do begin Bitmap.Assign (Picture.Graphic); // 2 Picture: = nil; // 3 ZOOM: = Max (Bitmap.width Div Height) 1; // 4 width: = Bitmap.width Div Zoom; // 5 Height: = Bitmap.Height Div Zoom; // 6 canvas.stretchDRAW (RECT (0, 0, Width, Height), Bitmap); // 7 end; finally bitmap.free; end; end;

I think this code is not very complicated. Imagecert is a TIMAGE control on Form, the only possible strange is the eighth, but everyone can get it from the help of Delphi, I am not translated here. (My suggestion is to help). At the same time, it should be pointed out that the third sentence is critical. If you remove this sentence, if your image format is not BMP, it will appear "Only Bitmap can modify".

The second step is to implement the rotation of the picture, because the program requires only 90 degrees each time, so it is also easier to handle. The means of processing is to replace according to pixels. Process is as follows: procedure TMainForm.RotateImage; var x, y: Integer; TmpBitMap: TBitmap; begin TmpBitMap: = TBitmap.Create; try TmpBitMap.Assign (ImageCert.Picture.Graphic); with ImageCert do begin Picture.Bitmap.Height: = TmpBitMap.width; Picture.bitmap.width: = tmpbitmap.Height; for x: = 0 to height do for y: = 0 to width do canvas.pixels [tmpbitmap.height-x, y]: = TmpBitmap.canvas. Pixels [y, x]; height: = tmpbitmap.width; width: = tmpbitmap.Height; end; fin or tmpbitmap.free; end;

There is nothing to talk about this program, but several high and width settings make me boring, I always feel more, but I can't get any line, if I am interested, I can try it. It is best to tell me the results. And in this inside due to TIMAGE and TBITMAP have their own Canvas, which may also be worth researching, but because of time is limited.

As for the process of partial graph, I used a TSHAPE, then set this TSHAP in the imageCert 'on mobile, this is not very sensitive, because when the mouse is on the Tshape of Tshape It will not play a role, fortunately the impact is not affected. At the same time, I took out some pictures below Tshape in the TSHAPE onmousedown event. At this time, if your image does not have a zoom processing, you will find that the removed picture and the location we see is not in harmonious (of course, if the TIMAGE does not correctly display the size of the picture).

It is certain that this method is not a good method, but at least it solves the problem.

Hey, I don't know the so-called.

Copyright: IDILENT website reproduced please indicate the author's other reprint, please contact the author (iDilent@yahoo.com.cn).

转载请注明原文地址:https://www.9cbs.com/read-24367.html

New Post(0)