CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Jul 2003
    Posts
    260

    How to load & save irregular dialog to bitmap?

    Hi all,

    Maybe I am just not geting it, but I have searched for the past 2 days, and I can't seem to find info on how to save an irregular dialog. There are 2 parts to my questions:

    1. If I am given a circular-shaped png file, how do I size the dialog to match that? I know for bitmap, there is a color masking for transparency, unfortunately, I don't know how to do this for PNG format.

    2. Since a dialog can have 2 circular pngs, so once I can load the png, I will be then having the ()() shape, how do I save that as a bitmap? For paint, it captures the irregular image as is, how do I do that?

    PS: Please elaborate. I came across GetRegionData, but not sure if this is what I needed, on top of everything else.

    Thanks!

    Jiac

  2. #2
    Join Date
    Aug 2006
    Posts
    59

    Re: How to load & save irregular dialog to bitmap?

    I don't sure what are you looking for, but I guess CxImage source has all that you need to handle and convert png.

    This amazing open-source takes care of almost all image formats, with seperate C++ classes for each format!

    address: http://www.codeproject.com/bitmap/cximage.asp

  3. #3
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    I have came across this project before, but shamelessly to say is that to my confusion, how do I use it?

    To load the png which will affect the shape of my dialog, and to save the irregular-shaped dialog to a bitmap, like paint's screen capture.

    Thanks,
    Jiac

  4. #4
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    To further illustrate what I need help on, please see this link.
    http://www.codeguru.com/Cpp/W-D/disl...icle.php/c4977

    the difference is, I want to load PNG instead. Thanks!

  5. #5
    Join Date
    Aug 2001
    Posts
    507

    Re: How to load & save irregular dialog to bitmap?

    Here is an example of exactly what you are trying to do.

    Exact example

    now remains the question of making the CRgn object from the png file.

    here is how

    If you go through the first example carefully, i dont think you will need to use the png file at all for circular dialogs.

    Enjoy
    If you found my reply to be useful, please dont hesitate to rate it.


    DO NOT kick the Axe if it doesnt fall on your foot.

    Salman

  6. #6
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    ( Thank you for your reply and taking the time to dig up the link.)

    I have looked over the first example on region creating and the 2nd one was actually what I based on loading the pngs. I think what I need to do is reverse of your suggestion. Perhaps I wasn't being clear.
    I need to dialog to shrink to the shape of the png, since png has transparency built into it, I have found that I could use alphaBlend to get load the png w/ transparency. This is what I based on and I can load one png ok:

    http://www.codeproject.com/gdi/pxalphablend.asp

    Unfortunately, I have > 1 transparent pngs to be loaded, so how would this get handled? They are attached to each other, right half circle A, left half circle B, how do I draw both AB on the screen? Is this thru CreateDIBSection?

    Thanks!
    Jiac

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to load & save irregular dialog to bitmap?

    Quote Originally Posted by jiac
    I have looked over the first example on region creating and the 2nd one was actually what I based on loading the pngs. I think what I need to do is reverse of your suggestion. Perhaps I wasn't being clear.
    I need to dialog to shrink to the shape of the png, since png has transparency built into it, I have found that I could use alphaBlend to get load the png w/ transparency.
    If you use alphablending, the image perhaps will be ok. But, the window itself will not be hollow. Do you understand what I am trying to say. For example, if you have a circle kind of image, with anything outside the circle being transparent per the PNG data, you might be able to draw it so. However, if you click on anywhere outside the circle , but within the window's rectangular bounds, the click will not go to the window underneath it , as you might expect, but will still go to the dialog since you have only painted it, but not really changed the dialog's region.

    Aren't you better off setting a particular color as transparent color and removing these areas from your dialog's region ?

  8. #8
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    Hi Kirants,
    I tried the sample code from http://www.codeproject.com/gdi/pxalphablend.asp
    and the dialog window resized according to the png's actual drawing, so the transparency part is not being blocked, unless I misunderstood you.
    so, the essential problem right now is how to load 2 pngs and display them both.

    PS: It is not up to me to decide what format to load... (feel my pain)
    PS2: Running out of time, please continue to help me.

    Thanks!

    JIac

  9. #9
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to load & save irregular dialog to bitmap?

    Quote Originally Posted by jiac
    Hi Kirants,
    I tried the sample code from http://www.codeproject.com/gdi/pxalphablend.asp
    and the dialog window resized according to the png's actual drawing, so the transparency part is not being blocked, unless I misunderstood you.
    What happens when you have the dialog showing and click in the transparent portion ?

  10. #10
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    Hi Kirants,
    Sorry for the delay.

    The portion is clicked through to whatever the underneath is, if it is another icon, it will invoke that.

    Here is what I put together in pngText.zip, please tell me how to fix it so it will display multiple pngs with transparency cut off. This only displays one.

    Thanks!
    Jiac
    Attached Files Attached Files

  11. #11
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    Hi all,

    My question now, essentially, is how to load more than 1 png on a dc? How do I specify that I want to load png1 at Rgn (0,0,100,100) and another at (100,100,200,200)?

    Is it to use SetClipRgn? I have tried that with no success, however.
    Code:
     
    	dcMemory.SelectClipRgn (&rgn1);
    	CBitmap *pOldBitmap= dcMemory.SelectObject(&bmp);
    
    	dcMemory.SelectClipRgn (&rgn2);
    	dcMemory.SelectObject(&bmp1);
    	dcMemory.SelectClipRgn (NULL);
    I figured I would have to load the pngs onto one dc, then do the updateLayer call for the transparency to show properly. If this is no the right approach, please advise one that is.

    PS: it is 4 in the morning on Sunday, please help....
    Thanks,
    jiac

  12. #12
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to load & save irregular dialog to bitmap?

    You are in the right path. You don't have to do anything with the clip regions.
    Alll you need to do is to BitBlt the image at different offsets before setting it to the UpdateLayeredWindow call.

    code below copies the same image of yours side by side. You can modify the code to use different bitmaps. Idea here was to use a second memory DC ( dcMemoryFinal ) which has the real expanded width i.e the widths of the 2 images you need combined ). Then, you will see that BitBlt is done twice, once at offset 0,0 and next at offset ( imagewidth,0). This dcMemoryFinal is then passed to UpdateLayeredWindow.

    Code:
    void CPngTestDlg::LoadPNG()
    {
    	//load background
    	TCHAR szCurrentPath [MAX_PATH];
    
    	strcpy (szCurrentPath, "res\\pngtest.png");
    	CT2W pszWCharString (szCurrentPath);
    	m_pBitmap = Gdiplus::Bitmap::FromFile(pszWCharString);
    	
    	int nImageWidth = m_pBitmap->GetWidth();
    	int nImageHeight = m_pBitmap->GetHeight();
    
    	CDC dcScreen,dcMemory, dcMemoryFinal;
    
    	dcScreen.Attach(::GetDC(NULL));
    	dcMemory.CreateCompatibleDC(&dcScreen);
       
    	//select the image to dcmemory
    	HBITMAP hBitmap = NULL;
    	m_pBitmap->GetHBITMAP(RGB(0,0,0),&hBitmap );
    
    	CBitmap bmp;
    	BOOL bSuccess = bmp.Attach(hBitmap);
    
    	CBitmap *pOldBitmap = dcMemory.SelectObject(&bmp);
    
    	//create an expanded bitmap	( double the width )
    	dcMemoryFinal.CreateCompatibleDC(&dcMemory);
        CBitmap oBmp;
    	oBmp.CreateCompatibleBitmap(&dcScreen,nImageWidth*2,nImageHeight);
    
    	CBitmap *pOldBitmap2 = dcMemoryFinal.SelectObject(&oBmp);
    
    	//BitBlt dcmemory contents at 0,0
        BOOL b = dcMemoryFinal.BitBlt(0, 0, nImageWidth, nImageHeight,
                 &dcMemory, 0, 0, SRCCOPY);
    	//BitBlt dcmemory contents at imagewidth,0
    	b = dcMemoryFinal.BitBlt(nImageWidth, 0, nImageWidth, nImageHeight,
                 &dcMemory, 0, 0, SRCCOPY);
    
    	//set the layered window properties
    	ModifyStyleEx(0, WS_EX_LAYERED);
    	// get the window rectangule (we are only interested in the top left position)
    	CRect rectDlg;
    	GetWindowRect(rectDlg);
    
    	// calculate the new window position/size based on the bitmap size
    	CPoint ptWindowScreenPosition(rectDlg.TopLeft());
    
    	CSize szWindow(nImageWidth*2,nImageHeight );
    
    	// setup the blend function
    	BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
    	CPoint ptSrc(0,0); // start point of the copy from dcMemory to dcScreen
    
    	// perform the alpha blend
    	BOOL bRet= ::UpdateLayeredWindow(this->GetSafeHwnd (), dcScreen, &ptWindowScreenPosition, &szWindow, dcMemoryFinal,
    		&ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
    	
    	// clean up
    	dcMemoryFinal.SelectObject(pOldBitmap2);
    	dcMemory.SelectObject(pOldBitmap);
    }

  13. #13
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    Kirants,
    Thanks! That helps!! Thank you so much for helping.

    I have another question, please tell me how to handle having controls? I want to put some CStatic controls on this dialog, but it doesn't show the controls. For examplen the default dialog has "OK" "Cancel" buttons, but after PNG is loaded, they are not shwn. so how do I perserve these buttons so they will appear on the png background?


    Thanks again,
    Jiac

  14. #14
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: How to load & save irregular dialog to bitmap?

    Quote Originally Posted by jiac
    Kirants,
    Thanks! That helps!! Thank you so much for helping.
    You are welcome
    I have another question, please tell me how to handle having controls? I want to put some CStatic controls on this dialog, but it doesn't show the controls. For examplen the default dialog has "OK" "Cancel" buttons, but after PNG is loaded, they are not shwn. so how do I perserve these buttons so they will appear on the png background?
    I haven't used UpdateLayeredWindow anytime before, so I may be wrong in what I am going to say. I have googled for this API and it appears that the UpdateLayeredWindow doesn't work well with child controls.

    There are ways to do what you want. But, it will be slightly long winded.

  15. #15
    Join Date
    Jul 2003
    Posts
    260

    Re: How to load & save irregular dialog to bitmap?

    Hi Kirants,
    Can you elaborate on the other ways to do what I wanted? Please....

    You are leaving me hanging with that last statement.

    Thanks again,
    Jiac

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured