0
我正在使用網絡攝像頭捕獲Silverlight中的圖像。有沒有辦法配置網絡攝像頭捕捉低分辨率的圖像?如何減少從網絡攝像頭捕獲的圖像的大小
我正在使用網絡攝像頭捕獲Silverlight中的圖像。有沒有辦法配置網絡攝像頭捕捉低分辨率的圖像?如何減少從網絡攝像頭捕獲的圖像的大小
public static WriteableBitmap GetImageSource(Stream stream, double maxWidth, double maxHeight)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(stream);
Image img = new Image();
img.Effect = new DropShadowEffect() { ShadowDepth = 0, BlurRadius = 0 };
img.Source = bmp;
double scaleX = 1;
double scaleY = 1;
if (bmp.PixelHeight > maxHeight)
scaleY = maxHeight/bmp.PixelHeight;
if (bmp.PixelWidth > maxWidth)
scaleX = maxWidth/bmp.PixelWidth;
// maintain aspect ratio by picking the most severe scale
double scale = Math.Min(scaleY, scaleX);
return new WriteableBitmap(img, new ScaleTransform() { ScaleX = scale, ScaleY = scale });
}