将图片缩小或放大至目标宽高
public Image pictureProcess(Image sourceImage,int targetWidth,int targetHeight) {
int width;//图片最终的宽
int height;//图片最终的高
try
{
System.Drawing.Imaging.ImageFormat format = sourceImage.RawFormat;
Bitmap targetPicture = new Bitmap(targetWidth, targetHeight);
Graphics g = Graphics.FromImage(targetPicture);
g.Clear(Color.White);
//计算缩放图片的大小
if (sourceImage.Width > targetWidth && sourceImage.Height <= targetHeight)
{
width = targetWidth;
height = (width * sourceImage.Height) / sourceImage.Width;
}
else if(sourceImage.Width <= targetWidth && sourceImage.Height > targetHeight)
{
height = targetHeight;