在Windows Mobile中调整图像大小 [英] Resize images in Windows Mobile
本文介绍了在Windows Mobile中调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有人知道在.net 2.0 紧凑型框架上调整图像大小的方法?
Is there anyone who knows a way to resize images on the .net 2.0 Compact Framework?
我希望能够从手机内存中获取用手机上的相机拍摄的图像,对其进行大小调整,然后将其上传到Web服务,因此我不需要将调整大小后的图像存储在磁盘上./p>
I want to be able to get images, taken with the camera on my phone, from the phones memory, resize them and then upload them to a webservice so I acctually don't need to store the resized images on disk.
推荐答案
这是我用来在.NET CF 2.0应用程序中调整图像大小的C#代码:
This is the C# code I use to resize images in my .NET CF 2.0 applications:
public static Image ResizePicture( Image image, Size maxSize )
{
if( image == null )
throw new ArgumentNullException( "image", "Null passed to ResizePictureToMaximum" );
if( ( image.Width > maxSize.Width ) || ( image.Height > maxSize.Height ) )
{
Image resizedImage = new Bitmap( maxSize.Width, maxSize.Height );
using( Graphics graphics = Graphics.FromImage( resizedImage ) )
{
graphics.Clear( Color.White );
float widthRatio = maxSize.Width / image.Width;
float heightRatio = maxSize.Height / image.Height;
int width = maxSize.Width;
int height = maxSize.Height;
if( widthRatio > heightRatio )
{
width = ( int )Math.Ceiling( maxSize.Width * heightRatio );
}
else if( heightRatio > widthRatio )
{
height = ( int )Math.Ceiling( maxSize.Height * widthRatio );
}
graphics.DrawImage(
image,
new Rectangle( 0, 0, width, height ),
new Rectangle( 0, 0, image.Width, image.Height ),
GraphicsUnit.Pixel );
}
return resizedImage;
}
return image;
}
这篇关于在Windows Mobile中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文