Can a indexed pixel format be converted to some other format?

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**Developer**

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
 
..NET can indeed handle indexed pixel files. You can load an image in GIF
format and save it in JPEG format very simply. You just need the correct
ImageFormat setting.

--
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.
 
I think my comment was too general by referencing all of DotNet.

I believe I got an exception when I tried to create a Graphics object for
such an Image object.

Thanks
 
Took me a while to run my program because VS2000. Couldn't run the debugger,
it told me to rerun Setup which I did. That took a while.

Anyway the following is the statement that causes the exception

mPicGraphics = Graphics.FromImage(PictureBoxDocument.Image)



The exception

System.Exception: A Graphics object cannot be created from an image that has
an indexed pixel format.
at System.Drawing.Graphics.FromImage(Image image)


Thanks
 
You don't need to get a Graphics object for an image that you want to save
in a different format.

--
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.
 
I want to do various thing with the image: crop it, copy to clipboard,
rotate it, ...
thanks
 
This is where I am now. Two problems:

1) I don't know what is a good PixelFormat to use.
What is the default?


2)ClonedBitmap has the same (Indexed) PixelFormat as ReadBitmap.
I was hopping it would be converted to Format32bppPArgb (even tho I don't
know that's a good one.)

Thanks for any help

Dim Filestream As Filestream = New Filestream(OpenFileDialog1.FileName,
FileMode.Open)

Dim ReadBitmap As New Bitmap(Filestream)

Dim CloneRect As New RectangleF(0, 0, ReadBitmap.Width, ReadBitmap.Height)

Dim ClonedBitmap = ReadBitmap.Clone(CloneRect,
Imaging.PixelFormat.Format32bppPArgb)
 
Bob

I just signed on to tell you that I had found the answers on your site.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top