thumbnail has poor quality

N

Narshe

I'm creating a thumbnail from an image saved in a db. If I write the
data directly to the stream, the image shows up perfectly.

Response.Clear();
Response.ContentType = myImage.ContentType;
Response.BinaryWrite( myImage.File );

But if i try and make a thumb, the image is distorted.

MemoryStream stream = new MemoryStream( myImage.File );
Bitmap bitmap = new Bitmap( stream );
Image image = bitmap.GetThumbnailImage( 100, 100, null, IntPtr.Zero );
image.Save( Response.OutputStream, bitmap.RawFormat );

Is there a way to make this clear?
 
L

Laurent Bugnion

Hi,
I'm creating a thumbnail from an image saved in a db. If I write the
data directly to the stream, the image shows up perfectly.

Response.Clear();
Response.ContentType = myImage.ContentType;
Response.BinaryWrite( myImage.File );

But if i try and make a thumb, the image is distorted.

MemoryStream stream = new MemoryStream( myImage.File );
Bitmap bitmap = new Bitmap( stream );
Image image = bitmap.GetThumbnailImage( 100, 100, null, IntPtr.Zero );
image.Save( Response.OutputStream, bitmap.RawFormat );

Is there a way to make this clear?


I think that what you mean with "distorted" is that you create
thumbnails having a size of 100*100 pixels, regardless of the original
size. If you want to keep the original proportions, you must calculate
the corresponding width, respectively height:

Bitmap bmpOriginal = new Bitmap( strPath );

int iNewHeight = m_iMaxSize;
float fRate = (float) iNewHeight / (float) bmpOriginal.Height;
int iNewWidth = (int) Math.Round( (float) bmpOriginal.Width * fRate );
if ( iNewWidth > m_iMaxSize )
{
iNewWidth = m_iMaxSize;
fRate = (float) iNewWidth / (float) bmpOriginal.Width;
iNewHeight = (int) Math.Round( (float) bmpOriginal.Height * fRate );
}

Bitmap bmpNew = new Bitmap( bmpOriginal, iNewWidth, iNewHeight );
bmpNew.Save( Response.OutputStream, bmpOriginal.RawFormat );

In the code above, I have m_iMaxSize set by the user (in your case 100).

I use this way (more or less) to create thumbnails dynamically in this page:
http://www.galasoft-lb.ch/pictures/welcome.aspx

It's true that the thumbnails look less clear than if produced using a
graphics application (I use SuperJpg when I want to make "static"
thumbnails). However, it's not that bad I think.

HTH,
Laurent
 
N

Narshe

Laurent said:
I think that what you mean with "distorted" is that you create
thumbnails having a size of 100*100 pixels, regardless of the original
size. If you want to keep the original proportions, you must calculate
the corresponding width, respectively height:

I actually have it doing something like this already, I just whipped up
sample code for an example.

The image is not clear. It's fuzzy and poor quality. I'll give your
method a try and see if that helps.
 
L

Laurent Bugnion

Hi,
I actually have it doing something like this already, I just whipped up
sample code for an example.

The image is not clear. It's fuzzy and poor quality. I'll give your
method a try and see if that helps.

As I said, the method of creating thumbnails programatically produces
thumbnails with lesser quality than dedicated programs. Check the page I
gave you to see if the quality is any better. The original images are
640*480 or 480*640, and the thumbnails go down to 120 pixels.

http://www.galasoft-lb.ch/pictures/index.html

HTH,
Laurent
 
N

Narshe

Laurent said:
As I said, the method of creating thumbnails programatically produces
thumbnails with lesser quality than dedicated programs. Check the page I
gave you to see if the quality is any better. The original images are
640*480 or 480*640, and the thumbnails go down to 120 pixels.

Yes, they are a lot better. I used the google logo off their home page,
and brought the size down to 100x40 (iirc), and the image looks like it
is made up of a bunch of dots, like a news paper.

I haven't had a chance to try your method, been in a meeting, but I'll
let you know.

Thanks.
 

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,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top