Image quality on generated images

  • Thread starter Kim Bach Petersen
  • Start date
K

Kim Bach Petersen

Using asp.net, I'm generating bitmaps, that I stream either as gif- og
jpg-images (se code below). In both cases, the image-quality is rather poor:

http://dotnet.kensho.dk/scr_diagram.aspx?tal=12&jeg=3&fan=9&san=3&soc=7&kon=2&int=12&fol=5&img=gif
http://dotnet.kensho.dk/scr_diagram.aspx?tal=12&jeg=3&fan=9&san=3&soc=7&kon=2&int=12&fol=5&img=jpg

I would very much like to have clearer images, but I haven't been able
to locate a property that allows me to control the image quality /
compression.

Any ideas?

Thanks In advance,

Kim :eek:)

Dim intSize As Integer = 400
Dim decStep As Decimal = intSize/26
Dim bmp As Bitmap = New Bitmap(intSize,intSize)
Dim g As Graphics = Graphics.FromImage(bmp)
g.FillRectangle(New SolidBrush(Color.White), 0, 0, intSize, intSize)
g.FillEllipse(New SolidBrush(Color.Gold), decStep, decStep,
CInt(24*decStep), CInt(24*decStep))
g.FillEllipse(New SolidBrush(Color.Khaki), CInt(4*decStep),
CInt(4*decStep), CInt(18*decStep), CInt(18*decStep))
g.FillEllipse(New SolidBrush(Color.PaleGoldenrod), CInt(7*decStep),
CInt(7*decStep), CInt(12*decStep), CInt(12*decStep))
g.FillEllipse(New SolidBrush(Color.LemonChiffon), CInt(10*decStep),
CInt(10*decStep), CInt(6*decStep), CInt(6*decStep))
bmp.Save(Response.OutputStream, ImageFormat.Gif)
 
J

Jeppe Jespersen

I would very much like to have clearer images, but I haven't been able to
locate a property that allows me to control the image quality /
compression.

Any ideas?

Try this, it might be what you're looking for. :)

Jeppe Jespersen
Denmark

----------

Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
Dim j As Integer
Dim encoders As ImageCodecInfo()
encoders = ImageCodecInfo.GetImageEncoders()
For j = 0 To encoders.Length
If encoders(j).MimeType = mimeType Then
Return encoders(j)
End If
Next j
Return Nothing
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim intSize As Integer = 800
Dim decStep As Decimal = intSize / 20
Dim bmp As Bitmap = New Bitmap(intSize, intSize)
Dim g As Graphics = Graphics.FromImage(bmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(New SolidBrush(Color.White), 0, 0, intSize, intSize)
g.FillEllipse(New SolidBrush(Color.Gold), decStep, decStep, CInt(24 *
decStep), CInt(24 * decStep))
g.FillEllipse(New SolidBrush(Color.Khaki), CInt(4 * decStep), CInt(4 *
decStep), CInt(18 * decStep), CInt(18 * decStep))
g.FillEllipse(New SolidBrush(Color.PaleGoldenrod), CInt(7 * decStep),
CInt(7 * decStep), CInt(12 * decStep), CInt(12 * decStep))
g.FillEllipse(New SolidBrush(Color.LemonChiffon), CInt(10 * decStep),
CInt(10 * decStep), CInt(6 * decStep), CInt(6 * decStep))
Dim eps As EncoderParameters = New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality, 8) 'play with this
last value to vary quality
Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg")
bmp.Save("c:\bob.jpg", ici, eps)
End Sub
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top