Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > thumbnail has poor quality

Reply
Thread Tools

thumbnail has poor quality

 
 
Narshe
Guest
Posts: n/a
 
      08-09-2006
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?

 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      08-11-2006
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
 
Reply With Quote
 
 
 
 
Narshe
Guest
Posts: n/a
 
      08-11-2006
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.

 
Reply With Quote
 
Laurent Bugnion
Guest
Posts: n/a
 
      08-11-2006
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
 
Reply With Quote
 
Narshe
Guest
Posts: n/a
 
      08-11-2006

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.

 
Reply With Quote
 
Narshe
Guest
Posts: n/a
 
      08-11-2006
I tried your method and it still ended up fuzzy. Here's the pic
http://www.yousendit.com/(E-Mail Removed)

-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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asterisk IVR has very poor voice quality Ramon F Herrera VOIP 4 08-13-2009 12:03 PM
Poor reception, poor connection, and dropped signal =?Utf-8?B?dW51c3VhbHBzeWNobw==?= Wireless Networking 2 06-07-2006 12:54 AM
Displaying a Thumbnail vs. creating a thumbnail David Lozzi ASP .Net 1 02-01-2006 10:34 PM
jpeg has poor quality when written back to disk code_wrong Java 2 04-21-2004 10:46 PM
THE Difference Between Good Quality and Poor Quality Pictures! N.E.1. Digital Photography 4 09-23-2003 02:43 AM



Advertisments