locked
How to render pixels in store apps, Writablebitmaps? RRS feed

  • Question

  • I need to write pixels to the screen for rendering fractals, in a Windows Store App in VB.

    I assume this is done with a Writablebitmap, but I have yet to find an example in VB.  Most are in C#.  The documentation says it requires language specific features to accomplish, so could somebody enlighten me?  Just an example that renders 100x100 pixels with random colors would be more than enough.  Thank you.

    Sunday, September 22, 2013 12:18 AM

All replies

  • Hi Dan,

    Welcome to MSDN Forum!

    I have moved this thread to Windows Store apps forum for better response.

    Best regards,
    Franklin


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 1:10 AM
    Moderator
  • Hi Dan,

    Take a look at the XAML images sample (Windows 8) . Scenario 4 draws a Mandelbrot set in a WriteableBitmap, and the sample is available in VB.

    --Rob

    Monday, September 23, 2013 1:13 AM
    Moderator
  • It took a while to isolate it, but does this look reasonable?  Not counting ignoring possible extra bytes in the bitmap due to rounding, that is?


            Dim BM As New WriteableBitmap(128, 128)

            Dim MyBytes(((128 * 4) * 128) - 1) As Byte
            Dim x, y As Integer

            Dim myrand As New Random
            Dim Pointer As Integer

            For y = 0 To 127
                For x = 0 To 127
                    Pointer = (y * 512) + (x * 4) '512=128*4
                    MyBytes(Pointer) = myrand.Next(0, 255)
                    MyBytes(Pointer + 1) = myrand.Next(0, 128)
                    MyBytes(Pointer + 2) = myrand.Next(0, 64)
                    MyBytes(Pointer + 3) = 255
                Next
            Next

            ' Open a stream to copy the graph to the WriteableBitmap's pixel buffer
            Using mystream As Stream = BM.PixelBuffer.AsStream()
                mystream.Write(MyBytes, 0, MyBytes.Length)
            End Using
       


            BM.Invalidate()

            MyImage.Source=bm


            MyText.Text = "done"

    Monday, September 23, 2013 8:23 PM