Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Thumbnail Image Grainy

 
Thread Tools Search this Thread
Old 11-06-2009, 07:35 PM   #1
Default Thumbnail Image Grainy


I found this link to create a thumbnail image.
http://forums.asp.net/t/739822.aspx

But the thumbnail image looks grainy.
If I take the same image, resample it in corel photopaint at 72dpi, the
image is nice and small and not grainy at all ( sharp ).

I was wondering if there is anything else that can be done to a jpg as you
are compressing it down to a smaller jpg, so you do not end up with a grainy
image.

Thanks,

Miro



Miro
  Reply With Quote
Old 11-06-2009, 08:06 PM   #2
Miro
 
Posts: n/a
Default Re: Thumbnail Image Grainy
I found this - but I cant seem to convert it to vb.

// Prepare for a controlled-quality JPEG
exportImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
Encoder jpegEncoder = Encoder.Quality;
EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder,
jpegQuality);
jpegEncoderParameters.Param[0] = jpegEncoderQuality;string thumbnailPath;
// some path to save your JPEG to
thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters);



"Miro" <> wrote in message
news:...
>I found this link to create a thumbnail image.
> http://forums.asp.net/t/739822.aspx
>
> But the thumbnail image looks grainy.
> If I take the same image, resample it in corel photopaint at 72dpi, the
> image is nice and small and not grainy at all ( sharp ).
>
> I was wondering if there is anything else that can be done to a jpg as you
> are compressing it down to a smaller jpg, so you do not end up with a
> grainy image.
>
> Thanks,
>
> Miro




Miro
  Reply With Quote
Old 11-06-2009, 08:56 PM   #3
Alexey Smirnov
 
Posts: n/a
Default Re: Thumbnail Image Grainy
On Nov 6, 9:06*pm, "Miro" <m...@beero.com> wrote:
> I found this - but I cant seem to convert it to vb.
>
> // Prepare for a controlled-quality JPEG
> exportImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
> Encoder jpegEncoder = Encoder.Quality;
> EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
> EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder,
> jpegQuality);
> jpegEncoderParameters.Param[0] = jpegEncoderQuality;string thumbnailPath;
> // some path to save your JPEG to
> thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters);
>
> "Miro" <m...@beero.com> wrote in message
>
> news:...
>
>
>
> >I found this link to create a thumbnail image.
> >http://forums.asp.net/t/739822.aspx

>
> > But the thumbnail image looks grainy.
> > If I take the same image, resample it in corel photopaint at 72dpi, the
> > image is nice and small and not grainy at all ( sharp ).

>
> > I was wondering if there is anything else that can be done to a jpg as you
> > are compressing it down to a smaller jpg, so you do not end up with a
> > grainy image.

>
> > Thanks,

>
> > Miro


' Prepare for a controlled-quality JPEG
Dim jpegCodec As exportImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim jpegEncoder As Encoder = Encoder.Quality
Dim jpegEncoderParameters As New EncoderParameters(1)
Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder,
jpegQuality)
jpegEncoderParameters.Param(0) = jpegEncoderQuality
Dim thumbnailPath As String
' some path to save your JPEG to
thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters)


Alexey Smirnov
  Reply With Quote
Old 11-07-2009, 05:00 AM   #4
Miro
 
Posts: n/a
Default Re: Thumbnail Image Grainy
Thanks Alexy,

this got me on the right track but my image is still more grainy than if I
do it in something like corel photopaint.

Here is my code below. Perhaps I have a logical error somehwere ?
Take note of the 1000L ...if I put 100L or anything higher it does not get
better, but a value of 0 is really really grainy...so I was hoping this was
some kind of a weird calculated value.


Private Sub generateThumbnail(ByVal filepath As String, ByVal FileName
As String)

'Create a new Bitmap Image loading from location of origional file
'Dim bm As Bitmap = System.Drawing.Image.FromFile(filepath &
FileName)
Dim jpg As System.Drawing.Image =
System.Drawing.Image.FromFile(filepath & FileName)

'Declare Thumbnails Height and Width
Dim newWidth As Integer = 125
'Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height
Dim newHeight As Integer = (newWidth / jpg.Width) * jpg.Height
Dim resizedBMP As Bitmap = New Bitmap(jpg, newWidth, newHeight)



' Prepare for a controlled-quality JPEG
Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim jpegEncoder As Encoder = Encoder.Quality
Dim jpegEncoderParameters As New EncoderParameters(1)
Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder, 1000L)
jpegEncoderParameters.Param(0) = jpegEncoderQuality
'Dim thumbnailPath As String
' some path to save your JPEG to
Dim newStrFileName As String = filepath & "ThumbNails/" & FileName
resizedBMP.Save(newStrFileName, jpegCodec, jpegEncoderParameters)
End Sub

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


Miro

"Alexey Smirnov" <> wrote in message
news:7d5661af-9947-45df-b21e-...
On Nov 6, 9:06 pm, "Miro" <m...@beero.com> wrote:
> I found this - but I cant seem to convert it to vb.
>
> // Prepare for a controlled-quality JPEG
> exportImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
> Encoder jpegEncoder = Encoder.Quality;
> EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
> EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder,
> jpegQuality);
> jpegEncoderParameters.Param[0] = jpegEncoderQuality;string thumbnailPath;
> // some path to save your JPEG to
> thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters);
>
> "Miro" <m...@beero.com> wrote in message
>
> news:...
>
>
>
> >I found this link to create a thumbnail image.
> >http://forums.asp.net/t/739822.aspx

>
> > But the thumbnail image looks grainy.
> > If I take the same image, resample it in corel photopaint at 72dpi, the
> > image is nice and small and not grainy at all ( sharp ).

>
> > I was wondering if there is anything else that can be done to a jpg as
> > you
> > are compressing it down to a smaller jpg, so you do not end up with a
> > grainy image.

>
> > Thanks,

>
> > Miro


' Prepare for a controlled-quality JPEG
Dim jpegCodec As exportImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim jpegEncoder As Encoder = Encoder.Quality
Dim jpegEncoderParameters As New EncoderParameters(1)
Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder,
jpegQuality)
jpegEncoderParameters.Param(0) = jpegEncoderQuality
Dim thumbnailPath As String
' some path to save your JPEG to
thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters)



Miro
  Reply With Quote
Old 11-07-2009, 05:10 AM   #5
Miro
 
Posts: n/a
Default Re: Thumbnail Image Grainy
Rewrote it a bit...but still grainy - found some differnet code- hoping that
would work.

Dim bm As Bitmap = System.Drawing.Image.FromFile(filepath & FileName)
Dim newWidth As Integer = 125
Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height
Dim resizedBMP As Bitmap = New Bitmap(bm, newWidth, newHeight)


Dim info As ImageCodecInfo = ImageCodecInfo.GetImageEncoders(1)
Dim Params As EncoderParameters = New EncoderParameters(1)
Params.Param(0) = New
EncoderParameter(System.Drawing.Imaging.Encoder.Qu ality, 100L)
Dim newStrFileName As String = filepath & "ThumbNails/" & FileName
resizedBMP.Save(newStrFileName, info, Params)


"Miro" <> wrote in message
news:...
> Thanks Alexy,
>
> this got me on the right track but my image is still more grainy than if I
> do it in something like corel photopaint.
>
> Here is my code below. Perhaps I have a logical error somehwere ?
> Take note of the 1000L ...if I put 100L or anything higher it does not get
> better, but a value of 0 is really really grainy...so I was hoping this
> was some kind of a weird calculated value.
>
>
> Private Sub generateThumbnail(ByVal filepath As String, ByVal FileName
> As String)
>
> 'Create a new Bitmap Image loading from location of origional file
> 'Dim bm As Bitmap = System.Drawing.Image.FromFile(filepath &
> FileName)
> Dim jpg As System.Drawing.Image =
> System.Drawing.Image.FromFile(filepath & FileName)
>
> 'Declare Thumbnails Height and Width
> Dim newWidth As Integer = 125
> 'Dim newHeight As Integer = (newWidth / bm.Width) * bm.Height
> Dim newHeight As Integer = (newWidth / jpg.Width) * jpg.Height
> Dim resizedBMP As Bitmap = New Bitmap(jpg, newWidth, newHeight)
>
>
>
> ' Prepare for a controlled-quality JPEG
> Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
> Dim jpegEncoder As Encoder = Encoder.Quality
> Dim jpegEncoderParameters As New EncoderParameters(1)
> Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder, 1000L)
> jpegEncoderParameters.Param(0) = jpegEncoderQuality
> 'Dim thumbnailPath As String
> ' some path to save your JPEG to
> Dim newStrFileName As String = filepath & "ThumbNails/" & FileName
> resizedBMP.Save(newStrFileName, jpegCodec, jpegEncoderParameters)
> End Sub
>
> 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
>
>
> Miro
>
> "Alexey Smirnov" <> wrote in message
> news:7d5661af-9947-45df-b21e-...
> On Nov 6, 9:06 pm, "Miro" <m...@beero.com> wrote:
>> I found this - but I cant seem to convert it to vb.
>>
>> // Prepare for a controlled-quality JPEG
>> exportImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg");
>> Encoder jpegEncoder = Encoder.Quality;
>> EncoderParameters jpegEncoderParameters = new EncoderParameters(1);
>> EncoderParameter jpegEncoderQuality = new EncoderParameter(jpegEncoder,
>> jpegQuality);
>> jpegEncoderParameters.Param[0] = jpegEncoderQuality;string thumbnailPath;
>> // some path to save your JPEG to
>> thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters);
>>
>> "Miro" <m...@beero.com> wrote in message
>>
>> news:...
>>
>>
>>
>> >I found this link to create a thumbnail image.
>> >http://forums.asp.net/t/739822.aspx

>>
>> > But the thumbnail image looks grainy.
>> > If I take the same image, resample it in corel photopaint at 72dpi, the
>> > image is nice and small and not grainy at all ( sharp ).

>>
>> > I was wondering if there is anything else that can be done to a jpg as
>> > you
>> > are compressing it down to a smaller jpg, so you do not end up with a
>> > grainy image.

>>
>> > Thanks,

>>
>> > Miro

>
> ' Prepare for a controlled-quality JPEG
> Dim jpegCodec As exportImageCodecInfo = GetEncoderInfo("image/jpeg")
> Dim jpegEncoder As Encoder = Encoder.Quality
> Dim jpegEncoderParameters As New EncoderParameters(1)
> Dim jpegEncoderQuality As New EncoderParameter(jpegEncoder,
> jpegQuality)
> jpegEncoderParameters.Param(0) = jpegEncoderQuality
> Dim thumbnailPath As String
> ' some path to save your JPEG to
> thumbnail.Save(thumbnailPath, jpegCodec, jpegEncoderParameters)




Miro
  Reply With Quote
Old 11-07-2009, 11:45 PM   #6
Herfried K. Wagner [MVP]
 
Posts: n/a
Default Re: Thumbnail Image Grainy
Alexey Smirnov schrieb:
> On Nov 6, 9:06 pm, "Miro" <m...@beero.com> wrote:
>> I found this - but I cant seem to convert it to vb.


I assume that commercial products contain more evolved compression
algorithms than the .NET Framework's default JPEG encoder. Adobe
Photoshop, for example, provides a better quality/file size ratio than
the .NET Framework's JPEG encoder too. The encoder used by GIMP is
worse than Photoshop's encoder.

Depending on the type of images you may want to consider using the PNG
format instead of JPEG (it's more suitable for screenshots, for example).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Herfried K. Wagner [MVP]
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Amplifier Home Theater Azzopardi@carmine.com Computer Security 0 05-18-2009 11:02 AM
Usb Hdtv Arrellano@sang.com Wireless Networking 0 05-17-2009 12:26 PM
Hdtv Recorder Archey@lurlene.com Wireless Networking 0 05-17-2009 12:18 PM
Canon Powershot Sd750 Digital Camera Alrod@issac.com Computer Security 0 05-17-2009 02:39 AM
Vista Drivers not loading at startup. Scribner Computer Support 18 09-09-2007 05:28 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46