Use Delphi to change the image pixel size. code is required! Urgent. Thank you! I will give you a very simple method:
Step 1: Put the image1 and image2 image controls on the form. Put another button control.
Step 2: load a jpg or BMP image in the picture attribute of image1. Image2 does not care about it.
Step 3: double-click the button to edit the environment by clicking the button. Write the following code:
Image2.height: = 200; // New Image Height
Image2.width: = 300; // The width of the new image.
Image2.canvas. stretchdraw (image2.clientrect, image1.picture. Graphic );
Image2.picture. savetofile ('C:/B .jpg '); // Save the new image
The answer is complete. Please give the score immediately after the test is correct. Don't drag the time.
You didn't talk about compression, so I didn't write the compressed code. In fact, it is best to compress the code. The compressed code is also very simple (because I don't like the code that is too long). If you need to compress the code, please add it to my handler 555044
Dizzy ........ I don't know ......
Add jpeg to uses.
VaR
BMP, BMP 1: tbitmap;
JPEG: tsf-image;
STR: string;
Begin
STR: = 'complete path of your image + image name'
If (extractfileext (STR) = '. jpg') or (extractfileext(str){'.jpg ') then
Begin
JPEG: = tsf-image. Create;
Try
JPEG. loadfromfile (STR );
BMP: = tbitmap. Create;
Try
BMP. Width: = strtoint (edit1.text );
BMP. Height: = strtoint (edit2.text );
BMP. Canvas. stretchdraw (rect (0, 0, BMP. Width, BMP. Height), JPEG );
JPEG. Assign (BMP );
Finally
BMP. Free;
End;
JPEG. savetofile ('d:/aa.jpg ');
Finally
JPEG. Free;
End;
End;
End;
If (extractfileext (STR) = '. BMP') or (extractfileext(str){'.bmp ') then
Begin
BMP 1: = tbitmap. Create;
Try
BMP 1.loadfromfile (STR );
BMP: = tbitmap. Create;
Try
BMP. Width: = strtoint (edit1.text );
BMP. Height: = strtoint (edit2.text );
BMP. Canvas. stretchdraw (rect (0, 0, BMP. Width, BMP. Height), BMP 1 );
BMP 1.assign (BMP );
Finally
BMP. Free;
BMP 1.savetofile ('d:/aa.bmp ');
End;
Finally
BMP 1.free;
End;
End;
End;
Only the width and height of the BMP added in edit1 and edit2 are not too large. Otherwise, the error "insufficient storage space" may occur. The specific value is beyond the limit. You can give it a try for specific analysis.