サムネイルフォルダに画像のサムネイルをアップロードして保存しようとしています。A Bitmap.SaveメソッドでGDI +で一般的なエラーが発生しました
私は次のリンク使用しています:例外の原因となっている
http://weblogs.asp.net/markmcdonnell/archive/2008/03/09/resize-image-before-uploading-to-server.aspx
しかし
newBMP.Save(directory + "tn_" + filename);
を "一般的なエラーがGDI +で発生しました。"
私はフォルダのパーミッションを与えようとしましたが、保存するときに新しい別のbmpオブジェクトを使用しようとしました。
編集:
protected void ResizeAndSave(PropBannerImage objPropBannerImage)
{
// Create a bitmap of the content of the fileUpload control in memory
Bitmap originalBMP = new Bitmap(fuImage.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth/origHeight;
int thumbWidth = 100;
int thumbHeight = thumbWidth/sngRatio;
int bannerWidth = 100;
int bannerHeight = bannerWidth/sngRatio;
// Create a new bitmap which will hold the previous resized bitmap
Bitmap thumbBMP = new Bitmap(originalBMP, thumbWidth, thumbHeight);
Bitmap bannerBMP = new Bitmap(originalBMP, bannerWidth, bannerHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(thumbBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, thumbWidth, thumbHeight);
Bitmap newBitmap = new Bitmap(thumbBMP);
thumbBMP.Dispose();
thumbBMP = null;
// Save the new graphic file to the server
newBitmap.Save("~/image/thumbs/" + "t" + objPropBannerImage.ImageId, ImageFormat.Jpeg);
oGraphics = Graphics.FromImage(bannerBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, bannerWidth, bannerHeight);
// Save the new graphic file to the server
bannerBMP.Save("~/image/" + objPropBannerImage.ImageId + ".jpg");
// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
bannerBMP.Dispose();
oGraphics.Dispose();
}
ありがとう、これらを使用して私はそれが働いている。私は再びコードを投稿しています。 – donstack
関連する問題、多分それは誰かを助けるでしょう - 私はビットマップ上に "GDI +で発生した一般的なエラー"を既に持っています。リモートWebサーバー上でのみ、私のローカルのテストマシンではありません。 Azure IISサーバー上のGDI +は、GIMPによって生成された新しい形式のBMPを処理できないことを示しています。私はa)BMPをペイントで再保存するb)代わりに非圧縮のPNGを使用するc)GMPと一緒に24ビットBMPとして保存する(悪い品質) – Andrew