473,799 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[URGENT] Images and Thumbnail : pb with rendering quality

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, ByVal TailleY As String, ByVal Resolution As
Integer, ByVal Fond As Boolean, ByVal ConserverRatio As Boolean, ByVal
PixelFormat As System.Drawing. Imaging.PixelFo rmat, ByVal ImageFormat As
System.Drawing. Imaging.ImageFo rmat, ByVal R As Integer, ByVal V As Integer,
ByVal B As Integer)
'Declarations des variables recevant les dimensions proportionnelle s
Ă* l'original
Dim Width_Out As Integer 'largeur proportionnelle original
Dim Height_Out As Integer 'hauteur proportionnelle original
'Declarations des variables recevant les dimensions de sortie
souhaitées
Dim Final_X As Integer 'largeur de sortie
Dim Final_Y As Integer 'hauteur de sortie
'Déclaration du Bitmap d'entrée
Dim Bitmap_In As Bitmap
'Chargement de l'image source dans le bitmap d'entrée
Bitmap_In = Image.FromFile( Source)
'Conservation du Ratio (OUI/NON)
If ConserverRatio Then
'Calcul des dimensions de la miniature du bitmap d'entrée
'si Largeur fixe
If TailleY = "" And TailleX <> "" Then
'DĂ©finition de la taille proprtionnelle
Width_Out = CInt(TailleX)
Height_Out = CInt(TailleX) * Bitmap_In.Heigh t /
Bitmap_In.Width
'Définition de la taille souhaitée
Final_X = TailleX
Final_Y = Height_Out
Else
'si Hauteur fixe
If TailleX = "" And TailleY <> "" Then
'DĂ©finition de la taille proprtionnelle
Height_Out = CInt(TailleY)
Width_Out = CInt(TailleY) * Bitmap_In.Width /
Bitmap_In.Heigh t
'Définition de la taille souhaitée
Final_X = Width_Out
Final_Y = TailleY
Else
If Bitmap_In.Width >= Bitmap_In.Heigh t Then
'DĂ©finition de la taille proprtionnelle
'si orientation = paysage
Width_Out = CInt(TailleX)
Height_Out = CInt(TailleX) * Bitmap_In.Heigh t /
Bitmap_In.Width
Else
'DĂ©finition de la taille proprtionnelle
'si orientation = portrait
Height_Out = CInt(TailleY)
Width_Out = CInt(TailleY) * Bitmap_In.Width /
Bitmap_In.Heigh t
End If
'Verification si la taille de la miniature est
compatible avec la taille souhaitée
'si Width_Out > TailleX
If Width_Out > TailleX Then
Width_Out = CInt(TailleX)
Height_Out = CInt(TailleX) * Bitmap_In.Heigh t /
Bitmap_In.Width
End If
'si Height_Out > TailleY
If Height_Out > TailleY Then
Height_Out = CInt(TailleY)
Width_Out = CInt(TailleY) * Bitmap_In.Width /
Bitmap_In.Heigh t
End If
'Définition de la taille souhaitée
Final_X = TailleX
Final_Y = TailleY
End If
End If
Else
'DĂ©finition de la taille proprtionnelle
Width_Out = CInt(TailleX)
Height_Out = CInt(TailleY)
'Définition de la taille souhaitée
Final_X = TailleX
Final_Y = TailleY
End If
'DĂ©claration du Bitmap de sortie
Dim Bitmap_Temp As New Bitmap(Width_Ou t, Height_Out, PixelFormat)
'Déclaration de la surface de dessin du bitmap d'entrée
Dim MyGraphics_Temp As Graphics = Graphics.FromIm age(Bitmap_Temp )
'Modification de la surface de dessin du bitmap d'entrée en
respectant les proptions
MyGraphics_Temp .DrawImage(Bitm ap_In, 0, 0, Width_Out, Height_Out)
'Liberation de la mémoire des éléments concernat le Bitmap d'entrée
Bitmap_In.Dispo se()
Bitmap_In = Nothing
'DĂ©claration du Bitmap de sortie
Dim Bitmap_Out As Bitmap
'CrĂ©ation d'un fond Ă* l'image (OUI/NON)
If Fond Then
'Instanciation du Bitmap de sortie
Bitmap_Out = New Bitmap(CInt(Fin al_X), CInt(Final_Y), PixelFormat)
'DĂ©claration de la surface de dessin du bitmap de sortie
Dim MyGraphics_out As Graphics = Graphics.FromIm age(Bitmap_Out)
'Definition de la couleur d'arrière-plan
Dim Couleur As Color = Color.FromArgb( 255, R, V, B)
Dim MyBackground As New SolidBrush(Coul eur)
'Calcul des décalages Haut et gauche pour centrer de l'image
Dim Top As Integer = (Bitmap_Out.Hei ght - Bitmap_Temp.Hei ght) / 2
Dim Left As Integer = (Bitmap_Out.Wid th - Bitmap_Temp.Wid th) / 2
'Definition de la resolution (dpi)
Bitmap_Out.SetR esolution(Resol ution, Resolution)
'Remplissage de tout les pixels de la couleur du fond
MyGraphics_Out. FillRectangle(M yBackground, 0, 0,
Bitmap_Out.Widt h, Bitmap_Out.Heig ht)
'Recopie du bitmap d'entrée en position centrée
MyGraphics_Out. DrawImageUnscal ed(Bitmap_Temp, Left, Top,
Bitmap_Temp.Wid th, Bitmap_Temp.Hei ght)
'Sauvegarde du bitmap de sortie
Bitmap_Out.Save (Destination, ImageFormat.Jpe g)
'Liberation de la mémoire
MyGraphics_out. dispose()
MyGraphics_out = Nothing
Bitmap_Out.Disp ose()
Bitmap_Out = Nothing
Else
'Instanciation du Bitmap de sortie
Bitmap_Out = New Bitmap(CInt(Wid th_Out), CInt(Height_Out ),
PixelFormat)
'DĂ©claration de la surface de dessin du bitmap de sortie
Dim MyGraphics_out As Graphics = Graphics.FromIm age(Bitmap_Out)
'Recopie du bitmap d'entrée
MyGraphics_Out. DrawImageUnscal ed(Bitmap_Temp, 0, 0,
Bitmap_Temp.Wid th, Bitmap_Temp.Hei ght)
'Sauvegarde du bitmap de sortie
Bitmap_Out.Save (Destination, ImageFormat.Jpe g)
'Liberation de la mémoire
MyGraphics_out. dispose()
MyGraphics_out = Nothing
Bitmap_Out.Disp ose()
Bitmap_Out = Nothing
End If
MyGraphics_Temp .Dispose()
MyGraphics_Temp = Nothing
Bitmap_Temp.Dis pose()
Bitmap_Temp = Nothing
End Sub

and calling it with the following one :

Reduction(Src, Dest, 221, 142, 72, True, True, PixelFormat.For mat24bppRgb,
ImageFormat.Jpe g, 255, 255, 255)

Meanwhile, the quality of the generated thumbnail is not as good as i could
expect. Could this piece of code be optimised, in order to improve the
rendering quality.

Thanks

Feb 8 '06 #1
1 1729
"CĂ©dric" <CĂ©dr**@discus sions.microsoft .com> schrieb:
Wanting to create a thumbnail of an image


Resizing an image with a certain interpolation mode
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=interpolati onmode&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2867
by: wtgee | last post by:
I posted this elsewhere but got no answer so I thought I would see if anyone here is smarter. :) I am creating a image management system and have a few questions, if anyone could help 1) I read somewhere that storing images in a mysql database as a BLOB reduces speed and efficiency. Is this true? I don't expect to be serving many images although they could feasible get up to about 1000. I am instead opting to just store the...
2
4014
by: jn | last post by:
This is the weirdest thing I've come across in a while. I'm trying to resize an image. If I give it a small image ( < 100K) it will resize. If I give it a larger image, it gives me the IE "Action Cancelled" page. The memory_limit for PHP has been changed to 30MB so that's not the problem. I know that the line with imagecreatefromjpeg() is the problem (even though I can't get an error message). I can run this code with the large images...
0
1888
by: Michael Rostkowski | last post by:
I posted this in alt.php, but as a reply, so now I'm posting it here for people who might have missed it but still could find it useful. Thanks to Andy Hassall for giving me good information. I compared the smooth image resampling used in PHP to create good quality thumbnails of large images, used commonly in image galleries. i compared ImageMagick and PHP (with GD2) and compiled some statistics below. I ran two test. Both used a...
5
1975
by: Fred | last post by:
I've written a number of "image gallery" pages before, but I'm trying to do something a little different. All the images are rectangular (these are just pictures from my camera), and the thumbnail images I have are uniform in size in the sense that the longest dimension is fixed, and the shortest dimension is fixed. That is, if it's a horizontal image, the width is X, if it's a vertical image, the height is X. I used to create...
7
2346
by: Vinay | last post by:
Hi All: I have a small application that stores images either in the database or as files (depending on the user preference). I'm in the process of providing a web interface to this application. 1. If the images are stored in the DB then, every an image is requested, it will need to be pulled out and a temp file created and then displayed? What is the best way to do this?
8
2454
by: Chris Beall | last post by:
I'm struggling with how to handle, on a web page, images that contain text that the user must be able to read. Examples: tombstone photos, photos or scans of historic documents (handwritten or typed), a map with place names, route numbers, etc. (An appropriate alternative for audio UAs would be provided and is not a part of my concern). I see two ways to handle these images: 1. Dynamic scaling, with the source image containing enough...
4
1359
by: moondaddy | last post by:
I have an app where users will upload photos to their shopping cart. When they review their cart I need to include a light weight thumbnail of the image they uploaded. how can I take the image a user uploaded (PixOfMom.jpg at 600k) and convert it to a thumbnail and put into the image url of a .net image control using vb.net 1.1? Thanks! -- moondaddy@nospam.com
3
4018
by: wardemon | last post by:
Hi All, I have a aspx page named: ImageProcess.aspx that creates a thumbnail version of an image by passing the ImagePath, width, and height. The ImagePath is taken from a table from a database, while width and height is user specific - meaning user can change this on demand. My question is, although this rendering images on the fly is cool, I would like to implement some sort of mechanism/logic that it wont keep rendering the thumbnail...
3
3584
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own little website: 1. Small: DOWNsize of original image to be used as a thumbnail. 2. Medium: DOWNsize of original image to be used as user avatars/icons in forums or profiles.
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.