Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Drawing / April 2005

Tip: Looking for answers? Try searching our database.

Problem with Palette's, ARGB, bitmaps

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dale.thayer@netzero.net - 25 Apr 2005 05:48 GMT
Hello,

The following code complains that "Index was outside the bounds of the
array" for the line inside the for loop that assigns the Color to the
palette.  Any suggestions:

            currentBitmap = new
Bitmap(640,480,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            System.Drawing.Imaging.ColorPalette palette = currentBitmap.Palette;

            for(int j=0;j<256;j++)
            {
                palette.Entries[j] = Color.FromArgb(255,j,j,j);
            }
           
            currentBitmap.Palette = palette;

Dale
Jacky Kwok - 25 Apr 2005 07:29 GMT
> Hello,
>
[quoted text clipped - 14 lines]
>
> Dale

It beacuse the length of palette.Entries is 0 of a Format32bppArgb image.

ColorPalette just will be used in indexed color image.
If the Bitmap is PixelFormat.Format8bppIndexed, it will has a 256
entries length palette.

Signature

Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
jacky@compose_DOT_com_DOT_hk

Bob Powell [MVP] - 25 Apr 2005 10:03 GMT
32 bit images don't require a palette. Only indexed image formatssuch as
8bpp or 1bpp will need them.

Signature

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

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.

> Hello,
>
[quoted text clipped - 14 lines]
>
> Dale
TroLoo - 25 Apr 2005 14:53 GMT
> 32 bit images don't require a palette. Only indexed image formatssuch as
> 8bpp or 1bpp will need them.

Do you have any examples of using palettes?

I'm working on a drawing app which allows to draw on JPGs, BMPs, etc. I
noticed that 'Graphics.CreateFromImage(...)' doesn't work for indexed
images. What should I use instead? (I guess palettes but don't have a
clue how :) ).

Signature

Regards,

TroLoo

Bob Powell [MVP] - 25 Apr 2005 19:13 GMT
There are two ways to draw on an indexed image.

#1 Convert the indexed image to 24 or 32 bpp, draw on it and then save it as
an indexed image again.

#2 Draw the new pixels onto a 32 bpit per pixel image and then merge the two
using code that employs the LockBits method to access the byte array of the
indexed image directly.

Signature

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

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.

>> 32 bit images don't require a palette. Only indexed image formatssuch as
>> 8bpp or 1bpp will need them.
[quoted text clipped - 5 lines]
> images. What should I use instead? (I guess palettes but don't have a clue
> how :) ).
TroLoo - 27 Apr 2005 12:48 GMT
> #1 Convert the indexed image to 24 or 32 bpp, draw on it and then save it as
> an indexed image again.

Ok, it would mean that I have to remember PixelFormat of the image I'm
loading and after modifying it, convert to this base format, right?
Well, it's pretty straight forward and a good idea but requires
implementation of conversion alghorithms (24bpp->16bpp, 16bpp->8bpp,
etc.). As far as I know it's not that easy to convert image to indexed
format and save good quality of it (requires recalculation of palette by
some nice working alghorithm)... I'm thinking 'loudly' so that you can
either approve or reject my ideas :) Any help will be strongly appreciated!

But I have another small question - first I explain my idea: I create
24bpp bitmap of the same resolution as my original image and draw
original image on it. In this way I have no problem converting
PixelFormat upwards. But when I create new 24bpp Bitmap to draw original
image on it, I loose HorizontalResolution. For instance - I have 300dpi
image of size 1008 x 1491. After creating Bitmap of the same size, I
obtain 96dpi picture.

> #2 Draw the new pixels onto a 32 bpit per pixel image and then merge the two
> using code that employs the LockBits method to access the byte array of the
> indexed image directly.

Also good idea, I have to think about it a little :)

Signature

Regards,

TroLoo


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.