473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Editing an indexed PixelFormat

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
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 24 '07 #1
1 1892
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" <nj********@hotmail.comwrote in message
news:uT**************@TK2MSFTNGP02.phx.gbl...
>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
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script...
0
by: Webgour | last post by:
Hello, I'm tring to create an indexed image on the fly with the following : Bitmap bcodeBitmap = new Bitmap(50,50,PixelFormat.Format32bppArgb); Graphics objGraphics =...
2
by: Phil Galey | last post by:
If you have a bitmap, but need for it to be of a different PixelFormat, how can you do that? PixelFormat is ReadOnly. Does it have to be done while Drawing to a graphics object? I wonder if...
8
by: **Developer** | last post by:
Seems that Dot.net can not handle files of Indexed Pixel Format as well as other types of formats. Given a file or and Image of type Indexed Pixel Format is there a method to convert it to some...
0
by: Mil | last post by:
Hello, I'm trying to convert Images using Bitmap class. I want to use different options for example reduce the size of image. In my code I tried to create a Bitmap class instance with a...
2
by: Sharon | last post by:
Hello Experts, I'm creating a bitmap object like this: Bitmap myImage = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb); But when I invoking the function myImage...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
1
by: theShmit | last post by:
I am writing a regression testing suite that uses some image comparison features for some RFI (radio frequency interference) testing equipment. I capture an image (from the screen of the device),...
3
tranc3d
by: tranc3d | last post by:
Hello again! I have to generate a large 2 color bitmap (b & w, the layout of a pcb based on gerber file) and for the moment i am drawing into a 24bpp bitmap which is a big waste of memory. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.