By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Help: simple resizing gif - why is it so hard...

P: n/a
Hello:
Using asp.net (vb) and I dont want to use active X controls - just server
side code.
I have uploaded a gif file but I want to resample it to a smaller size like
100 by 100 and save it to a file - simple ? right ?

Upload -> Original.gif
resample
save as ->resampled.gif

I get a range of errors ranging from: A generic error occurred in GDI+.
to:
A Graphics object cannot be created from an image that has an indexed pixel
format
-----------------------------------------------------------------------------------------------------------------------------------
Dim CurrentBitMap As Image = New Bitmap(TargetWidth, TargetHeight,
CurrentImage.PixelFormat)
Dim CurrentGraphics As Graphics = Graphics.FromImage(CurrentBitMap)
CurrentGraphics.CompositingQuality = CompositingQuality.HighQuality
CurrentGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic
Dim CurrentRectangle = New Rectangle(0, 0, TargetWidth, TargetHeight)
CurrentGraphics.DrawImage(CurrentImage, CurrentRectangle)
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
' save the picture in it's original format
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
Try
Select Case UCase(Ext)
Case ".JPEG"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Jpeg)
Case ".BMP"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Bmp)
Case ".GIF"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Gif)
End Select
Catch ex As Exception
Announce("Error Attempting to convert " & SourcePhysicalPath & " to " &
DestinationPhysicalPath, Color.Yellow, Color.Red)
End Try

---------------------------------------------------------------------------------------------------------------------------------------------------------

I get this error:
A Graphics object cannot be created from an image that has an indexed pixel
format.
Line 271: Dim CurrentGraphics As Graphics =
Graphics.FromImage(CurrentBitMap)

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
See the GDI+ FAQ for details.

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

"Support" <Re****************@mail.oci.state.ga.us> wrote in message
news:uL**************@TK2MSFTNGP14.phx.gbl...
Hello:
Using asp.net (vb) and I dont want to use active X controls - just server
side code.
I have uploaded a gif file but I want to resample it to a smaller size
like 100 by 100 and save it to a file - simple ? right ?

Upload -> Original.gif
resample
save as ->resampled.gif

I get a range of errors ranging from: A generic error occurred in GDI+.
to:
A Graphics object cannot be created from an image that has an indexed
pixel format
-----------------------------------------------------------------------------------------------------------------------------------
Dim CurrentBitMap As Image = New Bitmap(TargetWidth, TargetHeight,
CurrentImage.PixelFormat)
Dim CurrentGraphics As Graphics = Graphics.FromImage(CurrentBitMap)
CurrentGraphics.CompositingQuality = CompositingQuality.HighQuality
CurrentGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic
Dim CurrentRectangle = New Rectangle(0, 0, TargetWidth, TargetHeight)
CurrentGraphics.DrawImage(CurrentImage, CurrentRectangle)
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
' save the picture in it's original format
'+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++
Try
Select Case UCase(Ext)
Case ".JPEG"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Jpeg)
Case ".BMP"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Bmp)
Case ".GIF"
CurrentBitMap.Save(DestinationPhysicalPath,
System.Drawing.Imaging.ImageFormat.Gif)
End Select
Catch ex As Exception
Announce("Error Attempting to convert " & SourcePhysicalPath & " to " &
DestinationPhysicalPath, Color.Yellow, Color.Red)
End Try

---------------------------------------------------------------------------------------------------------------------------------------------------------

I get this error:
A Graphics object cannot be created from an image that has an indexed
pixel format.
Line 271: Dim CurrentGraphics As Graphics =
Graphics.FromImage(CurrentBitMap)


Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.