all groups > dotnet drawing api > july 2007 >
You're in the

dotnet drawing api

group:

How would you change the size of a Format8bppIndexed bitmap?


How would you change the size of a Format8bppIndexed bitmap? active
7/14/2007 8:07:19 PM
dotnet drawing api: I need to change the size of an Format8bppIndexed image.

I suppose I could change the format and scale it and put it back.

But I'm wondering if there is a more straight forward way.


How would you change the size of a Format8bppIndexed bitmap?


Thanks

Re: How would you change the size of a Format8bppIndexed bitmap? Bob Powell [MVP]
7/15/2007 12:00:00 AM
Changing the size will almost definitely result in changing the palette so
the reults may be less than stellar.

I would load the image, Create a 24 bit image of the new size, draw the 8
bit to the new image, calculate a new palette for the 24bit image and then
save the new image as 8 bit using the new palette.

See the articles in the FAQ about GIF palettes.

--
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.



[quoted text, click to view]

Re: How would you change the size of a Format8bppIndexed bitmap? active
7/15/2007 10:21:13 AM

[quoted text, click to view]

Why wouldn't the original palette work OK? Won't the colors be very similar
to the original?

Also, I wasn't clear. I don't need to save it, just display it. If that
makes any difference to your answer. Can I simply convert the new image to
8-bits - how - I believe I can't draw it into an 8-bit bitmap?


thanks


[quoted text, click to view]

Re: How would you change the size of a Format8bppIndexed bitmap? active
7/15/2007 7:53:43 PM
Displaying turned out to be simple.


[quoted text, click to view]

Re: How would you change the size of a Format8bppIndexed bitmap? Bob Powell [MVP]
7/22/2007 3:27:41 PM
Under GDI+ new 8bpp images are assigned a "spread palette" which is a
palette that simply contains a selection of common colours that are supposed
to suit all images but in reality is a bad choice for almost all images.

You can almost guarantee that the original palette will be unusable because
the index mappings will depend entirely on the algorithm used to generate
the dedicated palette.

It is therefore a laborious process as I outlined.

--
--
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.


[quoted text, click to view]
Re: How would you change the size of a Format8bppIndexed bitmap? active
7/23/2007 9:58:45 PM

[quoted text, click to view]


The following is what I've done so far.

I haven't yet looked into calculating a new palette (if needed).

I could sure use your comments!



mGifImage = Image.FromFile(dlg.FileName)

Dim newBitmap As Bitmap = New Bitmap(200, 200, PixelFormat.Format24bppRgb)

'Is newBitmap palette "spread palette" ?



Dim gr As Graphics = Graphics.FromImage(newBitmap)

gr.DrawImage(mGifImage, 0, 0, 200, 200)

'Is newBitmap palette from mGifImage or spread palette?



Dim ms As New MemoryStream()

newBitmap.Save(ms, ImageFormat.Gif)

'is ms palette newBitmap palette or created?



ms.Seek(0, SeekOrigin.Begin)

Dim outReader As BinaryReader = New BinaryReader(ms)

Dim newBitmap2 As Bitmap = New Bitmap(ms)

'is newBitmap2 palette from ms or spread palette?



Re: How would you change the size of a Format8bppIndexed bitmap? active
7/29/2007 1:25:25 PM

[quoted text, click to view]


[quoted text, click to view]
Bob,
I thought you'd like to know that the link in the following page is not good
any more.
Maybe it'll come back but I figured it best to pass the info on.
http://www.bobpowell.net/colourquantization.htm

I've been looking for code to calculate the new palette - if I find some
I'll pass it on.



[quoted text, click to view]

AddThis Social Bookmark Button