Results 1 to 8 of 8

Thread: Vb.net Gdi

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Vb.net Gdi

    how powerfull is the vb.net GDI?


    is it capable of creating something like this? http://www.vbforums.com/showthread.php?t=482303

    something like a 2d tanks game on a scrolling map with lots of different animations?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Vb.net Gdi

    Moved from General Developer

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Vb.net Gdi

    Yes, its possible. Using a Marshall copy, its possible to edit the bytes of the image, very, VERY quickly. This is still though, in my experience, just a slight speed decrease to using direct bitmap pointers in a language like C++ or C#.. probably won't be noticeable though.

    Look into the Marshall Class.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Vb.net Gdi

    whats Marshall Class?

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Vb.net Gdi

    ...

    Thats why I said look into it.. to find out what it was yourself.

    Its basically a class that has different memory management functions. The reason I suggested it was because, one way you can edit a pictures data quickly is to copy its pixel data into a byte array, edit the byte array, then copy it straight back into the picture, all with the Marshal Class.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: Vb.net Gdi

    Quote Originally Posted by psychotomus
    whats Marshall Class?
    I'm dealing with that right now myself. I dont know alot about it, however. From what i gathered, it directly reads/writes from memory. You use it by locking a bitmap in memory, and then modifying it directly, vs having VB modify if for you. I was about to gain about 300 times faster speeds when looking for any pixel values over 200, and changing them 255 while anything under 200 is set to 0 (basically converting an image to B/W). A 640x480 when from .6 FPS using GetPixel SetPixel, to around 200-250FPS using marshal class.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Vb.net Gdi

    is the marshall class built into VB or is this like a pre-built graphics engine by someone else?

  8. #8
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: Vb.net Gdi

    Quote Originally Posted by psychotomus
    is the marshall class built into VB or is this like a pre-built graphics engine by someone else?

    well heres a snippet (ok big snippet) of my program (found it on a website, so I did not create this code)

    you call it by passing your bitmap to it. The this code does the dirty work. You then call bm_bytes.ImageBytes(i) and you can read/write byte value for it. "I" is byte number (imagine if you lined up every byte in you image in a row)

    Code:
    Imports System.Drawing.Imaging
    Imports System.Runtime.InteropServices
    
    Public Class BitmapBytesRGB24
        ' Provide public access to the picture's byte data.
        Public ImageBytes() As Byte
        Public RowSizeBytes As Integer
        Public Const PixelDataSize As Integer = 24
    
        ' Save a reference to the bitmap.
        Public Sub New(ByVal bm As Bitmap)
            m_Bitmap = bm
        End Sub
    
        ' A reference to the Bitmap.
        Private m_Bitmap As Bitmap
    
        ' Bitmap data.
        Private m_BitmapData As BitmapData
    
        ' Lock the bitmap's data.
        Public Sub LockBitmap()
            ' Lock the bitmap data.
            Dim bounds As Rectangle = New Rectangle( _
                0, 0, m_Bitmap.Width, m_Bitmap.Height)
            m_BitmapData = m_Bitmap.LockBits(bounds, _
                Imaging.ImageLockMode.ReadWrite, _
                Imaging.PixelFormat.Format24bppRgb)
            RowSizeBytes = m_BitmapData.Stride
    
            ' Allocate room for the data.
            Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
            ReDim ImageBytes(total_size)
    
            ' Copy the data into the ImageBytes array.
            Marshal.Copy(m_BitmapData.Scan0, ImageBytes, _
               0, total_size)
        End Sub
    
        ' Copy the data back into the Bitmap
        ' and release resources.
        Public Sub UnlockBitmap()
            ' Copy the data back into the bitmap.
            Dim total_size As Integer = m_BitmapData.Stride * m_BitmapData.Height
            Marshal.Copy(ImageBytes, 0, _
                m_BitmapData.Scan0, total_size)
    
            ' Unlock the bitmap.
            m_Bitmap.UnlockBits(m_BitmapData)
    
            ' Release resources.
            ImageBytes = Nothing
            m_BitmapData = Nothing
        End Sub
    End Class

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