Bitmap PixelFormat Conversion

  • Thread starter Thread starter Flix
  • Start date Start date
F

Flix

Is there some way to convert a Bitmap from one PixelFormat (16bit or with
indexed colors) to another(24bit), without doing per pixel operations?
 
You can convert from any format to 32 or 24 bpp easily. However, converting
to an indexed format from either of those requires the use of per-pixel
operations.

Ideally you'd use LockBits to facillitate these operations

See the GDI+ FAQ for details. It demonstrates LockBits and how to convert
from 32bpp into 1bpp.

--
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.
 
Hi Flix,

I found this:

private void button3_Click(object sender, System.EventArgs e)
{
Bitmap b1=new Bitmap("augustinus_16ColorBitmap.bmp");

Bitmap b2=new
Bitmap(b1.Size.Width,b1.Size.Height,System.Drawing.Imaging.PixelFormat.Forma
t24bppRgb);
Graphics g = Graphics.FromImage(b2);
g.DrawImage(b1,new Point(0,0));
g.Dispose();

System.Console.WriteLine("b1.PixelFormat="+ b1.PixelFormat.ToString());
System.Console.WriteLine("b2.PixelFormat="+ b2.PixelFormat.ToString());

this.BackgroundImage=b2;
}

Christiaan.
 

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