473,395 Members | 1,466 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,395 software developers and data experts.

[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.PixelFormat, ByVal ImageFormat As
System.Drawing.Imaging.ImageFormat, ByVal R As Integer, ByVal V As Integer,
ByVal B As Integer)
'Declarations des variables recevant les dimensions proportionnelles
Ă* 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.Height /
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.Height
'Définition de la taille souhaitée
Final_X = Width_Out
Final_Y = TailleY
Else
If Bitmap_In.Width >= Bitmap_In.Height Then
'DĂ©finition de la taille proprtionnelle
'si orientation = paysage
Width_Out = CInt(TailleX)
Height_Out = CInt(TailleX) * Bitmap_In.Height /
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.Height
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.Height /
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.Height
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_Out, Height_Out, PixelFormat)
'Déclaration de la surface de dessin du bitmap d'entrée
Dim MyGraphics_Temp As Graphics = Graphics.FromImage(Bitmap_Temp)
'Modification de la surface de dessin du bitmap d'entrée en
respectant les proptions
MyGraphics_Temp.DrawImage(Bitmap_In, 0, 0, Width_Out, Height_Out)
'Liberation de la mémoire des éléments concernat le Bitmap d'entrée
Bitmap_In.Dispose()
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(Final_X), CInt(Final_Y), PixelFormat)
'DĂ©claration de la surface de dessin du bitmap de sortie
Dim MyGraphics_out As Graphics = Graphics.FromImage(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(Couleur)
'Calcul des décalages Haut et gauche pour centrer de l'image
Dim Top As Integer = (Bitmap_Out.Height - Bitmap_Temp.Height) / 2
Dim Left As Integer = (Bitmap_Out.Width - Bitmap_Temp.Width) / 2
'Definition de la resolution (dpi)
Bitmap_Out.SetResolution(Resolution, Resolution)
'Remplissage de tout les pixels de la couleur du fond
MyGraphics_Out.FillRectangle(MyBackground, 0, 0,
Bitmap_Out.Width, Bitmap_Out.Height)
'Recopie du bitmap d'entrée en position centrée
MyGraphics_Out.DrawImageUnscaled(Bitmap_Temp, Left, Top,
Bitmap_Temp.Width, Bitmap_Temp.Height)
'Sauvegarde du bitmap de sortie
Bitmap_Out.Save(Destination, ImageFormat.Jpeg)
'Liberation de la mémoire
MyGraphics_out.dispose()
MyGraphics_out = Nothing
Bitmap_Out.Dispose()
Bitmap_Out = Nothing
Else
'Instanciation du Bitmap de sortie
Bitmap_Out = New Bitmap(CInt(Width_Out), CInt(Height_Out),
PixelFormat)
'DĂ©claration de la surface de dessin du bitmap de sortie
Dim MyGraphics_out As Graphics = Graphics.FromImage(Bitmap_Out)
'Recopie du bitmap d'entrée
MyGraphics_Out.DrawImageUnscaled(Bitmap_Temp, 0, 0,
Bitmap_Temp.Width, Bitmap_Temp.Height)
'Sauvegarde du bitmap de sortie
Bitmap_Out.Save(Destination, ImageFormat.Jpeg)
'Liberation de la mémoire
MyGraphics_out.dispose()
MyGraphics_out = Nothing
Bitmap_Out.Dispose()
Bitmap_Out = Nothing
End If
MyGraphics_Temp.Dispose()
MyGraphics_Temp = Nothing
Bitmap_Temp.Dispose()
Bitmap_Temp = Nothing
End Sub

and calling it with the following one :

Reduction(Src, Dest, 221, 142, 72, True, True, PixelFormat.Format24bppRgb,
ImageFormat.Jpeg, 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 1706
"CĂ©dric" <CĂ©dr**@discussions.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=interpolationmode&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
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...
2
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...
0
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. ...
5
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...
7
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....
8
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...
4
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...
3
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,...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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...

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.