473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to "set" the PixelFormat for a bitmap?

I need to use the bitmap.getpixel method to work on the pixel level of
an image. But GetPixel will not work with Indexed images. The images
that i work with are black & white text scans.

I create the bitmap object like this:
Dim b As Bitmap = Bitmap.FromFile("c:\scan.tif")

But I want to convert this file to PixelFormat.Format24bppRgb (or
something NOT indexed)

PixelFormat.Format24bppRgb is Read Only, so i can't simply do:
b.pixelFormat = PixelFormat.Format24bppRgb

Bitmap has an overload that allows the Pixelformat to be specified, but
the overload cannot accept a file name for my tiff, just a width and
height. If I use that overload, my bitmap object ends up blank. I
need it to hold image data.

I'm totally stumped. Can anyone help?

Thanks!
John

Nov 21 '05 #1
3 37622
You must create a new bitmap of the same size as the indexed one and then
draw the indexed bitmap to the new bitmap. This will convert all the colours
to 32 bit and enable you to draw on the bitmap.

Bitmap bm=new Bitmap(org.Width, org.Height <,optional pixel format>);
bm.SetResolution(org.HorizontalResolution, org.VerticalResolution);
Graphics g=Graphics.FromImage(bm);
g.DrawImage(org,0,0);

//continue to draw on g here to add text or graphics.

g.Dispose();
bm.Save(......);

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"johnb41" <or****@informatik.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I need to use the bitmap.getpixel method to work on the pixel level of
an image. But GetPixel will not work with Indexed images. The images
that i work with are black & white text scans.

I create the bitmap object like this:
Dim b As Bitmap = Bitmap.FromFile("c:\scan.tif")

But I want to convert this file to PixelFormat.Format24bppRgb (or
something NOT indexed)

PixelFormat.Format24bppRgb is Read Only, so i can't simply do:
b.pixelFormat = PixelFormat.Format24bppRgb

Bitmap has an overload that allows the Pixelformat to be specified, but
the overload cannot accept a file name for my tiff, just a width and
height. If I use that overload, my bitmap object ends up blank. I
need it to hold image data.

I'm totally stumped. Can anyone help?

Thanks!
John

Nov 21 '05 #2
Sorry, that sample code was in C#. in VB...

Dim bm as new Bitmap(org.Width, org.Height <,optional pixel format>)
bm.SetResolution(org.HorizontalResolution, org.VerticalResolution)
Dim g as Graphics = Graphics.FromImage(bm)
g.DrawImage(org,0,0)

'continue to draw on g here to add text or graphics.

g.Dispose()
bm.Save(......)

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"johnb41" <or****@informatik.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I need to use the bitmap.getpixel method to work on the pixel level of
an image. But GetPixel will not work with Indexed images. The images
that i work with are black & white text scans.

I create the bitmap object like this:
Dim b As Bitmap = Bitmap.FromFile("c:\scan.tif")

But I want to convert this file to PixelFormat.Format24bppRgb (or
something NOT indexed)

PixelFormat.Format24bppRgb is Read Only, so i can't simply do:
b.pixelFormat = PixelFormat.Format24bppRgb

Bitmap has an overload that allows the Pixelformat to be specified, but
the overload cannot accept a file name for my tiff, just a width and
height. If I use that overload, my bitmap object ends up blank. I
need it to hold image data.

I'm totally stumped. Can anyone help?

Thanks!
John

Nov 21 '05 #3
Bob,

Thanks, that helped alot! By the way, thanks for your web site. I've
learned alot from it the past couple weeks! :)

John

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #4

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

Similar topics

3
1723
by: Anthony Liu | last post by:
I want to use the set function like mylist = myset = set (mylist) But I don't know what to import, I tried sys, sets, they don't work. What's the easy way to find out the module that...
3
1520
by: Skip Montanaro | last post by:
I use sets a lot in my Python 2.3 code at work and have been using this hideous import to make the future move to 2.4's set type transparent: try: x = set except NameError: from sets import...
1
3897
by: J. Muenchbourg | last post by:
The following line in part of my asp-sql block: Set rs = Server.CreateObject("ADODB.Recordset") creates an application error: "Set" assignment statements are no longer supported (in this...
7
3581
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
10
17183
by: Mart | last post by:
What class does everyone out there use if they want to store a set of values efficiently? In java I use a HashSet, but there is no equivalent in C#. Even worse, the lowest level interface to...
9
3486
by: Anders Borum | last post by:
Hello! I have a class that needs to validate the input value, when a programmer changes a specific property on a class. The input should only accept the following pattern {1,n} (alpha-numeric...
2
1715
by: Anders Borum | last post by:
Hello! I was looking at marking objects with a changed state, once properties have been changed. The reason behind this is, that I would like to enlist such objects for processing in a...
23
3159
by: Phil Powell | last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY AND THUS EXPIRE function setCookie(name, value, days, docObj)...
1
1977
by: slrj | last post by:
Can I use a local struct to store data in the "set" conatiner? If so, what is the correct method to do so? Compiler: Sun Studio 10 on Unix (Sun Solaris) #include<iostream> #include<set> ...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
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,...
0
3188
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
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...

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.