473,569 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 24 '07 #1
1 1915
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" <nj********@hot mail.comwrote in message
news:uT******** ******@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
nj********@hotm ail.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
2389
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 here http://www.pbrown.com/research/test1.php to see the formatting issues Formatting Issues
0
1518
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 = Graphics.FromImage(bcodeBitmap); objGraphics.FillRectangle(new SolidBrush(Color.White), new
2
1483
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 there's a code sample available somewhere in which this is done. Thanks Phil Galey
8
12581
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 other pixel format? Thanks
0
3823
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 Bitmap's constructor: new Bitmap(source.Width, source.Height, PixelFormat.Format8bppIndexed);
2
7503
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 .MakeTransparent() (with or without parameters), the myImage.PixelFormat changes to Format32bppArgb. Why is that and how can I avoid it but still...
8
4299
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 FromImage call will fail for indexed bitmaps.
1
6457
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), and save this first image as a reference as “what the screen should look like;” then when executing a “macro” on the device, I will then capture...
3
6029
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 problem is that i don't know how to do it because visual studio throws me an exception when i try to create a graphics object based on the 1bpp...
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.