Editing an indexed PixelFormat

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    #1

    Editing an indexed PixelFormat

    I have created declared a Bitmap using the following statement:

    Dim bmp As New Bitmap(100, 100, PixelFormat.For mat8bppIndexed)

    Because the SetPixel() method is disabled and a Graphics object cannot be
    created for indexed PixelFormats, I am not sure how to edit the Bitmap. I am
    assuming that there is some class or technique other than the following:

    Dim bmpdata As BitmapData = bmp.LockBits(Ne w Rectangle(0, 0, bmp.Width,
    bmp.Height), ImageLockMode.R eadOnly, PixelFormat.For mat8bppIndexed)
    For y As Integer = 0 To bmp.Height - 1
    For x As Integer = 0 To bmp.Width - 1
    System.Diagnost ics.Debug.Write Line(System.Run time.InteropSer vices.Marshal.R eadByte(bmpdata .Scan0,
    y * bmpdata.Stride + x))
    Next
    Next
    bmp.UnlockBits( bmpdata)

    Which is basically just directly changing the data that will be saved when
    the Bitmap is saved. However, using the technique shown above can make it
    require multiple steps and calculations when drawing shapes such as
    ellipses. Is there a more efficient way to edit an indexed Bitmap? Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Michael Phillips, Jr.

    #2
    Re: Editing an indexed PixelFormat

    Is there a more efficient way to edit an indexed Bitmap?

    If you use any of the CLR routines, you are stuck with LockBits.

    If you are willing to use P-Invoke, you can avail yourself of the many GDI
    routines which provide direct access to the image's memory
    and allow the use of fast BitBlt and similar functions that will operate on
    all image pixel formats including indexed.

    Create your indexed bitmap with CreateDIBSectio n and you will have all of
    the fast GDI functions at your disposal.
    CreateDIBSectio n returns a pointer to the image's memory that can be
    directly accessed without locking and unlocking.

    You can still mix and match the managed and unmanaged image API's.
    You can still benefit from the System.Drawing namespace methods.


    "Nathan Sokalski" <njsokalski@hot mail.comwrote in message
    news:uTspDklLIH A.2268@TK2MSFTN GP02.phx.gbl...
    >I have created declared a Bitmap using the following statement:
    >
    Dim bmp As New Bitmap(100, 100, PixelFormat.For mat8bppIndexed)
    >
    Because the SetPixel() method is disabled and a Graphics object cannot be
    created for indexed PixelFormats, I am not sure how to edit the Bitmap. I
    am assuming that there is some class or technique other than the
    following:
    >
    Dim bmpdata As BitmapData = bmp.LockBits(Ne w Rectangle(0, 0, bmp.Width,
    bmp.Height), ImageLockMode.R eadOnly, PixelFormat.For mat8bppIndexed)
    For y As Integer = 0 To bmp.Height - 1
    For x As Integer = 0 To bmp.Width - 1
    >
    System.Diagnost ics.Debug.Write Line(System.Run time.InteropSer vices.Marshal.R eadByte(bmpdata .Scan0,
    y * bmpdata.Stride + x))
    Next
    Next
    bmp.UnlockBits( bmpdata)
    >
    Which is basically just directly changing the data that will be saved when
    the Bitmap is saved. However, using the technique shown above can make it
    require multiple steps and calculations when drawing shapes such as
    ellipses. Is there a more efficient way to edit an indexed Bitmap? Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。

    >

    Comment

    Working...