Resolution of GDI+ bitmap from resource
-
I'm relatively new to GDI+. I'm trying to create a texture brush from a bitmap stored in a resource file in a Visual C++ project. However, the image comes out much too small when I fill a shape with the texture brush. The bitmap I'm using is 32x32 and is monochrome.
Bitmap bmpPattern(AfxGetResourceHandle(), (WCHAR*)lpszBmpName); TextureBrush *pBrush = new TextureBrush(&bmpPattern);
If I want to see the image as it's drawn when using GDI's CreateDIBPatternBrushPt, I have to do a scale tranform on the texture brush by about 10 times. I'm not sure what's causing this, but I'm guessing it's something to do with the page units. Any clues? Thanks in advance! -
I'm relatively new to GDI+. I'm trying to create a texture brush from a bitmap stored in a resource file in a Visual C++ project. However, the image comes out much too small when I fill a shape with the texture brush. The bitmap I'm using is 32x32 and is monochrome.
Bitmap bmpPattern(AfxGetResourceHandle(), (WCHAR*)lpszBmpName); TextureBrush *pBrush = new TextureBrush(&bmpPattern);
If I want to see the image as it's drawn when using GDI's CreateDIBPatternBrushPt, I have to do a scale tranform on the texture brush by about 10 times. I'm not sure what's causing this, but I'm guessing it's something to do with the page units. Any clues? Thanks in advance!Are you using GDI+ or GDI to draw a filled shape. Taking from your GDI+ code, I did this in a CWnd-derived OnPaint()... // IDB_BITMAP4 is a 32x32 monochrome bitmap resource, black 2-pixel-wide border filled with // dithered pixels (from a color in the monochrome bitmap editor palette). Graphics DstGraphics(*this); Bitmap brushbitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP4)); TextureBrush texturebrush(&brushbitmap, WrapModeTile); Rect ellipserect(0, 0, 640, 640); DstGraphics.FillEllipse(&texturebrush, ellipserect); The bitmap is drawn full size in the ellipse. Do you get the same result? Mark
"Go that way, really fast. If something gets in your way, turn."
-
Are you using GDI+ or GDI to draw a filled shape. Taking from your GDI+ code, I did this in a CWnd-derived OnPaint()... // IDB_BITMAP4 is a 32x32 monochrome bitmap resource, black 2-pixel-wide border filled with // dithered pixels (from a color in the monochrome bitmap editor palette). Graphics DstGraphics(*this); Bitmap brushbitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_BITMAP4)); TextureBrush texturebrush(&brushbitmap, WrapModeTile); Rect ellipserect(0, 0, 640, 640); DstGraphics.FillEllipse(&texturebrush, ellipserect); The bitmap is drawn full size in the ellipse. Do you get the same result? Mark
"Go that way, really fast. If something gets in your way, turn."
No, mine is displayed at about 1/10th the size it should be. I thought that my problem might be that the bitmap was created from a resource file bitmap. So, I tested just creating a bitmap by doing this:
Bitmap bmpTest(32, 32, PixelFormat32bppARGB); BitmapData bitmapData; bmpTest.LockBits(&Rect(0, 0, 32, 32), ImageLockModeRead | ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData); UINT* pixels = (UINT*)bitmapData.Scan0; for(UINT row = 0; row < 32; ++row) for(UINT col = 0; col < 32; ++col) pixels[row * bitmapData.Stride / 4 + col] = (row == 0 || row == 31 || col == 0 || col == 31) ? 0xFF000000 : 0xFFFFFFFF; bmpTest.UnlockBits(&bitmapData); TextureBrush *pBrush = new TextureBrush(&bmpTest);
But it still displays much too small. I'm thinking maybe it's a problem of page units, but if that's the case, then why do all my ellipses and rectangles show up in the right place, just with their texture-filled insides too small? -
No, mine is displayed at about 1/10th the size it should be. I thought that my problem might be that the bitmap was created from a resource file bitmap. So, I tested just creating a bitmap by doing this:
Bitmap bmpTest(32, 32, PixelFormat32bppARGB); BitmapData bitmapData; bmpTest.LockBits(&Rect(0, 0, 32, 32), ImageLockModeRead | ImageLockModeWrite, PixelFormat32bppARGB, &bitmapData); UINT* pixels = (UINT*)bitmapData.Scan0; for(UINT row = 0; row < 32; ++row) for(UINT col = 0; col < 32; ++col) pixels[row * bitmapData.Stride / 4 + col] = (row == 0 || row == 31 || col == 0 || col == 31) ? 0xFF000000 : 0xFFFFFFFF; bmpTest.UnlockBits(&bitmapData); TextureBrush *pBrush = new TextureBrush(&bmpTest);
But it still displays much too small. I'm thinking maybe it's a problem of page units, but if that's the case, then why do all my ellipses and rectangles show up in the right place, just with their texture-filled insides too small?Your code works for me too. I'm not sure what page units you're referring to, but the problem seems to be in the Graphics object you're drawing to (i haven't seen ay code showing your Graphics object creation and drawing :)). Maybe try this... Right before you draw, call DstGraphics.ResetTransform();
"Go that way, really fast. If something gets in your way, turn."
-
Your code works for me too. I'm not sure what page units you're referring to, but the problem seems to be in the Graphics object you're drawing to (i haven't seen ay code showing your Graphics object creation and drawing :)). Maybe try this... Right before you draw, call DstGraphics.ResetTransform();
"Go that way, really fast. If something gets in your way, turn."
-
Ah, very true! I create my graphics object from a handle to a CDC that gets passed down from an OnPaint's CPaintDC. I tried the reset transform on the graphics object, but no luck. :( By page units, I mean the SetPageUnit method of the Graphics class.
If you're using SetPageUnit() then maybe this will be of interest: Types of Coordinate Systems[^]
"Go that way, really fast. If something gets in your way, turn."