473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Thumbnail Image Quality Issues

Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.

The quality of the small thumbnail is ok, but the quality of the larger
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

Is there any way to control the compression level of a Jpeg??

If any one can give me some suggestions I would greatly appreciate it.

Chris
Nov 18 '05 #1
6 2467
Some suggest converting your thumnails to png. This has worked best for me.
"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.

The quality of the small thumbnail is ok, but the quality of the larger
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

Is there any way to control the compression level of a Jpeg??

If any one can give me some suggestions I would greatly appreciate it.

Chris

Nov 18 '05 #2
Yes there is a Quality level for jpeg images. Start out simple and create
an application that takes an image, modifies it (height, width, quality)
then save it or stram it to the browser in different formats including the
original and see how it looks. If your images are photos then I would stick
with jpegs. I don't know what method/control you are using but this is a
good starting point.

"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

The quality of the small thumbnail is ok, but the quality of the larger> Is there any way to control the compression level of a Jpeg??
If any one can give me some suggestions I would greatly appreciate it.

Chris

Nov 18 '05 #3
I have tried storing it in png with no visible improvement.

Is there maybe a specific way of converting it??

I don't think there is a problem with the GetThumbNail method as it returns
a good quality image if I get the image from the aspx page. the quality
worsens drastically when I write the image to a stream and to SQL server and
then retrieve it again.

Any ideas on that

Chris
"Manit Chanthavong" <ma***@chanthavong.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Some suggest converting your thumnails to png. This has worked best for me.

"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.

The quality of the small thumbnail is ok, but the quality of the larger
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

Is there any way to control the compression level of a Jpeg??

If any one can give me some suggestions I would greatly appreciate it.

Chris


Nov 18 '05 #4
It looks like you are using the image (GDI) class to do your conversions. I
don't think GetThumbNail by default does not do anything with the image
quality level. Hecnce you are seeing a decent image. What method are you
using to convert your other image? fyi, you can try the GetThumbNail and
specify a height and width for your second image if you really want.
Somethimes images have a thumbnails embeeded in the file in which
GetThumbNail returns that other wise GetThumbNail will just scale your image
to your specification (height, width). You will have to post code for me to
help you.

"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
I have tried storing it in png with no visible improvement.

Is there maybe a specific way of converting it??

I don't think there is a problem with the GetThumbNail method as it returns a good quality image if I get the image from the aspx page. the quality
worsens drastically when I write the image to a stream and to SQL server and then retrieve it again.

Any ideas on that

Chris
"Manit Chanthavong" <ma***@chanthavong.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Some suggest converting your thumnails to png. This has worked best for

me.


"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still smaller then the original. I store these in SQL 2000 server.

The quality of the small thumbnail is ok, but the quality of the larger image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

Is there any way to control the compression level of a Jpeg??

If any one can give me some suggestions I would greatly appreciate it.

Chris



Nov 18 '05 #5
Dan,

Here is the code I'm using to do this. Thanks in advance for taking a look
at this for me. I'm out of ideas.

'Declarations
Dim fsImageSize As Integer
Dim fsImageContent As Byte()
Dim fsImageType As String
Dim tnThumbnailSize As Integer
Dim tnThumbnailContent As Byte()
Dim tnThumbnailType As String
Dim orImage As System.Drawing.Image
Dim fsImage As System.Drawing.Image
Dim tnImage As System.Drawing.Image
Dim WHRatio As Single
Dim ms As New System.IO.MemoryStream()
Dim ms2 As New System.IO.MemoryStream()

'get image from submit and calculate WH ration
orImage = System.Drawing.Image.FromStream(Picture.PostedFile .InputStream)
WHRatio = orImage.Width / orImage.Height

'Resize image and create Thumbnail
fsImage = ResizeImage(orImage, 500 / WHRatio, 500) '---- See below for the
resizeimage function
tnImage = ResizeImage(orImage, 125 / WHRatio, 125) '---- See below for the
resizeimage function

'Convert both images to binary for save operation
fsImage.Save(ms, Imaging.ImageFormat.Bmp)
fsImageSize = ms.Length
ReDim fsImageContent(fsImageSize)
ms.Seek(0, IO.SeekOrigin.Begin)
ms.Read(fsImageContent, 0, fsImageContent.Length)

tnImage.Save(ms2, Imaging.ImageFormat.Bmp)
tnThumbnailSize = ms2.Length
ReDim tnThumbnailContent(tnThumbnailSize)
ms2.Seek(0, IO.SeekOrigin.Begin)
ms2.Read(tnThumbnailContent, 0, tnThumbnailContent.Length)

Then I dump it to the DB via Stored Procedure:

..Parameters.Add("@ImageContent", SqlDbType.Image).Value = fsImageContent
..Parameters.Add("@ThumbnailContent", SqlDbType.Image).Value =
tnThumbnailContent

Resize Function:

Shared Function ResizeImage(ByVal p_objImage As System.Drawing.Image, ByVal
p_intHeight As Integer, ByVal p_intWidth As Integer) As System.Drawing.Image
Dim intHeight As Integer
Dim intWidth As Integer
intHeight = p_objImage.Height
intWidth = p_objImage.Width
If p_intHeight > -1 And p_intWidth > -1 Then
intHeight = p_intHeight
intWidth = p_intWidth
ElseIf p_intHeight > -1 Then
If p_intWidth > -1 Then
intWidth = p_intWidth
Else
intWidth = CInt(intWidth / (intHeight / p_intHeight))
End If
intHeight = p_intHeight
End If
If p_intWidth > -1 Then
If p_intHeight > -1 Then
intHeight = p_intHeight
Else
intHeight = CInt(intHeight / (intWidth / p_intWidth))
End If
intWidth = p_intWidth
End If
Return p_objImage.GetThumbnailImage(intWidth, intHeight, Nothing, Nothing)
End Function

Thaks again ... Chris

"Dan Nigro" <dw*****@direcway.com> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
It looks like you are using the image (GDI) class to do your conversions. I don't think GetThumbNail by default does not do anything with the image
quality level. Hecnce you are seeing a decent image. What method are you
using to convert your other image? fyi, you can try the GetThumbNail and
specify a height and width for your second image if you really want.
Somethimes images have a thumbnails embeeded in the file in which
GetThumbNail returns that other wise GetThumbNail will just scale your image to your specification (height, width). You will have to post code for me to help you.

"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
I have tried storing it in png with no visible improvement.

Is there maybe a specific way of converting it??

I don't think there is a problem with the GetThumbNail method as it

returns
a good quality image if I get the image from the aspx page. the quality
worsens drastically when I write the image to a stream and to SQL server

and
then retrieve it again.

Any ideas on that

Chris
"Manit Chanthavong" <ma***@chanthavong.com> wrote in message
news:OM**************@TK2MSFTNGP12.phx.gbl...
Some suggest converting your thumnails to png. This has worked best for
me.


"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
> Hi,
>
> I have an application where a user uploads an image and I create two
> thumbnails. One a small image and the second is a larger image but still > smaller then the original. I store these in SQL 2000 server.
>
> The quality of the small thumbnail is ok, but the quality of the larger > image is terrible. I tried both Jpeg and Gif formats and there is no
> difference.
>
> Is there any way to control the compression level of a Jpeg??
>
> If any one can give me some suggestions I would greatly appreciate

it. >
> Chris
>
>



Nov 18 '05 #6
dwn
Here are some routines I just put together. Anything with "img..." is a
image parameter that you need to pass in. I am confused on your height to
width scaling but I think you have the right idea. Play around with that a
bit more but for now leave it out and try these routunies. I would not use
GetThumbnail for images bigger than 100x100.

Sub StreamImage(imgHeight as integer, imgWidth as integer, imgFileName as
String, imgQuality as integer)

Dim myNewImage As System.drawing.Image
Dim myImageCodecInfo As ImageCodecInfo
Dim myEncoder As Encoder
Dim myEncoderParameter As EncoderParameter
Dim myEncoderParameters As EncoderParameters

Try
Select Case imgQuality

Case Is = 0

If imgWidth = 0 Then imgWidth = 200
If imgHeight = 0 Then imgHeight = 200
myNewImage = mgAdjustBitmap(imgFileName, imgWidth,
imgHeight)

myNewImage.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg)

Case Else

If imgWidth = 0 Then imgWidth = 90
If imgHeight = 0 Then imgHeight = 90
myNewImage = mgGetThumbNail(imgFileName, imgWidth,
imgHeight)

'Image Type
'myImageCodecInfo = GetEncoderInfo("image/tiff")
myImageCodecInfo = GetEncoderInfo("image/jpeg")

'Image Qualiy for Jpeg only
myEncoder = Encoder.Quality
myEncoderParameters = New EncoderParameters(1)
'25L is the quality level Hard to 25 coded for now
'but I would use imgQuality to create the 25L for
example
myEncoderParameter = New EncoderParameter(myEncoder,
25L)
myEncoderParameters.Param(0) = myEncoderParameter

'myNewImage.Save(Response.OutputStream,
ImageFormat.Jpeg)
myNewImage.Save(Response.OutputStream, myImageCodecInfo,
myEncoderParameters)

End Select

Catch

End Try

End Sub

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
GetEncoderInfo = encoders(J)
Exit For
End If
Next

End Function

Function mgGetThumbNail(ByVal strFile As String, ByVal intWidth As
Integer, ByVal intHeight As Integer) As System.drawing.Image

Dim myBitmap As Bitmap = New Bitmap(strFile)
Return myBitmap.GetThumbnailImage(intWidth, intHeight, Nothing,
Nothing)
myBitmap.Dispose()

End Function

Function mgAdjustBitmap(ByVal strFile As String, ByVal intHorz As
Integer, ByVal intVert As Integer) As Bitmap

Dim mysize As Size
Dim myBitmap As Bitmap = New Bitmap(strFile)
If intHorz > 0 Then
mysize = New Size(intHorz, intVert)
Else
mysize = New Size(myBitmap.Width, myBitmap.Height)
End If
Dim myImg As Bitmap = New Bitmap(myBitmap, mysize)
Return myImg
myBitmap.Dispose()

End Function

"Chris D" <qw*****@hotmail.com> wrote in message
news:3f********@news.nucleus.com...
Hi,

I have an application where a user uploads an image and I create two
thumbnails. One a small image and the second is a larger image but still
smaller then the original. I store these in SQL 2000 server.

The quality of the small thumbnail is ok, but the quality of the larger
image is terrible. I tried both Jpeg and Gif formats and there is no
difference.

Is there any way to control the compression level of a Jpeg??

If any one can give me some suggestions I would greatly appreciate it.

Chris

Nov 18 '05 #7

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

Similar topics

0
by: Mike | last post by:
Sites using thumbnail preview for world wide web file navigation and searching. Below are list of sites that are either researching or providing thumbnail preview images for online web...
0
by: Chris D | last post by:
Hi, I have an application where a user uploads an image and I create two thumbnails. One a small image and the second is a larger image but still smaller then the original. I store these in SQL...
6
by: Trint Smith | last post by:
How can I show image thumbnail?? thanks, Trint ..Net programmer trintsmith@hotmail.com *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get...
4
by: moondaddy | last post by:
I have an app where users will upload photos to their shopping cart. When they review their cart I need to include a light weight thumbnail of the image they uploaded. how can I take the image a...
1
by: CĂ©dric | last post by:
Hello, Wanting to create a thumbnail of an image, i'm using the following piece of code : Public Sub Reduction(ByVal Source As String, ByVal Destination As String, ByVal TailleX As String,...
1
by: Summercoolness | last post by:
In PIL, since thumbnail() first makes a draft copy of the image, and then resize it, so thumbnail() can run a lot faster than resize() because draft() seems a lot faster when resizing from very big...
0
by: sakurasyi | last post by:
hai guys... can someone solve my problems? i'm doing a thumbnail program. But, i have some problems. 1. The thumbnail image become black (cannot see anything) 2. Can anyone know how to get...
8
by: barb | last post by:
So that the world at large benefits from our efforts, here is one fully documented way to use Windows Irfanview freeware to create thumbnail web galleries (http://www.irfanview.com). STEP 1:...
15
tlhintoq
by: tlhintoq | last post by:
I'd like to think I can work out most issues, but this one is kicking my butt. What's worse, is that I know I can't be the first guy to want to add a thumbnail to jpg that doesn't already have one. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.