]> git.saurik.com Git - wxWidgets.git/commitdiff
Add raw bitmap access sample to the demo
authorRobin Dunn <robin@alldunn.com>
Sun, 27 Aug 2006 09:11:47 +0000 (09:11 +0000)
committerRobin Dunn <robin@alldunn.com>
Sun, 27 Aug 2006 09:11:47 +0000 (09:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40860 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/demo/BitmapFromBuffer.py
wxPython/demo/Main.py
wxPython/demo/RawBitmapAccess.py [new file with mode: 0644]

index 2f72f6a02e1cd1b52547715a4305e3274daa2c41..4fd8bae64958b256ed5162d1030b82036efb70e8 100644 (file)
@@ -77,7 +77,7 @@ class TestPanel(wx.Panel):
         # Make a bitmap using an array of RGB bytes plus a separate
         # buffer for the alpha channel
         bpp = 3  # bytes per pixel
-        bytes = array.array('B', [1,2,3] * width*height)#*bpp)
+        bytes = array.array('B', [0] * width*height*bpp)
 
         def offset(x, y):
             # return the offset into the bytes array for the start of
index b67361889d20cdbc6e58e28fe62cc99075035bc5..be75f8c97cc4d4f160ce8ef9c094fc6254a63a20 100644 (file)
@@ -50,7 +50,6 @@ _treeList = [
         'AnalogClock',
         'AUI_DockingWindowMgr',
         'AUI_Notebook',
-        'BitmapFromBuffer',
         'CheckListCtrlMixin',
         'ComboTreeBox',
         'Pickers',
@@ -58,6 +57,8 @@ _treeList = [
         'RichTextCtrl',
         'Treebook',
         'Toolbook',
+        'BitmapFromBuffer',
+        'RawBitmapAccess',
         ]),
 
     # managed windows == things with a (optional) caption you can close
@@ -239,6 +240,7 @@ _treeList = [
         'ImageAlpha',
         'ImageFromStream',
         'Mask',
+        'RawBitmapAccess',
         'Throbber',
         ]),
 
diff --git a/wxPython/demo/RawBitmapAccess.py b/wxPython/demo/RawBitmapAccess.py
new file mode 100644 (file)
index 0000000..2e0e57d
--- /dev/null
@@ -0,0 +1,79 @@
+
+import wx
+
+#----------------------------------------------------------------------
+
+class TestPanel(wx.Panel):
+    def __init__(self, parent, log):
+        self.log = log
+        wx.Panel.__init__(self, parent, -1)
+        self.Bind(wx.EVT_PAINT, self.OnPaint)
+        
+        self.redBmp   = self.MakeBitmap(188, 143, 234)
+        self.greenBmp = self.MakeBitmap(35,  142,  35)
+        self.blueBmp  = self.MakeBitmap(50,  153, 204)
+
+    def MakeBitmap(self, red, green, blue, alpha=128):
+        bmp = wx.EmptyBitmap(100, 100, 32)
+
+        # Create an object that facilitates access to the bitmap's
+        # pixel buffer
+        pixelData = wx.AlphaPixelData(bmp)
+        if not pixelData:
+            raise RuntimeError("Failed to gain raw access to bitmap data.")
+
+        # We have two ways to access each pixel, first we'll use an
+        # iterator to set every pixel to the colour and alpha values
+        # passed in.
+        for pixel in pixelData:
+            pixel.Set(red, green, blue, alpha)
+
+        # Next we'll use the pixel accessor to draw a border
+        pixels = pixelData.GetPixels()
+        for x in xrange(100):
+            pixels.MoveTo(pixelData, x, 0)
+            pixels.Set(red, green, blue, wx.ALPHA_OPAQUE)
+            pixels.MoveTo(pixelData, x, 99)
+            pixels.Set(red, green, blue, wx.ALPHA_OPAQUE)
+        for y in xrange(100):
+            pixels.MoveTo(pixelData, 0, y)
+            pixels.Set(red, green, blue, wx.ALPHA_OPAQUE)
+            pixels.MoveTo(pixelData, 99, y)
+            pixels.Set(red, green, blue, wx.ALPHA_OPAQUE)
+            
+        return bmp
+
+
+    def OnPaint(self, evt):
+        dc = wx.PaintDC(self)
+        dc.DrawBitmap(self.redBmp,    50,  50, True)
+        dc.DrawBitmap(self.greenBmp, 110, 110, True)
+        dc.DrawBitmap(self.blueBmp,  170,  50, True)
+        
+#----------------------------------------------------------------------
+
+def runTest(frame, nb, log):
+    win = TestPanel(nb, log)
+    return win
+
+#----------------------------------------------------------------------
+
+
+
+overview = """<html><body>
+<h2><center>Raw Bitmap Access</center></h2>
+
+wx.NativePixelData and wx.AlphaPixelData provide a cross-platform way
+to access the platform-specific pixel buffer within a wx.Bitmap.  They
+provide both a random access method, and an iterator interface.
+
+</body></html>
+"""
+
+
+
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
+