编码如何在asp.net中调整图像大小 [英] coding for how to resize image in asp.net
本文介绍了编码如何在asp.net中调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在asp.net中调整图像大小的编码
coding for how to resize image in asp.net
推荐答案
尝试
在ASP.NET中上传时调整图像大小 [ ^ ]
http://imageresizing.net/ [ ^ ]
Try
Resizing images while uploading in ASP.NET[^]
http://imageresizing.net/[^]
嗨@Abhinav
请使用以下代码
Hi @Abhinav
please use the following code
// Calculate the new image dimensions
System.Drawing.Bitmap originalBMP = new System.Drawing.Bitmap(FileUploadCtrlPatientPhoto.FileContent);
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 100;
if (sngRatio == 0)
sngRatio = 1;
int newHeight = newWidth / sngRatio;
// Create a new bitmap which will hold the previous resized bitmap
System.Drawing.Bitmap newBMP = new System.Drawing.Bitmap(originalBMP, newWidth, newHeight); // Create a graphic based on the new bitmap
System.Drawing.Graphics oGraphics = System.Drawing.Graphics.FromImage(newBMP);
// Set the properties for the new graphic file
oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
oGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, 120, 130);
// Save the new graphic file to the server
newBMP.Save(UploadPath);//upload path is either set from the webconfig file or some where else
// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();
希望对您有帮助
谢谢
Hope this will help you
Thanks
这篇关于编码如何在asp.net中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文