|
|
|
start date: Fri, 10 Aug 2007 05:48:01 -0700,
posted on: microsoft.public.dotnet.framework.drawing
back
| Thread Index |
|
1
mcimaging
|
|
2
Michael Phillips, Jr. 0.c0m
|
|
3
Andrew Christiansen
|
A Graphics object cannot be created from an image that has an inde
Hi ,
Bellow is my code.
Dim img As Image = System.Drawing.Image.FromFile("E:\Images\form.gif")
Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
------------------
Error line : Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
-----------------
In that above code .
If i use .GIF images i am getting an Error :
A Graphics object cannot be created from an image that has an indexed?
But if i use .jpg images i am not getting any errors ?
any idea to solve this porblem.
Date:Fri, 10 Aug 2007 05:48:01 -0700
Author:
|
Re: A Graphics object cannot be created from an image that has an inde
> A Graphics object cannot be created from an image that has an indexed?
This a Microsoft "By Design" issue. However, there is nothing stopping you
from using GDI.
You can get a GDI device context for any bitmap. Microsoft's com IPicture,
IPictureDisp intefaces
will load and write .gif files. You can also get a device context dc from
these interfaces so that you
can use any of the GDI functions.
If you want to stick with the System.Drawing API, you either use Lockbits or
convert the .gif to a 24bpp bitmap
work with that bitmap and then recalculate the palette and reindex the
bitmap to 8bpp and finally save it as a .gif.
Check out Bob Powell's excellent site for sample code to work with .gif
palettes and images:
http://www.bobpowell.net/
"mcimaging" wrote in message
news:FC32BC84-9868-4FAA-9E48-981B82104704@microsoft.com...
> Hi ,
> Bellow is my code.
>
> Dim img As Image = System.Drawing.Image.FromFile("E:\Images\form.gif")
>
> Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
>
> ------------------
> Error line : Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
> -----------------
>
>
> In that above code .
> If i use .GIF images i am getting an Error :
> A Graphics object cannot be created from an image that has an indexed?
> But if i use .jpg images i am not getting any errors ?
> any idea to solve this porblem.
>
>
>
>
>
>
Date:Fri, 10 Aug 2007 10:03:46 -0400
Author:
|
Re: A Graphics object cannot be created from an image that has an inde
Create a new bitmap the same size as the GIF, create a graphics object
around that bitmap (it will have a compatible PixelFormat), and draw the GIF
image onto it.
Example:
Using img As Bitmap = Bitmap.FromImage("E:\Images\form.gif")
Dim output As New Bitmap(img.Width, img.Height)
Using g as Graphics = Graphics.FromImage(output)
g.DrawImage(img, 0, 0)
'Do whatever else you need to with this image.
End Using
End Using
Andrew
"mcimaging" wrote in message
news:FC32BC84-9868-4FAA-9E48-981B82104704@microsoft.com...
> Hi ,
> Bellow is my code.
>
> Dim img As Image = System.Drawing.Image.FromFile("E:\Images\form.gif")
>
> Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
>
> ------------------
> Error line : Dim gr As System.Drawing.Graphics = Graphics.FromImage(img)
> -----------------
>
>
> In that above code .
> If i use .GIF images i am getting an Error :
> A Graphics object cannot be created from an image that has an indexed?
> But if i use .jpg images i am not getting any errors ?
> any idea to solve this porblem.
>
>
>
>
>
>
Date:Fri, 10 Aug 2007 11:44:19 -0500
Author:
|
|
|