473,698 Members | 2,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

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(TargetWi dth, TargetHeight,
CurrentImage.Pi xelFormat)
Dim CurrentGraphics As Graphics = Graphics.FromIm age(CurrentBitM ap)
CurrentGraphics .CompositingQua lity = CompositingQual ity.HighQuality
CurrentGraphics .InterpolationM ode = InterpolationMo de.HighQualityB icubic
Dim CurrentRectangl e = New Rectangle(0, 0, TargetWidth, TargetHeight)
CurrentGraphics .DrawImage(Curr entImage, CurrentRectangl e)
'++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
' save the picture in it's original format
'++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
Try
Select Case UCase(Ext)
Case ".JPEG"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
Case ".BMP"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Bmp)
Case ".GIF"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Gif)
End Select
Catch ex As Exception
Announce("Error Attempting to convert " & SourcePhysicalP ath & " to " &
DestinationPhys icalPath, 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.FromIm age(CurrentBitM ap)

Nov 21 '05 #1
1 1322
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.s tate.ga.us> wrote in message
news:uL******** ******@TK2MSFTN GP14.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.gi f

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(TargetWi dth, TargetHeight,
CurrentImage.Pi xelFormat)
Dim CurrentGraphics As Graphics = Graphics.FromIm age(CurrentBitM ap)
CurrentGraphics .CompositingQua lity = CompositingQual ity.HighQuality
CurrentGraphics .InterpolationM ode = InterpolationMo de.HighQualityB icubic
Dim CurrentRectangl e = New Rectangle(0, 0, TargetWidth, TargetHeight)
CurrentGraphics .DrawImage(Curr entImage, CurrentRectangl e)
'++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
' save the picture in it's original format
'++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++ +
Try
Select Case UCase(Ext)
Case ".JPEG"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
Case ".BMP"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Bmp)
Case ".GIF"
CurrentBitMap.S ave(Destination PhysicalPath,
System.Drawing. Imaging.ImageFo rmat.Gif)
End Select
Catch ex As Exception
Announce("Error Attempting to convert " & SourcePhysicalP ath & " to " &
DestinationPhys icalPath, 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.FromIm age(CurrentBitM ap)


Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11256
by: Clyde Ellul | last post by:
Hi there. I need to write a simple program that reads a GIF image from an input stream, resizes it, then writes it back to an output stream in the same format (GIF). (JPEG input/output is good too, but GIF is preferrable). JAI can do this sort of but can't write to GIF format. Also, it looks too complicated for what I need; I'm a bit in a hurry... Is there a simple way of doing what I want? Is there a free,
86
7770
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that: http://www.clagnut.com/blog/348/ I hope that's going to be a good discussion! Michael
46
4683
by: Blue Ocean | last post by:
How do I do it? I'm doing a practice problem which includes me implementing a set of ints as a class. I don't want to use vector because that would be cheating. ;) I don't want to spend enough time on it to make it a treeset, so I'm just gonna do an array set. It's gonna have a static const int default size, and it's going to have a member private int threshold. Once the size of the set passes the threshold, the next call to any...
5
4727
by: Jim | last post by:
I've heard that resizing images through PHP (either GD2 or ImageMagick) is a processor intensive exercise. I'm setting up a site where users will be uploading up to 10 images along with the details of their product. For each image uploaded (max 500Kb), I'll be resizing it to create a small, medium and large version after which I'll discard the original. My worry is that as the site becomes more popular, the processor time spent resizing...
11
17856
by: Sharon | last post by:
I'm writing a new control derived from UserControl. I need to get an event when the control is done resizing. I tried the Resize, SizeChanged, Move and the Layout events and I also tried to override them. But they all invoked when the control is in the middle of the resizing process. I'm not using breakpoints, I'm using trace to see which one is invoked and when.
6
2260
by: tomasio | last post by:
Dear NG, years have passed and I am still more designer than programmer. I build a new version of my website which has a few nasty bugs, especially on my startpage: Resizing text brakes the dotted lines which I use as visual border on the left and right edge of the page layout and thus produces an unwanted white gap above the enlarged text. Viewing the page with IE shows this behaviour even without changing the font size.
0
5569
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
9
5307
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from http://blogs.crankygoblin.com/blogs/geoff.appleby/pages/50712.aspx. I've also read the post on this topic by bggraphics, but he doesn't arrive at a final result. The main problem I am having is that the layerX and layerY event properties don't work. They're supposed to return the...
1
4030
by: Tom P. | last post by:
It's kind of hard to explain (so if you need more just ask) and any help would be greatly appreciated. I am writing a side-by-side file manager. On each side I have a DropDownButton that holds either the root name or the Favorite name for the current path. I also have a DropDownComboBox that has the current full path as well as a series of paths that lead back to the root (i.e. "C;\Program Files\Microsoft Office", "C:\Program Files", "C:...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.