GDI + loads GIF images (convert byte * To istream)

Source: Internet
Author: User

Today, I encountered the problem of using GDI + to load image streams. I couldn't find a lot of information on the Internet, and other frames were always blurred ,,

The online method code is as follows:

Note: pimagedata is of the byte * type and dimagelen is of the DWORD type;

Hglobal m_hmem = globalalloc (gmem_fixed, dimagelen); byte * pmem = (byte *) globallock (m_hmem); memcpy (pmem, pimagedata, dimagelen); istream * PSTM; hresult ht = createstreamonhglobal (m_hmem, false, & PSTM); If (ht! = S_ OK) {globalfree (m_hmem); return;} m_pimage = gdiplus: Image: fromstream (PSTM); globalunlock (m_hmem); PSTM-> release (); globalfree (m_hmem); If (m_pimage) {uint COUNT = m_pimage-> getframedimensionscount (); If (count> 0 & m_pimage-> getlaststatus () = 0) {m_pdimensionids = new guid [count]; m_pimage-> getframedimensionslist (m_pdimensionids, count); wchar strguid [39]; stringfromguid2 (m_pdimensionids [0], strguid, 39 ); m_framecount = m_pimage-> getframecount (& m_pdimensionids [0]); uint totalbuffer = m_pimage-> getpropertyitemsize (bytes); m_pitem = (gdiplus: propertyitem *) malloc (totalbuffer ); m_pimage-> getpropertyitem (propertytagframedelay, totalbuffer, m_pitem); m_bstatok = true ;}}

Always draw a method to solve the problem after the problem occurs. The Code is as follows:

Note: m_pstream is a class member and is released during class analysis. pimagedata is of the byte * type and dimagelen is of the DWORD type;

If (createstreamonhglobal (null, true, & m_pstream) = s_ OK) {ulong ulwritten = 0; m_pstream-> write (pimagedata, dimagelen, & ulwritten ); // rewind the argument stream; large_integer Lint; lint. quadpart = 0; m_pstream-> seek (lint, stream_seek_set, null); // read The lenght of the argument stream; statstg; long dwresult = m_pstream-> Stat (& statstg, statflag_default); If (dwresult! = S_ OK) {return;} m_pimage = gdiplus: Image: fromstream (m_pstream); If (m_pimage) {uint COUNT = m_pimage-> getframedimensionscount (); if (count> 0 & m_pimage-> getlaststatus () = 0) {m_pdimensionids = new guid [count]; m_pimage-> getframedimensionslist (m_pdimensionids, count ); wchar strguid [39]; stringfromguid2 (m_pdimensionids [0], strguid, 39); m_framecount = m_pimage-> getframecount (& m_pdimensionids [0]); uint totalbuffer = m_pimage-> getpropertyitemsize (bytes); m_pitem = (gdiplus: propertyitem *) malloc (totalbuffer); m_pimage-> getpropertyitem (bytes, totalbuffer, m_pitem ); m_bstatok = true ;}}}

In this way, other frames can be drawn through the timer without image imaging.

DrawGif(HDC hDC, const RECT& rc) {if (NULL == m_pItem)return 0;    m_pImage->SelectActiveFrame(&Gdiplus::FrameDimensionTime, m_iCurrentFrame);    unsigned msec = ((int*)m_pItem->value)[m_iCurrentFrame] * 10;Graphics g( hDC );g.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);g.DrawImage( m_pImage, rc.left, rc.top, rc.right-rc.left, rc.bottom - rc.top );    return msec;}

  

 

GDI + loads GIF images (convert byte * To istream)

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.