469,600 Members | 2,232 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

thumbnail has poor quality

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?

Aug 9 '06 #1
5 2310
Hi,

Narshe wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 11 '06 #2
Laurent Bugnion wrote:
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.

Aug 11 '06 #3
Hi,

Narshe wrote:
Laurent Bugnion wrote:
>>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.
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 11 '06 #4

Laurent Bugnion wrote:
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.

Aug 11 '06 #5
I tried your method and it still ended up fuzzy. Here's the pic
http://www.yousendit.com/tr*********...****@gmail.com

-Josh

Narshe wrote:
Laurent Bugnion wrote:
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.
Aug 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Chris D | last post: by
6 posts views Thread by Trint Smith | last post: by
1 post views Thread by mo | last post: by
4 posts views Thread by ōyvind Isaksen | last post: by
reply views Thread by sakurasyi | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.