Cximage memory conversion Image

Source: Internet
Author: User

Recently, it is required to convert BMP to JPEG format. Previously, we used the GDI + method. This method has a major defect in that it cannot implement cross-platform processing. If you have less time to talk about it, go to the topic.

Cximage cximagebmp (prgbbuffer, dwrgbsize, cximage_format_bmp );

Cximagebmp. Save ("D: \ ttt.jpg", cximage_format_jpg );

This method is normal. The 24-bit BMP image in RGB format is successfully converted to a local JPG file and saved.

 

However, the following memory conversion method fails.

Byte * pjpgdatatemp = new byte [1024*1024];

Int ljpgsize = 0;

Bool B = cximagebmp. encode (pjpgdatatemp, ljpgsize, cximage_format_jpg );

On the one hand, the return value of the function is false; on the other hand, the Data Length, ljpgsize is 0.

 

Later, the modification was successful.

Byte * pjpgdatatemp = NULL;

Int ljpgsize = 0;

Bool B = cximagebmp. encode (pjpgdatatemp, ljpgsize, cximage_format_jpg );

 

Why? We can view the following information from the cximage: encode () Definition:

Bool cximage: encode (byte * & buffer, long & size, DWORD imagetype)
{
If (buffer! = NULL)

{
Strcpy (info. szlasterror, "the buffer must be empty ");
Return false;
}

Cxmemfile file;
File. open ();
If (encode (& file, imagetype ))

{
Buffer = file. getbuffer ();
Size = file. Size ();
Return true;
}

Return false;
}

The truth is clear!

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.