Results 1 to 19 of 19

Thread: Fast update of bitmap from polar coordinate data

Threaded View

  1. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Fast update of bitmap from polar coordinate data

    Hi chriscross,

    It's nice to see you are using FastPix. Here's a suggestion for what I think will be a more efficient approach. Instead of plotting the points directly to the picturebox Image, plot them to a single horizontal line:

    Code:
    Dim radialLine As New Bitmap(scale, 1)
    
    Using fp As New FastPix(radialLine)
       Dim Pixels() As Integer = fp.PixelArray
       For radius As Integer = 0 To Scale - 1
           Pixels(radius) = &HFF000000 + echo(radius) * 257 * 256 'I may have to explain this!
       Next
    End Using
    I've used my favourite FastPix version, the Integer array, because it's far away the most efficient. Still, I'm not certain that the above will actually be much faster than old-fashioned Bitmap.SetPixel, because the number of pixels involved is probably small and Lockbits/FastPix has an overhead.

    Now you have a horizontal line plotted in the correct colours. Next draw it at the required angle on your target bitmap. I'll assume you want to draw the full sweep circle, not just the single line. Otherwise use g.Clear to clear the graphics.

    Code:
    'At form level:
    Dim bm As New Bitmap(PictureBox1.Width, PictureBox1.Height)
    
    'In your sub:
    Using g As Graphics = Graphics.FromImage(bm)
         Using mtx As New Drawing2d.Matrix
               mtx.RotateAt(angle, New Point(500, 500)) 'no need to convert to radians
               g.Transform = mtx 'rotate the Graphics
         End Using
         g.DrawImageUnscaled(radialLine, 500, 500)
    End Using
    PictureBox1.Image = bm
    This is just a sketch and I haven't tried it out (yet) but I hope the idea is clear enough. You might gain some speed by doing your own maths and using a lookup table, but my impression is that GDI+ is pretty efficient with things like rotating the graphics. And I hope you'll agree this is much simpler.

    BB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width