PDA

View Full Version : سوال: اعتبارسنجي (Validation) عکس resize شده



bftarane
سه شنبه 14 آذر 1391, 19:04 عصر
سلام.
لطفاً اين کد رو ببينيد

private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
{
using (var image = System.Drawing.Image.FromStream(sourcePath))
{
// can given width of image as we want
//var newWidth = (int)(image.Width * scaleFactor);

var newWidth = 200;
// can given height of image as we want
//var newHeight = (int)(image.Height * scaleFactor);

var newHeight = 200;
var thumbnailImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbnailImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);

thumbGraph.DrawImage(image, imageRectangle);
Response.Write(thumbnailImg.Size.ToString());

thumbnailImg.Save(targetPath, image.RawFormat);


مرجع کد: http://tuvianblog.com/2011/07/07/how-to-create-thumbnail-image-in-asp-netc-or-resize-the-image-before-upload-in-asp-netc/
حالا چطور ميشه در اين کد حجم tumbnail رو اگه از يه مقداري بيشتر بود يه پيغام داد
مثلاً من سايزش رو با اين کد مي تونم نشون بدم
Response.Write(thumbnailImg.Size.ToString());
ولي براي حجم نمي دونم راهي داره يا نه!
لطفاً راهنمايي کنيد.