Differences between revisions 1 and 10 (spanning 9 versions)
Revision 1 as of 2001-04-05 07:44:48
Size: 615
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 10 as of 2001-06-08 07:16:22
Size: 2569
Editor: anonymous
Comment: missing edit-log entry for this revision
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Formats and Conversions == Formats and Conversions ==
Line 3: Line 3:
    Conversions among wxImage, wxBitmap, wxCursor, wxIcon     Conversions among wxImage, wxBitmap, wxCursor, wxIcon and DATA
Line 5: Line 5:
    Embedding images in code as strings, conversion to/from strings         wxImage to wxBitmap -- {{{ myWxImage.ConvertToBitmap() }}}

        wxImage to DATA -- {{{ myWxImage.GetData() }}} returning a string in width * height * 3 format

        DATA to wxImage -- {{{ image = wxImage(); image.SetData( data ) }}} where data is a Python string of length width * height * 3.

        DATA to wxBitmap -- ???

        DATA to wxIcon -- Should be possible, but I don't see an overloaded-constructor name for it.

== Using dynamic bitmaps (wxBitmapFromData) ==
Line 8: Line 18:

    Animated Icons (are these possible in wxPython?)

Using dynamic bitmaps (wxBitmapFromData)
Line 17: Line 23:
Drawing Bitmaps to Screen/Printer Contexts === Examples ===

    This example shows the creation of a bitmap using a Numeric Python array as the data source for a {{{wxImage/wxBitmap}}}. Note that Numeric uses reversed column-row ordering compared to wxPython, so you'll need to make sure that you generate images using height, width, not width, height coordinates. Also note the user of the 'c' data type for image data.

{{{
 def GetBitmap( self, width=32, height=32, colour = (0,0,0) ):
  array = Numeric.zeros( (height, width, 3),'c')
  array[:,:,] = colour
  image = wxEmptyImage(width,height)
  image.SetData( array.tostring())
  return image.ConvertToBitmap()
}}}

    This example shows use of Numeric's (extended) slicing notation to alter the in-memory image. This slicing notation, for our purposes, goes as follows:

    {{{ [ rowStart: rowEnd, columnStart: columnEnd, colourPlanes ] }}}

    To assign a single colour to the entire image: {{{ array[:,:] = (r,g,b) }}} . To assign a value to the entire red bit plane: {{{ array[:,:,0] = 255 }}} . To assign a colour to the first row: {{{ array[ 0 ] = (r,g,b ) }}} .

{{{
 def GetBitmap( self, width=32, height=32, colour = (128,128,128), border=5, borderColour=(255,255,255) ):
  array = Numeric.zeros( (height, width, 3),'c')
  array[border:-border,border:-border,:] = colour
  array[:border,:,:] = borderColour
  array[-border:,:,:] = borderColour
  array[:,:border,:] = borderColour
  array[:,-border:,:] = borderColour
  image = wxEmptyImage(width,height)
  image.SetData( array.tostring())
  return image.ConvertToBitmap()
}}}


== Drawing Bitmaps to Screen/Printer Contexts ==
Line 21: Line 60:
Masks and Transparency/Alpha == Masks and Transparency/Alpha ==

Formats and Conversions

  • Conversions among wxImage, wxBitmap, wxCursor, wxIcon and DATA
    • wxImage to wxBitmap --  myWxImage.ConvertToBitmap() 

      wxImage to DATA --  myWxImage.GetData()  returning a string in width * height * 3 format

      DATA to wxImage --  image = wxImage(); image.SetData( data )  where data is a Python string of length width * height * 3. DATA to wxBitmap -- ??? DATA to wxIcon -- Should be possible, but I don't see an overloaded-constructor name for it.

Using dynamic bitmaps (wxBitmapFromData)

  • Using PIL with wxPython Run-time generation of images Using device contexts to write into wxBitmaps

Examples

  • This example shows the creation of a bitmap using a Numeric Python array as the data source for a wxImage/wxBitmap. Note that Numeric uses reversed column-row ordering compared to wxPython, so you'll need to make sure that you generate images using height, width, not width, height coordinates. Also note the user of the 'c' data type for image data.

        def GetBitmap( self, width=32, height=32, colour = (0,0,0) ):
                array = Numeric.zeros( (height, width, 3),'c')
                array[:,:,] = colour
                image = wxEmptyImage(width,height)
                image.SetData( array.tostring())
                return image.ConvertToBitmap()
  • This example shows use of Numeric's (extended) slicing notation to alter the in-memory image. This slicing notation, for our purposes, goes as follows:

     [ rowStart: rowEnd, columnStart: columnEnd, colourPlanes ] 

    To assign a single colour to the entire image:  array[:,:] = (r,g,b)  . To assign a value to the entire red bit plane:  array[:,:,0] = 255  . To assign a colour to the first row:  array[ 0 ] = (r,g,b )  .

        def GetBitmap( self, width=32, height=32, colour = (128,128,128), border=5, borderColour=(255,255,255) ):
                array = Numeric.zeros( (height, width, 3),'c')
                array[border:-border,border:-border,:] = colour
                array[:border,:,:] = borderColour
                array[-border:,:,:] = borderColour
                array[:,:border,:] = borderColour
                array[:,-border:,:] = borderColour
                image = wxEmptyImage(width,height)
                image.SetData( array.tostring())
                return image.ConvertToBitmap()

Drawing Bitmaps to Screen/Printer Contexts

  • This is basically covered in the demo, but it's part of the topic.

Masks and Transparency/Alpha

  • Bitmap masks (from the demo) Alpha-blending (is this even possible?)

WorkingWithImages (last edited 2011-06-20 15:32:02 by pool-71-244-98-82)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.