Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:04:14+00:00 2026-06-01T20:04:14+00:00

I am learning wxPython. My question is how create bit map. I have R,

  • 0

I am learning wxPython. My question is how create bit map. I have R, G, B values for each pixel but I don’t know how create bit map from it. I tried use wx.BitmapFromBuffer, I don’t understand how should I create this buffer. I went through each pixel and in linear way put in list R, G, B components, but it did not draw what I expected. Do you understand how the buffer should be constructed?.

I don’t want draw each pixel on bitmap using wx.MemoryDC because it is too slow.

Thank you!

Edit:
I use approach from wxPython demo – RawBitmapAccess.

    buf = numpy.empty((w,h,3), numpy.uint8)
    n = 29000
    for i in xrange(w):
        for j in xrange(h):
            r = int(n*255*field[j,i])
            if r > 253: 
                r = 253
            buf[i, j, 0] = int(r)
            buf[i, j, 1] = int(r)
            buf[i, j, 2] = int(b)
            #dc.SetPen(wx.Pen(wx.Colour(r,r,b)))
            #dc.DrawPoint(i,j)
    bmp = wx.BitmapFromBuffer(w, h, buf)
    gc = wx.GraphicsContext.Create(dc)
    gc.DrawBitmap(bmp, 0, 0, w, h)

If I uncomment my old way of drawing (two commented lines in the loop) then I got what I want – one fuzzy ball. If I don’t uncomment them that I have odd picture – it is splitted vertically for several fragments, each have it own fuzzy ball, plus it look like that there is vertical lines of missed pixels.
I use buffer in the same way as in demo program. Why I get weird picture?

Edit2:
I figure out it. I should swap i and j in the loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:04:15+00:00Added an answer on June 1, 2026 at 8:04 pm

    As I posted in my previous answer, this is done using numpy, and there’s an example in the demo call RawBitmapAccess. The code basically looks like,

    def MakeBitmap2(self, red, green, blue, alpha=128):
        # Make an array of bytes that is DIM*DIM in size, with enough
        # slots for each pixel to have a RGB and A value
        #arr = makeByteArray( (DIM,DIM, 4) )
        arr = numpy.empty((DIM,DIM, 4), numpy.uint8)
    
        # just some indexes to keep track of which byte is which
        R, G, B, A = range(4)
    
        # initialize all pixel values to the values passed in
        arr[:,:,R] = red
        arr[:,:,G] = green
        arr[:,:,B] = blue
        arr[:,:,A] = alpha
    
        # Set the alpha for the border pixels to be fully opaque
        arr[0,     0:DIM, A] = wx.ALPHA_OPAQUE  # first row
        arr[DIM-1, 0:DIM, A] = wx.ALPHA_OPAQUE  # last row
        arr[0:DIM, 0,     A] = wx.ALPHA_OPAQUE  # first col
        arr[0:DIM, DIM-1, A] = wx.ALPHA_OPAQUE  # last col
    
        # finally, use the array to create a bitmap
        bmp = wx.BitmapFromBufferRGBA(DIM, DIM, arr)
        return bmp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning Ruby. Needed to create a hash of arrays. This works... but I don't
Learning Javascript and have a question about global variables. From my reading, most recommend
Learning from my broad question here ... I was wondering how I could go
I'm learning python and wxPython at the same time... :) So, I have a
Learning from my last question , most member names seem to get included in
learning Jquery and integrating with PHP - getting there, but have one last challenge
Learning R language - I know how to do a moving average but I
Ok, so I'm learning about sizers in wxPython and I was wondering if it
Learning Scala currently and needed to invert a Map to do some inverted value->key
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.