J'utilise le code suivant dans mon site, pour la création des vignettes:Créer miniature dans # .NET C en définissant la largeur
string furl = "~/images/thumbs/" + matchString;
lBlogThumb.ImageUrl = GetThumbnailView(furl, 200, 200);
private string GetThumbnailView(string originalImagePath, int height, int width)
{
//Consider Image is stored at path like "ProductImage\\Product1.jpg"
//Now we have created one another folder ProductThumbnail to store thumbnail image of product.
//So let name of image be same, just change the FolderName while storing image.
string thumbnailImagePath = originalImagePath.Replace("thumbs", "thumbs2");
//If thumbnail Image is not available, generate it.
if (!System.IO.File.Exists(Server.MapPath(thumbnailImagePath)))
{
System.Drawing.Image imThumbnailImage;
System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(Server.MapPath(originalImagePath));
imThumbnailImage = OriginalImage.GetThumbnailImage(width, height,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
imThumbnailImage.Save(Server.MapPath(thumbnailImagePath), System.Drawing.Imaging.ImageFormat.Jpeg);
imThumbnailImage.Dispose();
OriginalImage.Dispose();
}
return thumbnailImagePath;
}
public bool ThumbnailCallback() { return false; }
Je voudrais changer ce code, et être en mesure de créer une largeur définissant la vignette SEULEMENT. Ce que j'ai à l'esprit est en fait quelque chose comme le recadrage/redimensionnement de l'image, en utilisant une largeur statique, en maintenant son ratio. Est-ce possible;
Est-ce que vous voulez? newHeight = oldHeight * newWidth/oldWidth, vous ne savez pas exactement ce que vous voulez dire quand vous dites que vous voulez recadrer l'image - voulez-vous recadrer ET redimensionner? –
merci pour votre aide – zekia
idk pourquoi mais cela m'a donné un "out of memory" err .. y at-il quelqu'un qui peut mettre une exeption pour cela? Je ne sais pas vraiment comment C# gère la mémoire. –