How to read JPEG, GIF, and other images from memory on VC

Source: Internet
Author: User
This article from http://blog.csdn.net/hellogv/
First, this article is suitable for JPEG and GIF images that are transmitted over the network, because these images are transmitted in the form of byte arrays. Give the function directly, not to mention nonsense!
// ----------- Put the following two sentences in the header file definition # include "gdiplus. H "using namespace gdiplus; // ----------- the following code modifies the variable to its own variable and uses void readfrombuffer (char * video_data, int size) {gdiplusstartupinput m_gdiplusinput; ulong_ptr m_gdipluw.en; gdiplusstartup (& m_gdiplustoken, & m_gdiplusinput, null); // initialize GDI + ipicture * PPIC; istream * PSTM; // allocate global storage space hglobal = globalalloc (gmem_moveable, size ); lpvoid pvdata = NULL; // lock the allocation Memory block pvdata = globallock (hglobal); // copy the data packet video_data to pvdatamemcpy (pvdata, video_data, size); globalunlock (hglobal); createstreamonhglobal (hglobal, true, & PSTM ); ularge_integer limit EK; large_integer dlibmove = {0}; PSTM-> seek (dlibmove, stream_seek_set, & pseek); sleep (15 ); // mount the image file if (failed (oleloadpicture (PSTM, size, true, iid_ipicture, (lpvoid *) & PPIC) {// attached: if the image contained in the video_data array is incorrect, oleloadpicture is prone to read/write memory errors. PPIC-> r Elasticsearch (); PSTM-> release (); return;} image IMG (PSTM, 0); graphics mgraphics (getdc (hwnd); mgraphics. drawimage (& IMG, 0, 0, video_width, video_height); IMG. ~ Image (); // an error occurs in mgraphics .~ Graphics (); PPIC-> release (); PSTM-> release (); gdiplusshutdown (m_gdiplustoken); // destroy GDI +}

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.