Add raw bitmap access sample to the demo
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40860 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -77,7 +77,7 @@ class TestPanel(wx.Panel):
|
|||||||
# Make a bitmap using an array of RGB bytes plus a separate
|
# Make a bitmap using an array of RGB bytes plus a separate
|
||||||
# buffer for the alpha channel
|
# buffer for the alpha channel
|
||||||
bpp = 3 # bytes per pixel
|
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):
|
def offset(x, y):
|
||||||
# return the offset into the bytes array for the start of
|
# return the offset into the bytes array for the start of
|
||||||
|
@@ -50,7 +50,6 @@ _treeList = [
|
|||||||
'AnalogClock',
|
'AnalogClock',
|
||||||
'AUI_DockingWindowMgr',
|
'AUI_DockingWindowMgr',
|
||||||
'AUI_Notebook',
|
'AUI_Notebook',
|
||||||
'BitmapFromBuffer',
|
|
||||||
'CheckListCtrlMixin',
|
'CheckListCtrlMixin',
|
||||||
'ComboTreeBox',
|
'ComboTreeBox',
|
||||||
'Pickers',
|
'Pickers',
|
||||||
@@ -58,6 +57,8 @@ _treeList = [
|
|||||||
'RichTextCtrl',
|
'RichTextCtrl',
|
||||||
'Treebook',
|
'Treebook',
|
||||||
'Toolbook',
|
'Toolbook',
|
||||||
|
'BitmapFromBuffer',
|
||||||
|
'RawBitmapAccess',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# managed windows == things with a (optional) caption you can close
|
# managed windows == things with a (optional) caption you can close
|
||||||
@@ -239,6 +240,7 @@ _treeList = [
|
|||||||
'ImageAlpha',
|
'ImageAlpha',
|
||||||
'ImageFromStream',
|
'ImageFromStream',
|
||||||
'Mask',
|
'Mask',
|
||||||
|
'RawBitmapAccess',
|
||||||
'Throbber',
|
'Throbber',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
79
wxPython/demo/RawBitmapAccess.py
Normal file
79
wxPython/demo/RawBitmapAccess.py
Normal file
@@ -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:])
|
||||||
|
|
Reference in New Issue
Block a user