How to fill a Rectangle with a Bitmap Resource using GDI+

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Qm9iS » Sun, 29 Jul 2007 01:30:01


I need to use custom bitmaps with a GDI+ Brush but this seems to be
undocumented. I am using VS6 MFC.

I need a different pattern than available in HatchBrush.
TextureBrush will load a bitmap from an Image, but Image loads a bitmap from
a file, not a resource.


IN GDI, I can do the following:
===================
CBitmap m_Bitmap56;
CBrush m_Brush56;
//
m_Bitmap56.LoadBitmap(IDB_56PERCENT);
m_Brush56.CreatePatternBrush(&m_Bitmap56);
...
m_pDC->SelectObject(&m_Brush56);
m_pDC->PatBlt(Rect.left,Rect.top,Rect.Width(),Rect.Height(),PATCOPY);


In GDI+, I have the basics started:
======================
CBitmap m_Bitmap56;
...
m_Bitmap56.LoadBitmap(IDB_56PERCENT);
//
//Brush m_Brush56;
//TextureBrush Brush56(&m_Bitmap56,WrapModeTile); <- need equivalent here
//
Brush* m_pBrush56=&m_Brush56;
//
...
m_pGDI->FillRectangle(m_pBrush56,FRect);


Does anyone know if this is possible in GDI+? Hopefully, I am just missing
where to find this in the documentation.

Thanks,
--
Bob
 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Michael Ph » Sun, 29 Jul 2007 03:08:30

> //TextureBrush Brush56(&m_Bitmap56,WrapModeTile); <- need equivalent here

Use the gdi+ ImageAttributes class with the SetWrapMode method.
WrapModeTile is the enum that you would use with this method.

 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Qm9iS » Sun, 29 Jul 2007 08:24:00

Thank you Michael,

However, this still doesn't help me load the bitmap from the app's resources.

--
Bob
 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Mark Salsb » Sun, 29 Jul 2007 11:40:33

Bitmap::FromResource() will do it.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Qm9iS » Sun, 29 Jul 2007 19:24:00

Thank you Mark.

I guess I need to add more detail.

1. There is no problem loading a bitmap from resources.
2. There is no problem painting an image from a file.
3. The problem is painting a bitmap/image as a brush from a resource.
4. "TextureBrush Brush56(&m_Bitmap56,WrapModeTile);" will not compile. It
will not accept a Bitmap as an Image. Once I do load a bitmap, I do not see
how to paint it as a Brush. Some other technique must be required.

Thanks again.
--
Bob
 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Michael Ph » Sun, 29 Jul 2007 23:41:24

gt; 4. "TextureBrush Brush56(&m_Bitmap56,WrapModeTile);" will not compile. It

If "&m_Bitmap56" is not a pointer to a gdi+ Bitmap, then it will not
compile.

Either use the gdi+ API to load and/or create your bitmap's or use the
Mfc/ATL CImage class.
The Mfc CBitmap class was written for gdi bitmaps not gdi+ Bitmaps.

"BobH" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...


 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Qm9iS » Mon, 30 Jul 2007 21:28:00

ichael, Thank you again for trying to gie me an answer I truly do appreciate
it. However, before answering the next time, can you please read first? Don't
tell me what not to do, please tell me what TO do.

I AM using a GDI+ Bitmap. The whole point is that I am trying to do this in
GDI+ and it doesn't look like it is possible to do this in GDI+.

To make my question really clear, "How do you display a resource based
bitmap as a brush using GDI+?".
--
Bob


"Michael Phillips, Jr." wrote:

 
 
 

How to fill a Rectangle with a Bitmap Resource using GDI+

Post by Qm9iS » Mon, 30 Jul 2007 22:06:04

ichael, you were right. I had CBitmap rather than Bitmap in my sample code.

I played around some more, and my problem was understanding how to use the
new GDI+ constructors. And yes, Texture Brush DOES appear to accept a Bitmap
as well as an Image. Complete sample Code in case anyone needs it:

TextureBrush* m_pTest;
...
Bitmap BitmapTest(AfxGetInstanceHandle(),(PWCHAR)MAKEINTRESOURCE(IDB_TEST));
TextureBrush BrushTest(&BitmapTest,WrapModeTile);
m_pTest=&BrushTest;

RectF FRect(100,100,200,300);
GDI.FillRectangle(m_pTest,FRect);

Thanks again for the clues.
--
Bob


"Michael Phillips, Jr." wrote: