473,405 Members | 2,279 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,405 software developers and data experts.

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 2406
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
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...
1
by: mo | last post by:
Hi, I have the following code to create a thumbnail from the input stream System.Drawing.Image source; source=System.Drawing.Image.FromStream(new System.IO.MemoryStream(myData));...
4
by: Øyvind Isaksen | last post by:
Hello! Does anyone know about an ASP.NET thumbnail script that generate thumbnail with MAX quality? Have tested some scripts, but the thumbnail is not getting as good quality as I need. This...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.