Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - GIF transparency
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

GIF transparency

 Post Reply Post Reply
Author
Message
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Topic: GIF transparency
    Posted: 13 January 2007 at 6:58pm
Xtreme Toolkit Pro has a lot of classes, so before I try to implement this sh*t myself, I'm going to ask the gurus :)
 
GDI+/MFC gives us CImage - a quite handy class for image loading/saving. The problem is that it cannot draw a GIF correctly. The transparent parts are drawn in solid green.
 
My question is; is there a class in the library that can help in this case? All I want to do is to load a GIF with transparency and then paint it correctly.
 
Thanks!
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2007 at 3:23am
Hi,
try OleLoadPicture:
 
#include <olectl.h>
    
    HRESULT Load(LPCTSTR szFile)
    {
        CComPtr<IStream> pStream;
        
        // Load the file to a memory stream
        HRESULT hr = FileToStream(szFile, &pStream);

        if (SUCCEEDED(hr))
        {
            // Decode the picture
            hr = ::OleLoadPicture(
                    pStream,            // [in] Pointer to the stream that contains picture's data
                    0,                    // [in] Number of bytes read from the stream (0 == entire)
                    true,                // [in] Loose original format if true
                    IID_IPicture,        // [in] Requested interface
                    (void**)&m_pPicture // [out] IPictire object on success
                    );
        }

        return hr;
    }

    HRESULT DrawImg(HDC hdc, const RECT& rcBounds)
    {
        if (m_pPicture)
        {
            // Get the width and the height of the picture
            long hmWidth = 0, hmHeight = 0;
            m_pPicture->get_Width(&hmWidth);
            m_pPicture->get_Height(&hmHeight);

            // Convert himetric to pixels
            int nWidth    = MulDiv(hmWidth, ::GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
            int nHeight    = MulDiv(hmHeight, ::GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);

            // Display the picture using IPicture::Render
            return m_pPicture->Render(
                hdc,                            // [in] Handle of device context on which to render the image
                rcBounds.left,                    // [in] Horizontal position of image in hdc
                rcBounds.top,                    // [in] Vertical position of image in hdc
                rcBounds.right - rcBounds.left,    // [in] Horizontal dimension of destination rectangle
                rcBounds.bottom - rcBounds.top, // [in] Vertical dimension of destination rectangle
                0,                                // [in] Horizontal offset in source picture
                hmHeight,                        // [in] Vertical offset in source picture
                hmWidth,                        // [in] Amount to copy horizontally in source picture
                -hmHeight,                        // [in] Amount to copy vertically in source picture
                &rcBounds                        // [in, optional] Pointer to position of destination for a metafile hdc
                );
        }

        return E_UNEXPECTED;
    }
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post Posted: 14 January 2007 at 6:03am
Thanks! I'll give it a try.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.180 seconds.