PNG image shown is missing 1 pixel right and 1 pixel bottom
-
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
-
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
-
Where is the code for
CGdiPlusBitmapResource
? I can only assume that it returns the wrong values for height and width.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