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.

A Graphics object cannot be created from an image that has an inde

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Davoli - 26 Apr 2005 21:24 GMT
Why am I getting this message? I get it on both BMP's and GIF's. Do I need to
convert before I create my BitMap? See code below.

A Graphics object cannot be created from an image that has an indexed pixel
format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Exception: A Graphics object cannot be created
from an image that has an indexed pixel format.

Source Error:

Line 26:     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Line 27:         Dim bmp As Bitmap = New
Bitmap("C:\DinasourEye\image_map.gif")
Line 28:         Dim canvas As Graphics = Graphics.FromImage(bmp)
Line 29:         Dim strWatermark As String = "Property of Chris"
Line 30:         canvas.DrawString(strWatermark, New Font("Verdana", 14,
FontStyle.Bold), _


Source File: c:\inetpub\wwwroot\Unleashed\Chapter27\WaterMarkOnImage.aspx.vb
  Line: 28

Stack Trace:

[Exception: A Graphics object cannot be created from an image that has an
indexed pixel format.]
  System.Drawing.Graphics.FromImage(Image image) +206
  Unleashed.WaterMarkOnImage.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\Unleashed\Chapter27\WaterMarkOnImage.aspx.vb:28
  System.Web.UI.Control.OnLoad(EventArgs e) +67
  System.Web.UI.Control.LoadRecursive() +35
  System.Web.UI.Page.ProcessRequestMain() +739



Signature

Chris Davoli

Bob Powell [MVP] - 28 Apr 2005 22:57 GMT
The exception is concise and explicit. You cannot create a Graphics object
for any image with an indexed pixel format. This means GIFs etc.

The only way you can mess with one is to create a non-indexed image of the
same size, obtain a Graphics object for it, draw the original indexed image
to it and then manipulate the new image. Later, if you wish, you can save
the image in an indexed format.

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.

> Why am I getting this message? I get it on both BMP's and GIF's. Do I need
> to
[quoted text clipped - 37 lines]
>   System.Web.UI.Control.LoadRecursive() +35
>   System.Web.UI.Page.ProcessRequestMain() +739
Chris Davoli - 29 Apr 2005 01:20 GMT
Bob,

Do  you have some sample code that does this?

> The exception is concise and explicit. You cannot create a Graphics object
> for any image with an indexed pixel format. This means GIFs etc.
[quoted text clipped - 45 lines]
> >   System.Web.UI.Control.LoadRecursive() +35
> >   System.Web.UI.Page.ProcessRequestMain() +739
Chris Davoli - 29 Apr 2005 01:26 GMT
Is there a way to get the size if the non-indexed image so you can create a
non-idexed image of the same size?

> The exception is concise and explicit. You cannot create a Graphics object
> for any image with an indexed pixel format. This means GIFs etc.
[quoted text clipped - 45 lines]
> >   System.Web.UI.Control.LoadRecursive() +35
> >   System.Web.UI.Page.ProcessRequestMain() +739
Bob Powell [MVP] - 29 Apr 2005 08:43 GMT
Bitmap org=(Bitmap)Image.FromFile(<original image of gif type>);
Bitmap bm=new Bitmap(org.Width, Org.Height); << Can specify optional pixel
format but defaults to 32bppArgb
Graphics g=Graphics.FromImage(bm);
g.DrawImage(org,0,0);
//Draw other stuff on g here...
g.Dispose();
bm.Save(<filename>,<format>);

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.

> Is there a way to get the size if the non-indexed image so you can create
> a
[quoted text clipped - 58 lines]
>> >   System.Web.UI.Control.LoadRecursive() +35
>> >   System.Web.UI.Page.ProcessRequestMain() +739

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.