Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Resolution of GDI+ bitmap from resource

Resolution of GDI+ bitmap from resource

Scheduled Pinned Locked Moved Graphics
c++graphicswinformsquestionlearning
6 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bozalina
    wrote on last edited by
    #1

    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!

    M 1 Reply Last reply
    0
    • B bozalina

      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!

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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."

      B 1 Reply Last reply
      0
      • M Mark Salsbery

        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."

        B Offline
        B Offline
        bozalina
        wrote on last edited by
        #3

        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?

        M 1 Reply Last reply
        0
        • B bozalina

          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?

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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."

          B 1 Reply Last reply
          0
          • M Mark Salsbery

            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."

            B Offline
            B Offline
            bozalina
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • B bozalina

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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."

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups