Groups | Blog | Home
all groups > dotnet drawing api > july 2007 >

dotnet drawing api : question about Powell's "Creating Transparent GIF Images"


active
7/25/2007 9:23:56 AM
Why couldn't the palette of the saved bitmap be revised and re-inserted back
into that bitmap.

Rather then the time consuming coping of all that bitmap's data to a new
bitmap?


I'm sure knowing that is important to knowing how to work with indexed
files.



Thank


active
7/25/2007 9:35:52 AM
I should have said more.
I have read Powell's comment that makes it sound like (to me anyway) there
are two palettes, one for display and one used while saving.


But the palette in the temporary bitmap (bm) is changed. If that can be
done, why can't the palette in the saved bitmap be changed?

Or why not :
're-insert the palette
_gifImage.Palette=ncp

and be done?

I think there is much to learn from that code.


Thanks


[quoted text, click to view]

active
7/26/2007 3:17:23 PM
I think the thing I was missing is that if I make a new bitmap similar to
one I have and draw the one I have on the new one, even though the colors
and image are exactly the same, the locations in the palette will probable
differ.

I was focused on the fact that they had the same colors so thought the same
palette should work.

(Actually it now seems to me that even the colors in the palette could be
different)

Thanks for helping


[quoted text, click to view]
active
7/26/2007 3:56:49 PM
I still confused about something!
In your Creating Transparent GIF Images why couldn't get the palette from
the bitmap, revise it and then insert it back?

thanks

[quoted text, click to view]

Bob Powell [MVP]
7/26/2007 8:52:26 PM
Palettes do not necessarily contain colours that make logical sense. A
palette may have predominance of blues or greens for example if the
histogram of the image dictates their relative weights as being important.

The contents of a palette won't be in any specific order either, so the
palette produced for a given image will almost certainly not be of any
use on another image.

The only way to ensure that all images are equal (equally bad that is)
is to provide the same palette for all images and the same indexes for
each colour in the palette so that the colour of the pixel itself can be
used to determine the index in the palette. This is how the GDI+ spread
palette works.

All images that originate from basic GDI+ codecs use this palette but it
is just about guaranteed that ANY other program will create a custom
palette for the image simply because this is how GIF was supposed to work.

--
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]
active
7/26/2007 10:25:51 PM
Oh, I believe you no doubt about that!

It's just that in that case there was no changing of indexes nor colors
(except for the high byte)

Thanks for all the help you've given




[quoted text, click to view]
Bob Powell [MVP]
7/26/2007 10:58:12 PM
How many ways do you imagine I can explain "No" in a convincing manner??

--
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]
active
7/27/2007 6:54:51 PM
Please prove me wrong.

I've been looking at this and can't find anything I'm mistaking (but
wouldn't be surprised if someone else does)

I simply reinsert the modified palette and the displayed 8-bit image changes
as expected.

Thanks



'Create a new 8 bit per pixelbitmap

Dim Bm As New Bitmap(SplitContainer3.Panel1.BackgroundImage.Width,
SplitContainer3.Panel1.BackgroundImage.Height,
PixelFormat.Format8bppIndexed)

'get it's palette

Dim NCP As ColorPalette = Bm.Palette

'copy and modify all the entries from the old palette

For n As Integer = 0 To NCP.Entries.Length - 1

If n >= SplitContainer3.Panel1.BackgroundImage.Palette.Entries.Length Then

NCP.Entries(n) = Color.Black

Else

'ncp.Entries(n) = Color.FromArgb(255, GifCP.Entries(n))

'NCP.Entries(n) = Color.FromArgb(255,
SplitContainer3.Panel1.BackgroundImage.Palette.Entries(n).G,
SplitContainer3.Panel1.BackgroundImage.Palette.Entries(n).B,
SplitContainer3.Panel1.BackgroundImage.Palette.Entries(n).R)

'NCP.Entries(n) = Color.FromArgb(255, 0,
SplitContainer3.Panel1.BackgroundImage.Palette.Entries(n).G, 0)

NCP.Entries(n) = Color.FromArgb(255,
SplitContainer3.Panel1.BackgroundImage.Palette.Entries(n).R, 0, 0)

End If

Next n

're-insert the palette

SplitContainer3.Panel1.BackgroundImage.Palette = NCP



'SplitContainer3.Panel1.BackgroundImage is 8-bit indexed



AddThis Social Bookmark Button