thumbnail has poor quality

Discussion in 'ASP .Net' started by Narshe, Aug 9, 2006.

  1. Narshe

    Narshe Guest

    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?
    Narshe, Aug 9, 2006
    #1
    1. Advertising

  2. 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
    Laurent Bugnion, Aug 11, 2006
    #2
    1. Advertising

  3. Narshe

    Narshe Guest

    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.
    Narshe, Aug 11, 2006
    #3
  4. 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
    Laurent Bugnion, Aug 11, 2006
    #4
  5. Narshe

    Narshe Guest

    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.
    Narshe, Aug 11, 2006
    #5
  6. Narshe

    Narshe Guest

    I tried your method and it still ended up fuzzy. Here's the pic
    http://www.yousendit.com/transfer.php?action=download&ufid=8A1A3BFE67C7BBD0&rcpt=

    -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.
    Narshe, Aug 11, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris D

    Thumbnail Image Quality Issues

    Chris D, Nov 18, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    327
    Chris D
    Nov 18, 2003
  2. David Lozzi
    Replies:
    1
    Views:
    493
    john smith
    Feb 1, 2006
  3. code_wrong
    Replies:
    2
    Views:
    584
    code_wrong
    Apr 21, 2004
  4. Replies:
    7
    Views:
    582
  5. RHjorth
    Replies:
    2
    Views:
    291
    RHjorth
    Mar 25, 2008
Loading...

Share This Page