+ 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);
+ }
+ }
+
+ ::SelectObject(hMemDC, hOldBitmap);
+ ::DeleteDC(hMemDC);
+
+#if wxUSE_PALETTE
+ // Copy the palette from the source image
+ if (GetPalette())
+ image.SetPalette(* GetPalette());
+#endif // wxUSE_PALETTE
+
+ return image;
+}
+
+#endif // __WXMICROWIN__
+
+// ----------------------------------------------------------------------------
+// wxImage to/from conversions
+// ----------------------------------------------------------------------------
+
+#if wxUSE_WXDIB
+
+bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
+{
+ return CreateFromImage(image, depth, 0);
+}
+
+bool wxBitmap::CreateFromImage(const wxImage& image, const wxDC& dc)
+{
+ wxCHECK_MSG( dc.Ok(), FALSE,
+ _T("invalid HDC in wxBitmap::CreateFromImage()") );
+
+ return CreateFromImage(image, -1, dc.GetHDC());
+}
+
+bool wxBitmap::CreateFromImage(const wxImage& image, int depth, WXHDC hdc)
+{
+ wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") );
+
+ UnRef();
+
+ // first convert the image to DIB
+ const int h = image.GetHeight();
+ const int w = image.GetWidth();
+
+ wxDIB dib(image);
+ if ( !dib.IsOk() )
+ return FALSE;
+
+
+ // store the bitmap parameters
+ wxBitmapRefData *refData = new wxBitmapRefData;
+ refData->m_width = w;
+ refData->m_height = h;
+ refData->m_hasAlpha = image.HasAlpha();
+
+ m_refData = refData;
+
+
+ // next either store DIB as is or create a DDB from it
+ HBITMAP hbitmap wxDUMMY_INITIALIZE(0);
+
+ // are we going to use DIB?
+ //
+ // NB: DDBs don't support alpha so if we have alpha channel we must use DIB
+ if ( image.HasAlpha() || wxShouldCreateDIB(w, h, depth, hdc) )
+ {
+ // don't delete the DIB section in dib object dtor
+ hbitmap = dib.Detach();
+
+ refData->m_isDIB = TRUE;
+ refData->m_depth = dib.GetDepth();
+ }
+#ifndef ALWAYS_USE_DIB
+ else // we need to convert DIB to DDB
+ {
+ hbitmap = dib.CreateDDB((HDC)hdc);
+
+ refData->m_depth = depth == -1 ? dib.GetDepth() : depth;
+ }
+#endif // !ALWAYS_USE_DIB
+
+ // validate this object
+ SetHBITMAP((WXHBITMAP)hbitmap);
+
+ // finally also set the mask if we have one
+ if ( image.HasMask() )