Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用相机拍摄一张完美正方形的照片?_C#_Windows Phone 7_Camera_Windows Phone 7.1 - Fatal编程技术网

C# 用相机拍摄一张完美正方形的照片?

C# 用相机拍摄一张完美正方形的照片?,c#,windows-phone-7,camera,windows-phone-7.1,C#,Windows Phone 7,Camera,Windows Phone 7.1,我正在使用WP7相机样本,在拍摄图像时遇到了一个问题。现在,它使用标准480(宽)x 800(高)拍照。我想做的是把图片做成正方形,因为我的应用程序要求图片是一个完美的正方形 我将视频画笔调整为仅显示480x480,最初拍摄的图像看起来是方形的,但当您在图片中心内查看时,它是一幅普通的480x800肖像 是否有人知道如何将相机设置为拍摄方形照片或裁剪顶部和底部?您需要手动将像素复制到新位图。 因此,如果相机是水平的,并且您希望裁剪图像的左侧部分,以便新的宽度等于高度,那么类似的操作将起作用(我没

我正在使用WP7相机样本,在拍摄图像时遇到了一个问题。现在,它使用标准480(宽)x 800(高)拍照。我想做的是把图片做成正方形,因为我的应用程序要求图片是一个完美的正方形

我将视频画笔调整为仅显示480x480,最初拍摄的图像看起来是方形的,但当您在图片中心内查看时,它是一幅普通的480x800肖像


是否有人知道如何将相机设置为拍摄方形照片或裁剪顶部和底部?

您需要手动将像素复制到新位图。 因此,如果相机是水平的,并且您希望裁剪图像的左侧部分,以便新的宽度等于高度,那么类似的操作将起作用(我没有测试此代码,但即使它不是100%正确,它也应该为您提供基本思路):

WriteableBitmap SquareImage(WriteableBitmap srcBitmap)
{
int[]srcData=srcbimabit.Pixels;
int[]destData=new int[srcbimat.PixelHeight*srcbimat.PixelHeight];
对于(int row=0;row
您需要手动将像素复制到新位图。 因此,如果相机是水平的,并且您希望裁剪图像的左侧部分,以便新的宽度等于高度,那么类似的操作将起作用(我没有测试此代码,但即使它不是100%正确,它也应该为您提供基本思路):

WriteableBitmap SquareImage(WriteableBitmap srcBitmap)
{
int[]srcData=srcbimabit.Pixels;
int[]destData=new int[srcbimat.PixelHeight*srcbimat.PixelHeight];
对于(int row=0;row
您必须使用WritableBitMap您必须使用WritableBitMap这是一个很好的起点。事实证明,裁剪图像时,WriteableBitmap是一种方法。我所要做的就是将捕获的JPEG转换为可写位图,然后在裁剪后将其编码回JPEG流并保存到ISO。我发现此解决方案对我的应用程序很有用,但对于一些图片,我得到了
ArgumentOutOfRangeException
,特别是那些
pixelheight
为640,
pixelWidth
为480的照片,对于其他
pixelheight
为600,
pixelWidth
为800的照片,它工作正常。有什么原因吗?如何避免这种例外?您需要使用最小的尺寸来表示新的宽度和高度。int newsize=(srcBitmap.PixelHeightArgumentOutOfRangeException,特别是那些
pixelheight
为640,
pixelWidth
为480的照片,对于其他
pixelheight
为600,
pixelWidth
为800的照片,它工作正常。有什么原因吗?如何避免这种例外?您需要使用最小的尺寸来表示新的宽度和高度。int newsize=(srcBitmap.PixelHeight WriteableBitmap SquareImage(WriteableBitmap srcBitmap) { int[] srcData = srcBitmap.Pixels; int[] destData = new int[srcBitmap.PixelHeight * srcBitmap.PixelHeight]; for (int row = 0; row < srcBitmap.PixelHeight; ++row) { for (int col = 0; col < srcBitmap.PixelHeight; ++col) { destData[(row * srcBitmap.PixelHeight) + col] = srcData[(row * srcBitmap.PixelWidth) + col]; } } WriteableBitmap squareBitmap = new WriteableBitmap(srcBitmap.PixelHeight, srcBitmap.PixelHeight); destData.CopyTo(squareBitmap.Pixels, 0); return squareBitmap; }