Use Delphi to change the pixel size of an image.

Source: Internet
Author: User
Tags bmp image
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.

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.