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

Bitmap Saved as GIF loses image quality

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

"Michael" <mh*******@core-techs.net> wrote in message
news:37**************************@posting.google.c om...
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

Nov 20 '05 #2

P: n/a
* mh*******@core-techs.net (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>
Nov 20 '05 #3

P: n/a
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
Nov 20 '05 #4

P: n/a
* "Cor" <no*@non.com> scripsit:
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...

:-)

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a
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
Nov 20 '05 #6

P: n/a
* "Cor" <no*@non.com> scripsit:
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.

;-)

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.