Results 1 to 9 of 9

Thread: BitBlt Tutorials

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    BitBlt Tutorials

    Are there any good starting bitblt tutorials? Vlatkos faq has seemed to have disappeared...Thanks!

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    winprog's isn't working for me
    it works but whenever I try to put it in another project it bombs...and is there a way to have a transparent bitmap but loaded from a file instead of from a resource file?

    Im really lookng to just make this a class for easy use.

  3. #3
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    If you are ready to read an entire book, then there is a whole chapter on it in the 'Programming Windows' by Charles Petzold.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  4. #4
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Here is a real basic tutorial I made awhile back. There is a html file in there that is the acutal tutorial. I am not sure if it is the complete one anymore. The real one was on my site before my ISP destroyed it. I hope this helps
    Attached Files Attached Files
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  5. #5
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Also here is some code from an old project of mine that has a transparent bitmap. You can probably figure it out

    Code:
    /*###########################################################################################*/
    
    /*
    ======================================================================================
    
    Name:	DrawTransparentBitmap
    
    Return:	None
    
    In:		HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor 
    
    Notes:	hdc Of The Device To Paint To, hBitmap Is The Bitmap To Be Transparent, XandYShort 
    		Is The X and Y To Paint On The Device, Color Is The Color To Make Transparent
    
    ======================================================================================
    */
    
    void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap,  short xPaint, short yPaint, short xStart, short xEnd, COLORREF cTransparentColor)
    {
    /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
    	HDC			hdcMem	= CreateCompatibleDC(0);
    
    	HBITMAP		hbmColour, 
    				hbmMask;
    /*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
    	
    	//Get The Orginal Bitmap
    	hbmColour = hBitmap;
    
    	//Get The Mask, Make All Perfect Red Tansparent
    	hbmMask = CreateBitmapMask(hbmColour, cTransparentColor,xStart, xEnd);
    
    	if(xStart == -1)
    	{
    		//Get The Passed In Bitmap Info
    		BITMAP bm;
    		GetObject(hbmColour, sizeof(BITMAP), &bm);
    
    		//BitBlt The Mask Image To The Screen
    		SelectObject(hdcMem, hbmMask);
    		BitBlt(hdc, xPaint, yPaint, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCAND);
    
    		//BitBlt The Orginal Over The Mask
    		SelectObject(hdcMem, hbmColour);
    		BitBlt(hdc, xPaint, yPaint, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);
    	}
    	else
    	{
    		//BitBlt The Mask Image To The Screen
    		SelectObject(hdcMem, hbmMask);
    		BitBlt(hdc, xPaint, yPaint, xEnd, 45, hdcMem, xStart, 0, SRCAND);
    
    		//BitBlt The Orginal Over The Mask
    		SelectObject(hdcMem, hbmColour);
    		BitBlt(hdc, xPaint, yPaint, xEnd, 45, hdcMem, xStart, 0, SRCPAINT);
    	}
    
    	//Clean Up
    	DeleteDC(hdcMem);
    	DeleteObject(SelectObject(hdcMem, hbmMask));
    	DeleteObject(SelectObject(hdcMem, hbmColour));
    
    } 
    
    
    
    
    
    /*###########################################################################################*/
    
    /*
    ======================================================================================
    
    Name:	CreateBitmapMask
    
    Return:	HBITMAP
    
    In:		HBITMAP hbmColour, COLORREF crTransparent 
    
    Notes:	Returns The Mask For The Previous Function
    		Function Was Not Created By Me
    
    ======================================================================================
    */
    
    HBITMAP CreateBitmapMask(HBITMAP hbmColour, COLORREF crTransparent,short xStart, short xEnd)
    {
    	HDC hdcMem, hdcMem2;
    	HBITMAP hbmMask;
    	BITMAP bm;
    
    	/*
    		Create mask bitmap.
    	*/
    	GetObject(hbmColour, sizeof(BITMAP), &bm);
    	hbmMask = CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL);
    
    	hdcMem	= CreateCompatibleDC(0);
    	hdcMem2 = CreateCompatibleDC(0);
    
    	SelectObject(hdcMem, hbmColour);
    	SelectObject(hdcMem2, hbmMask);
    
    	/*
    		Set the background colour of the colour image to the colour
    		you want to be transparent.
    	*/
    	SetBkColor(hdcMem, crTransparent);
    	/*
    		Copy the bits from the colour image to the B+W mask... everything
    		with the background colour ends up white while everythig else ends up
    		black...Just what we wanted.
    	*/
    	BitBlt(hdcMem2, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    	/*
    		Take our new mask and use it to turn the transparent colour in our
    		original colour image to black so the transparency effect will
    		work right.
    	*/
    	BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem2, 0, 0, SRCINVERT);
    	
    	//Clean up.
    	DeleteDC(hdcMem);
    	DeleteDC(hdcMem2);
    
    	return hbmMask;
    }
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Where is the CreateBitmapMask from? It seems familiar to me.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I think Megatron gave it to me.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    i think I got it from microsoft...i did a search on google for something and I found that

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think I read it in "Programming Windows with MFC"...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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