GetThumbnailImage m'out of memory à la figure

Lanzouille Messages postés 1 Date d'inscription jeudi 17 juillet 2003 Statut Membre Dernière intervention 17 juillet 2003 - 17 juil. 2003 à 11:21
jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 - 17 juil. 2003 à 18:42
Voilà le pb :
j'ai un formulaire avec un champ de type file qui me permet d'uploader une image. J'ai besoin de récupérer cette image et de la redimmensionner à la bonne largeur.

Pour ce faire j'utilise la méthode getThumbnailImage() de la classe Image du Framework :

		public void setImage( Stream pImage )
{
Bitmap newImage = new Bitmap( pImage );
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image myThumbnail = newImage.GetThumbnailImage(largeur, (largeur/newImage.Width)*newImage.Height, myCallback, IntPtr.Zero); // ça plante ici !!
myThumbnail.Save( "C:\\InetPub\\wwwroot\\dynimg\"+ nom + ID +".jpg", System.Drawing.Imaging.ImageFormat.Jpeg );

}


le hic, c'est que si l'image dépasse disons 10 Ko, je reçoit en retour une exception "Out of memory"...

Quelqu'un a-t-il une solution ? c'est relativement urgent (pour hier, en fait :/ )

1 réponse

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
17 juil. 2003 à 18:42
lol pour hier :)

C assez simple : j'ai fais une source qui pourrait t'aider : http://www.aspfr.com/article.aspx?Val=553 dont voici le code qui t'interesse

La partie qui t'interesse c'est celle la

Private Sub CorrectionTaille(ByVal Photo As String)

Dim PhotominiPath As String
PhotominiPath = Server.MapPath("phototeque") & Path.DirectorySeparatorChar & _
Categorie & Path.DirectorySeparatorChar & _
"miniature" & Path.DirectorySeparatorChar & _
Path.GetFileNameWithoutExtension(Photo) & ".jpg"

Dim BmpPhoto As New Bitmap(Photo)
Dim BmpPhotoMini As New Bitmap(PhotoMiniWidth, PhotoMiniHeight)
Dim graphicsPhotoMini As Graphics = Graphics.FromImage(BmpPhotoMini)
graphicsPhotoMini.DrawImage(BmpPhoto, _
New Rectangle(0, 0, PhotoMiniWidth, PhotoMiniHeight), _
0, 0, BmpPhoto.Width, BmpPhoto.Height, _
System.Drawing.GraphicsUnit.Pixel)
BmpPhoto.Dispose()
graphicsPhotoMini.Dispose()

If File.Exists(PhotominiPath) Then
File.Delete(PhotominiPath)
End If

BmpPhotoMini.Save(PhotominiPath, System.Drawing.Imaging.ImageFormat.Jpeg)
BmpPhotoMini.Dispose()

EcrireLog("Creation de la miniature de " & Path.GetFileNameWithoutExtension(Photo) & " réalisé avec succé")
End Sub ' Finit & pas commenté :\

mais je l'ai pas encore commenté et ca fait deja pas mal de temps donc je m'en suiviens plus tres bien

PhotominiPath est le dossier de la miniature que tu veux créer
Photo est je crois un string du dossier de la photo
PhotoMiniWidth, PhotoMiniHeight sont les tailles de la miniature

ecrirelog() c'est uns sub pour ecrire un log, bon c du VB et pas du C# car je connais pas du tt mais si tu veux il y a www.c2i.fr dans l'espace de nom system.drawing un exemple dont je me suis inspiré :)

J'espere que ca t'ira :)
0
Rejoignez-nous