HighTechTalks DotNet Forums  

Editing an indexed PixelFormat

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Editing an indexed PixelFormat in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default Editing an indexed PixelFormat - 11-23-2007 , 11:15 PM






I have created declared a Bitmap using the following statement:

Dim bmp As New Bitmap(100, 100, PixelFormat.Format8bppIndexed)

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(New Rectangle(0, 0, bmp.Width,
bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed)
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
System.Diagnostics.Debug.WriteLine(System.Runtime. InteropServices.Marshal.ReadByte(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 (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Editing an indexed PixelFormat - 11-24-2007 , 08:59 AM






Quote:
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 CreateDIBSection and you will have all of
the fast GDI functions at your disposal.
CreateDIBSection 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 (AT) hotmail (DOT) com> wrote

Quote:
I have created declared a Bitmap using the following statement:

Dim bmp As New Bitmap(100, 100, PixelFormat.Format8bppIndexed)

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(New Rectangle(0, 0, bmp.Width,
bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed)
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1

System.Diagnostics.Debug.WriteLine(System.Runtime. InteropServices.Marshal.ReadByte(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 (AT) hotmail (DOT) com
http://www.nathansokalski.com/




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.