Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Interface and Graphics > Cannot Bitmap.SetPixel twice


Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2004, 01:31 PM
chaos syndrome chaos syndrome is offline
Newcomer
 
Join Date: Jan 2004
Posts: 8
Default Cannot Bitmap.SetPixel twice


I'm using the following code to generate a sort of spotted texture which can then be mapped onto a sphere.

Unfortunately it doesn't seem to work: the first call to CreateCrater does the job fine but subsequent calls produce no result. On rewriting the code it seems that after using the Bitmap.SetPixel method it is impossible to subsequently use Bitmap.SetPixel on that same pixel.

Is there some method I need to call to reset the bitmap to a state where the pixels can be written again?

Thanks.

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        Dim b As New Bitmap(800, 400, Imaging.PixelFormat.Format24bppRgb)
        'For i = 1 To 10
        'CreateCrater(b, RangedRandom(-180, 180), RangedRandom(-90, 90), RangedRandom(1000, 5000))
        'Next
        CreateCrater(b, 0, 0, 1000)
        CreateCrater(b, 0, -90, 1000)
        b.Save("cratered.bmp", Imaging.ImageFormat.Bmp)
        b.Dispose()
        Button1.Enabled = True
    End Sub

    Private Function SphereDistance(ByVal long1 As Single, ByVal lat1 As Single, ByVal long2 As Single, ByVal lat2 As Single)
        ' Maths stuff which is irrelevant to the topic. I think.
    End Function

    Private Sub CreateCrater(ByRef b As Bitmap, ByVal longitude As Single, ByVal latitude As Single, ByVal radius As Single)
        Dim pixX, pixY As Integer
        Dim myrect As RectangleF = b.GetBounds(GraphicsUnit.Pixel)
        For pixX = myrect.Left To myrect.Right - 1
            For pixY = myrect.Top To myrect.Bottom - 1
                Dim lng As Single = pixX / myrect.Width * 360 - 180
                Dim lat As Single = pixY / myrect.Height * 180 - 90
                Dim dist As Single = SphereDistance(lng, lat, longitude, latitude)
                Dim v As Integer = 0
                If dist <= radius Then
                    v = 255 ' For now. Will be replaced by more advanced function later.
                End If
                Dim mycol As Color = Color.FromArgb(v, v, v)
                b.SetPixel(pixX, pixY, mycol)
            Next
        Next
    End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->