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. C / C++ / MFC
  4. PNG image shown is missing 1 pixel right and 1 pixel bottom

PNG image shown is missing 1 pixel right and 1 pixel bottom

Scheduled Pinned Locked Moved C / C++ / MFC
graphicscomhelpquestionlearning
3 Posts 2 Posters 0 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.
  • S Offline
    S Offline
    sdancer75
    wrote on last edited by
    #1

    Using the code below (called from void CLoadPngDlg::OnPaint()) I am trying to view a PNG file that already included in the resource (IDB_FULLSCRINFOBAR_OPAQ_TEST). As you can see in the image attached the bottom red line and the rightmost column of pixels are not shown. https://i.imgur.com/Ug6gYjr.jpg Image Attached[^] What seems to be the problem here?

    BOOL CLoadPngDlg::ShowPngAt(CDC *dcWnd) {

    CGdiPlusBitmapResource		\*pPngChannel;
    UINT						nWidth,nHeight;
    CRect						rectClient;
    CBitmap						Bitmap, \*pOldBitmap;	
    CDC							bitmapDC;
    CDC							\*dialogDC;
    
    pPngChannel	= NULL;
    pPngChannel = new CGdiPlusBitmapResource;
    
    if (!pPngChannel->Load(IDB\_FULLSCRINFOBAR\_OPAQ\_TEST, \_T("PNG"))) {
    	delete pPngChannel;
    	return TRUE;
    }
    
    GetWindowRect(&rectClient);
    
    // Get size of bitmap.
    nWidth = pPngChannel->m\_pBitmap->GetWidth();
    nHeight = pPngChannel->m\_pBitmap->GetHeight();
    
    bitmapDC.CreateCompatibleDC( dcWnd ); 
    Bitmap.CreateCompatibleBitmap(dcWnd, nWidth, nHeight);
    pOldBitmap = bitmapDC.SelectObject(&Bitmap);	
    
    Gdiplus::Graphics graphics(bitmapDC.GetSafeHdc());										
    graphics.DrawImage(\*pPngChannel, 0, 0);
    
    dcWnd->BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &bitmapDC,   0,  0,   SRCCOPY );
    
    bitmapDC.SelectObject( pOldBitmap );
    bitmapDC.DeleteDC();
    
    
    if (pPngChannel != NULL)
    	delete pPngChannel;
    
    
    return FALSE;
    

    }

    sdancer75

    L 1 Reply Last reply
    0
    • S sdancer75

      Using the code below (called from void CLoadPngDlg::OnPaint()) I am trying to view a PNG file that already included in the resource (IDB_FULLSCRINFOBAR_OPAQ_TEST). As you can see in the image attached the bottom red line and the rightmost column of pixels are not shown. https://i.imgur.com/Ug6gYjr.jpg Image Attached[^] What seems to be the problem here?

      BOOL CLoadPngDlg::ShowPngAt(CDC *dcWnd) {

      CGdiPlusBitmapResource		\*pPngChannel;
      UINT						nWidth,nHeight;
      CRect						rectClient;
      CBitmap						Bitmap, \*pOldBitmap;	
      CDC							bitmapDC;
      CDC							\*dialogDC;
      
      pPngChannel	= NULL;
      pPngChannel = new CGdiPlusBitmapResource;
      
      if (!pPngChannel->Load(IDB\_FULLSCRINFOBAR\_OPAQ\_TEST, \_T("PNG"))) {
      	delete pPngChannel;
      	return TRUE;
      }
      
      GetWindowRect(&rectClient);
      
      // Get size of bitmap.
      nWidth = pPngChannel->m\_pBitmap->GetWidth();
      nHeight = pPngChannel->m\_pBitmap->GetHeight();
      
      bitmapDC.CreateCompatibleDC( dcWnd ); 
      Bitmap.CreateCompatibleBitmap(dcWnd, nWidth, nHeight);
      pOldBitmap = bitmapDC.SelectObject(&Bitmap);	
      
      Gdiplus::Graphics graphics(bitmapDC.GetSafeHdc());										
      graphics.DrawImage(\*pPngChannel, 0, 0);
      
      dcWnd->BitBlt(0, 0, rectClient.Width(), rectClient.Height(), &bitmapDC,   0,  0,   SRCCOPY );
      
      bitmapDC.SelectObject( pOldBitmap );
      bitmapDC.DeleteDC();
      
      
      if (pPngChannel != NULL)
      	delete pPngChannel;
      
      
      return FALSE;
      

      }

      sdancer75

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Where is the code for CGdiPlusBitmapResource? I can only assume that it returns the wrong values for height and width.

      S 1 Reply Last reply
      0
      • L Lost User

        Where is the code for CGdiPlusBitmapResource? I can only assume that it returns the wrong values for height and width.

        S Offline
        S Offline
        sdancer75
        wrote on last edited by
        #3

        Thanks for your answer. The CGdiPlusBitmapResource is part of an older codeproject.com article at Loading JPG & PNG resources using GDI+[^] Anyway, I found the root of the problem. I had to call DrawImage with the size of the image. Now all works just fine.

        graphics.DrawImage(*pPngChannel, 0, 0, 800, 50);

        sdancer75

        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