Let's take a look at this image conversion function. Why is it normal when BMP is converted to JPG? When JPG is converted to JPG, Delphi does not know the converted image.

Source: Internet
Author: User
Tags bmp image
Let's take a look at this image conversion function. Why is it normal when BMP is converted to JPG? When JPG is converted to JPG, Delphi doesn't know it. Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061024164425208.html
Function pictureresiz (afilename {source image}, dfilename {converted image}: string): string;
VaR
Image: tpicture;
BMP, tmpbmp: tbitmap;
Adesiredfilename: string;
Begin
Image: = tpicture. Create;
BMP: = tbitmap. Create;
Tmpbmp: = tbitmap. Create;
Try
Image. loadfromfile (afilename );
BMP. Assign (image. Graphic );
Tmpbmp. Width: = liwidth; // specify the image width.
Tmpbmp. Height: = liheight; // specify the Image Height
Setstretchbltmode (tmpbmp. Canvas. Handle, stretch_deletescans); // Smooth Processing
Stretchblt (tmpbmp. Canvas. Handle, 0, 0, tmpbmp. Width, tmpbmp. height,
BMP. Canvas. Handle, 0, 0, BMP. Width, BMP. Height, srccopy );
Image. Graphic. Assign (tmpbmp );
Adesiredfilename: = dfilename;
If fileexists (adesiredfilename) Then deletefile (adesiredfilename );

Image. savetofile (adesiredfilename );
Result: = adesiredfilename;
Finally
BMP. Free;
Tmpbmp. Free;
Image. Free;
End;
End;

First, determine whether the file is BMP or JPG.
Then process them separately.
Uses
JPEG;

//--------------------
VaR
Myjpeg: tsf-image;
Mybitmap: tbitmap;
Begin
Mybitmap: = tbitmap. Create ();
Myjpeg: = tsf-image. Create ();
Mybitmap. loadfromfile ('C: \ windows \ Desktop \ AA. BMP '); // load the bitmap from a file
Myjpeg. Assign (mybitmap); // assign the bitmap to myjpeg object
// Myjpeg. Canvas. stretchdraw (trect (0, 0, nimagewidth, nimageheight), mybitmap );
Myjpeg. compressionquality: = strtoint ('75 ');
Myjpeg. Compress;
Myjpeg. savetofile ('C: \ windows \ Desktop \ test. jpg '); // Save the JPEG to disk
End;

Convert JPG to BMP and write it in turn.

The image size also needs to be changed during conversion. happyggy (tobject says: I am a god ~~~), YourCodeYou cannot set the image size. For example, to convert a jpg or BMP image of 500*500 to a jpg image of 100*100.

Add a variable
// ==================================
VaR
Myjpeg: tsf-image;
Mybitmap: tbitmap;
Desbitmap: tbitmap;
Begin
Myjpeg: = tsf-image. Create;
Mybitmap: = tbitmap. Create;
Desbitmap: = tbitmap. Create;
Myjpeg. loadfromfile ('C: \ 123.jpg ');
Mybitmap. Assign (myjpeg );
Desbitmap. Height: 100;
Desbitmap. Width: = 100;
Desbitmap. Canvas. copyrect (desbitmap. Canvas. cliprect, mybitmap. Canvas, mybitmap. Canvas. cliprect );
Image1.picture. Bitmap: = desbitmap;
Mybitmap. Free;
Myjpeg. Free;
Desbitmap. Free;
End;

Add group 32179979 or 26929954

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.