C# 在Windows Mobile中调整图像大小
是否有人知道如何在.net 2.0Compact框架上调整图像大小C# 在Windows Mobile中调整图像大小,c#,.net,windows-mobile,compact-framework,C#,.net,Windows Mobile,Compact Framework,是否有人知道如何在.net 2.0Compact框架上调整图像大小 我希望能够从手机内存中获取手机摄像头拍摄的图像,调整图像大小,然后将其上载到Web服务,这样我就不需要将调整大小的图像存储在磁盘上。Graphics.FromImage适用于jpg图像,但您可能会遇到内存问题 看看这篇文章,了解一些想法。Graphics.FromImage应该适用于jpg图像,但是您可能会遇到内存问题 请看一看,了解一些想法。此vb.net可在Windows Mobile上运行。唯一限制:打开大型位图时会导致O
我希望能够从手机内存中获取手机摄像头拍摄的图像,调整图像大小,然后将其上载到Web服务,这样我就不需要将调整大小的图像存储在磁盘上。Graphics.FromImage适用于jpg图像,但您可能会遇到内存问题
看看这篇文章,了解一些想法。Graphics.FromImage应该适用于jpg图像,但是您可能会遇到内存问题
请看一看,了解一些想法。此vb.net可在Windows Mobile上运行。唯一限制:打开大型位图时会导致OutOfMemoryException:
Private Function ResizedImage(ByVal image As Bitmap, ByVal maxW As Integer, ByVal maxH As Integer) As Bitmap
Dim divideByH, divideByW As Double
Dim width, height As Integer
divideByW = image.Width / maxW
divideByH = image.Height / maxH
If divideByW > 1 Or divideByH > 1 Then
If divideByW > divideByH Then
width = CInt(CDbl(image.Width) / divideByW)
height = CInt(CDbl(image.Height) / divideByW)
Else
width = CInt(CDbl(image.Width) / divideByH)
height = CInt(CDbl(image.Height) / divideByH)
End If
Dim scaled As New Bitmap(width, height)
Dim g As Graphics
g = Graphics.FromImage(scaled)
g.DrawImage(image, New Rectangle(0, 0, width, height), New Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel)
g.Dispose()
ResizedImage = scaled
Else
ResizedImage = image
End If
End Function
此vb.net在Windows Mobile上工作。唯一限制:打开大型位图时会导致OutOfMemoryException:
Private Function ResizedImage(ByVal image As Bitmap, ByVal maxW As Integer, ByVal maxH As Integer) As Bitmap
Dim divideByH, divideByW As Double
Dim width, height As Integer
divideByW = image.Width / maxW
divideByH = image.Height / maxH
If divideByW > 1 Or divideByH > 1 Then
If divideByW > divideByH Then
width = CInt(CDbl(image.Width) / divideByW)
height = CInt(CDbl(image.Height) / divideByW)
Else
width = CInt(CDbl(image.Width) / divideByH)
height = CInt(CDbl(image.Height) / divideByH)
End If
Dim scaled As New Bitmap(width, height)
Dim g As Graphics
g = Graphics.FromImage(scaled)
g.DrawImage(image, New Rectangle(0, 0, width, height), New Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel)
g.Dispose()
ResizedImage = scaled
Else
ResizedImage = image
End If
End Function
这是我在.NET CF 2.0应用程序中用于调整图像大小的C#代码:
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;
}
这是我在.NET CF 2.0应用程序中用于调整图像大小的C#代码:
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;
}
c代码缺少一个强制转换
float widthRatio = (float) maxSize.Width / image.Width;
float heightRatio = (float) maxSize.Height / image.Height;
以及图像居中:
graphics.DrawImage(image, new Rectangle((maxSize.Width - width) / 2, (maxSize.Height -height ) / 2, width, height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
c代码缺少一个强制转换
float widthRatio = (float) maxSize.Width / image.Width;
float heightRatio = (float) maxSize.Height / image.Height;
以及图像居中:
graphics.DrawImage(image, new Rectangle((maxSize.Width - width) / 2, (maxSize.Height -height ) / 2, width, height), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
引用论坛的帖子:“我希望有一个.NET实例调用DLL。我从来没有在C环境中用C或C++做过任何事情,我希望不要这样做。”“我希望得到一个调用DLL的.net示例。我从来没有在C或C++环境下做过任何事情,我希望不要“我喜欢这个说法,不管怎样,谢谢。这看起来很有趣,但不幸的是我在几周内无法尝试。BR,LarreThis看起来很有趣,但不幸的是我会在几周内再试试。Br,Larre。