]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't use bitmap still selected in wxMemoryDC in image sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Aug 2010 18:57:47 +0000 (18:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Aug 2010 18:57:47 +0000 (18:57 +0000)
The bitmap must be deselected from wxMemoryDC before being used in any other
way but the sample didn't do this. Fix this by simply destroying the DC as
soon as we don't need it, this makes bitmap available for other use as well.

Closes #12310.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65232 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/image/canvas.cpp

index 93b6a689732d903b9b27d169ef230fbf4e8d6fb8..5b98dcf07b0376a16f52e658f3c8a8ffb397f976 100644 (file)
@@ -641,22 +641,22 @@ void MyCanvas::CreateAntiAliasedBitmap()
 {
     wxBitmap bitmap( 300, 300 );
 
-    wxMemoryDC dc;
-
-    dc.SelectObject( bitmap );
+    {
+        wxMemoryDC dc(bitmap);
 
-    dc.Clear();
+        dc.Clear();
 
-    dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
-    dc.SetTextForeground( wxT("RED") );
-    dc.DrawText( wxT("This is anti-aliased Text."), 20, 5 );
-    dc.DrawText( wxT("And a Rectangle."), 20, 45 );
+        dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL) );
+        dc.SetTextForeground( wxT("RED") );
+        dc.DrawText( wxT("This is anti-aliased Text."), 20, 5 );
+        dc.DrawText( wxT("And a Rectangle."), 20, 45 );
 
-    dc.SetBrush( *wxRED_BRUSH );
-    dc.SetPen( *wxTRANSPARENT_PEN );
-    dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
+        dc.SetBrush( *wxRED_BRUSH );
+        dc.SetPen( *wxTRANSPARENT_PEN );
+        dc.DrawRoundedRectangle( 20, 85, 200, 180, 20 );
+    }
 
-    wxImage original= bitmap.ConvertToImage();
+    wxImage original = bitmap.ConvertToImage();
     wxImage anti( 150, 150 );
 
     /* This is quite slow, but safe. Use wxImage::GetData() for speed instead. */