Bitmap Saved as GIF loses image quality

M

Michael

I'm trying to use the Bitmap class's Save Method to save a Bitmap as a
GIF. My code runs fine, and converts the image, but the quality is
not anywhere close to as good. I know that GIF quality is not a good
as a BMP's but, is there a way to convert the image while preserving
its quality. Any help would be greatly appreciated. Here's what I
have...

Public Enum ImageType
Bmp = 0
Emf = 1
Exif = 2
Gif = 3
Icon = 4
Jpeg = 5
MemoryBmp = 6
Png = 7
Tiff = 8
Wmf = 9
End Enum

Public Sub ConvertImage(ByVal ConvertImageTo As ImageType, _
ByVal SourceImagePath As String,
Optional ByVal DeleteSouceFile As Boolean
= True)
Dim oImage As Bitmap
Try
'Make sure the source file even exists before we start
If Not File.Exists(SourceImagePath) Then
Err.Raise(10001, "ImagingUtility.ConvertImage", "The
image '" & SourceImagePath & "' does not
exist.")
Exit Sub
End If
oImage = New Bitmap(SourceImagePath)
Select Case ConvertImageTo
Case ImageType.Bmp :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".bmp",
Imaging.ImageFormat.Bmp)
Case ImageType.Emf
Case ImageType.Exif
Case ImageType.Gif :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".gif",
Imaging.ImageFormat.Gif)
Case ImageType.Icon :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".ico",
Imaging.ImageFormat.Icon)
Case ImageType.Jpeg :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".jpeg",
Imaging.ImageFormat.Jpeg)
Case ImageType.MemoryBmp
Case ImageType.Png :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".png",
Imaging.ImageFormat.Png)
Case ImageType.Tiff :
oImage.Save(Path.GetDirectoryName(SourceImagePath) & "\" &
Path.GetFileNameWithoutExtension(SourceImagePath) & ".tiff",
Imaging.ImageFormat.Tiff)
Case ImageType.Wmf
End Select
oImage.Dispose()
oImage = Nothing
'Delete the sourcefile if necessary
If DeleteSouceFile Then File.Delete(SourceImagePath)
Catch ex As Exception
Err.Raise(Err.Number, "ImageUtility.ConvertImage",
ex.Message)
End Try
End Sub
 
R

Robin Tucker

You are probably reducing colour depth from 24 bit right down to 8bit,
obviously a lot of colour information is therefore being thrown out of the
window. Optimised Octree algorithm is an excellent choice (but you will
have to implement it) for colour space mapping.
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed) (Michael) scripsit:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a
GIF. My code runs fine, and converts the image, but the quality is
not anywhere close to as good. I know that GIF quality is not a good
as a BMP's but, is there a way to convert the image while preserving
its quality. Any help would be greatly appreciated. Here's what I
have...

GIF only supports 256 colors.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
 
C

Cor

Hi Herfried,
Some gets answers about Bitmaps, but that poor Newbie not
:-((((
He has even have opened the newsgroup drawing now.
But he is afraid that that is to much for him
:-((((
Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Some gets answers about Bitmaps, but that poor Newbie not
:-((((
He has even have opened the newsgroup drawing now.
But he is afraid that that is to much for him
:-((((

I think Fergus answered the question...

:)
 
C

Cor

Hi Herfried,

Yes and I was just starting to look deeper to it, but very good.

I thought you and Nick where the experts about this, but I changed my idea
about that.
But soon there will be an extra one of course.

:)

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
Yes and I was just starting to look deeper to it, but very good.

I thought you and Nick where the experts about this, but I changed my idea
about that.
But soon there will be an extra one of course.

I didn't have enough time yesterday... sorry.

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top