if ( m_hBitmap)
{
- // printf("About to delete bitmap %d\n", (int) (HBITMAP) m_hBitmap);
+ // printf("About to delete bitmap %d\n", (int) (HBITMAP) m_hBitmap);
#if 1
if ( !::DeleteObject((HBITMAP)m_hBitmap) )
{
// Initial attempt at a simple-minded implementation.
// The bitmap will always be created at the screen depth,
// so the 'depth' argument is ignored.
-
+
HDC hScreenDC = ::GetDC(NULL);
// printf("Screen planes = %d, bpp = %d\n", hScreenDC->psd->planes, hScreenDC->psd->bpp);
int screenDepth = ::GetDeviceCaps(hScreenDC, BITSPIXEL);
if (hBitmap == NULL)
{
::ReleaseDC(NULL, hScreenDC);
- return FALSE;
+ return FALSE;
}
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
if (!hMaskBitmap)
{
hasMask = FALSE;
- }
+ }
else
{
hScreenDC = ::GetDC(NULL);
::ReleaseDC(NULL, hScreenDC);
hOldMaskBitmap = ::SelectObject( hMaskDC, hMaskBitmap);
- }
+ }
#else
hasMask = FALSE;
#endif
int i, j;
for (i = 0; i < image.GetWidth(); i++)
{
- for (j = 0; j < image.GetHeight(); j++)
- {
- unsigned char red = image.GetRed(i, j);
- unsigned char green = image.GetGreen(i, j);
- unsigned char blue = image.GetBlue(i, j);
+ for (j = 0; j < image.GetHeight(); j++)
+ {
+ unsigned char red = image.GetRed(i, j);
+ unsigned char green = image.GetGreen(i, j);
+ unsigned char blue = image.GetBlue(i, j);
- ::SetPixel(hMemDC, i, j, PALETTERGB(red, green, blue));
+ ::SetPixel(hMemDC, i, j, PALETTERGB(red, green, blue));
if (hasMask)
{
::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0));
else
::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255));
- }
- }
+ }
+ }
}
::SelectObject(hMemDC, hOldBitmap);
if (hasMask)
{
::SelectObject(hMaskDC, hOldMaskBitmap);
- ::DeleteDC(hMaskDC);
+ ::DeleteDC(hMaskDC);
((wxBitmapRefData*)m_refData)->m_bitmapMask = new wxMask((WXHBITMAP) hMaskBitmap);
}
-
+
SetWidth(image.GetWidth());
SetHeight(image.GetHeight());
SetDepth(screenDepth);
SetHBITMAP( (WXHBITMAP) hBitmap );
-
+
#if wxUSE_PALETTE
// Copy the palette from the source image
SetPalette(image.GetPalette());
if (!Ok())
{
wxFAIL_MSG( wxT("bitmap is invalid") );
- return wxNullImage;
+ return wxNullImage;
}
wxImage image;
wxFAIL_MSG( wxT("could not allocate data for image") );
return wxNullImage;
}
-
+
HDC hScreenDC = ::GetDC(NULL);
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
::ReleaseDC(NULL, hScreenDC);
HBITMAP hBitmap = (HBITMAP) GetHBITMAP();
-
+
HBITMAP hOldBitmap = ::SelectObject(hMemDC, hBitmap);
int i, j;
for (i = 0; i < GetWidth(); i++)
{
- for (j = 0; j < GetHeight(); j++)
- {
- COLORREF color = ::GetPixel(hMemDC, i, j);
- unsigned char red = GetRValue(color);
- unsigned char green = GetGValue(color);
- unsigned char blue = GetBValue(color);
-
- image.SetRGB(i, j, red, green, blue);
- }
+ for (j = 0; j < GetHeight(); j++)
+ {
+ COLORREF color = ::GetPixel(hMemDC, i, j);
+ unsigned char red = GetRValue(color);
+ unsigned char green = GetGValue(color);
+ unsigned char blue = GetBValue(color);
+
+ image.SetRGB(i, j, red, green, blue);
+ }
}
::SelectObject(hMemDC, hOldBitmap);
::DeleteDC(hMemDC);
-
+
#if wxUSE_PALETTE
// Copy the palette from the source image
if (GetPalette())
wxImage image;
if ( image.LoadFile( filename, type ) && image.Ok() )
{
- *this = image.ConvertToBitmap();
+ *this = wxBitmap(image);
return TRUE;
}
else
{
// FIXME what about palette? shouldn't we use it?
- wxImage image( *this );
+ wxImage image = ConvertToImage();
if ( image.Ok() )
{
return image.SaveFile(filename, type);
wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
{
-#ifndef __WXMICROWIN__
wxCHECK_MSG( Ok() &&
(rect.x >= 0) && (rect.y >= 0) &&
(rect.x+rect.width <= GetWidth()) &&
wxBitmap ret( rect.width, rect.height, GetDepth() );
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
+#ifndef __WXMICROWIN__
// copy bitmap data
- HDC dcSrc = ::CreateCompatibleDC(NULL);
- HDC dcDst = ::CreateCompatibleDC(NULL);
- SelectObject(dcSrc, (HBITMAP) GetHBITMAP());
- SelectObject(dcDst, (HBITMAP) ret.GetHBITMAP());
- BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
+ MemoryHDC dcSrc, dcDst;
+
+ {
+ SelectInHDC selectSrc(dcSrc, GetHbitmap()),
+ selectDst(dcDst, GetHbitmapOf(ret));
+
+ if ( !::BitBlt(dcDst, 0, 0, rect.width, rect.height,
+ dcSrc, rect.x, rect.y, SRCCOPY) )
+ {
+ wxLogLastError(_T("BitBlt"));
+ }
+ }
// copy mask if there is one
- if (GetMask())
+ if ( GetMask() )
{
HBITMAP hbmpMask = ::CreateBitmap(rect.width, rect.height, 1, 1, 0);
- SelectObject(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap());
- SelectObject(dcDst, (HBITMAP) hbmpMask);
- BitBlt(dcDst, 0, 0, rect.width, rect.height, dcSrc, rect.x, rect.y, SRCCOPY);
+ SelectInHDC selectSrc(dcSrc, (HBITMAP) GetMask()->GetMaskBitmap()),
+ selectDst(dcDst, hbmpMask);
+
+ if ( !::BitBlt(dcDst, 0, 0, rect.width, rect.height,
+ dcSrc, rect.x, rect.y, SRCCOPY) )
+ {
+ wxLogLastError(_T("BitBlt"));
+ }
wxMask *mask = new wxMask((WXHBITMAP) hbmpMask);
ret.SetMask(mask);
}
-
- SelectObject(dcDst, NULL);
- SelectObject(dcSrc, NULL);
- DeleteDC(dcDst);
- DeleteDC(dcSrc);
+#endif // !__WXMICROWIN__
return ret;
-#else
- return wxBitmap();
-#endif
}
// ----------------------------------------------------------------------------
// scan the bitmap for the transparent colour and set the corresponding
// pixels in the mask to BLACK and the rest to WHITE
- COLORREF maskColour = RGB(colour.Red(), colour.Green(), colour.Blue());
+ COLORREF maskColour = wxColourToPalRGB(colour);
m_maskBitmap = (WXHBITMAP)::CreateBitmap(width, height, 1, 1, 0);
HDC srcDC = ::CreateCompatibleDC(NULL);
ok = FALSE;
}
- // VZ: I'm leaving the old code in for now in case it is needed under Win95
- // or any other broken Windows versions but it is horribly inefficient:
- // creating 100 masks for 80x80 bitmaps takes 7.8 seconds on my machine
- // but only 0.2 using the new code!
-#if 0
- // this is not very efficient, but I can't think of a better way of doing
- // it
- for ( int w = 0; ok && (w < width); w++ )
+ if ( ok )
{
- for ( int h = 0; ok && (h < height); h++ )
- {
- COLORREF col = GetPixel(srcDC, w, h);
- if ( col == CLR_INVALID )
- {
- wxLogLastError(wxT("GetPixel"));
-
- // doesn't make sense to continue
- ok = FALSE;
-
- break;
- }
-
- if ( col == maskColour )
- {
- ::SetPixel(destDC, w, h, RGB(0, 0, 0));
- }
- else
- {
- ::SetPixel(destDC, w, h, RGB(255, 255, 255));
- }
- }
+ // this will create a monochrome bitmap with 0 points for the pixels
+ // which have the same value as the background colour and 1 for the
+ // others
+ ::SetBkColor(srcDC, maskColour);
+ ::BitBlt(destDC, 0, 0, width, height, srcDC, 0, 0, NOTSRCCOPY);
}
-#else
- HBRUSH hbrMask = ::CreateSolidBrush(maskColour);
- HGDIOBJ hbrOld = ::SelectObject(destDC, hbrMask);
-
- // the ternary raster operation 0x3C004A is dest := src ^ brush
- ::BitBlt(destDC, 0, 0, width, height, srcDC, 0, 0, 0x3C004A);
-
- ::SelectObject(destDC, hbrOld);
-#endif
::SelectObject(srcDC, hbmpSrcOld);
::DeleteDC(srcDC);
::DeleteDC(destDC);
return ok;
-#else
+#else // __WXMICROWIN__
return FALSE;
-#endif
+#endif // __WXMICROWIN__/!__WXMICROWIN__
}
// ----------------------------------------------------------------------------