Windows phone 8.1 BitmapDecoder.GetPixelDataAsync(参数)更改捕获图像的方向
我正在使用UWP应用程序,在图像控件中显示相机拍摄的图像(肖像)时遇到了一个问题Windows phone 8.1 BitmapDecoder.GetPixelDataAsync(参数)更改捕获图像的方向,windows-phone-8.1,uwp,windows-10-universal,windows-10-mobile,uwp-xaml,Windows Phone 8.1,Uwp,Windows 10 Universal,Windows 10 Mobile,Uwp Xaml,我正在使用UWP应用程序,在图像控件中显示相机拍摄的图像(肖像)时遇到了一个问题 decoder.GetPixelDataAsync( BitmapPixelFormat.Bgra8, // WriteableBitmap uses BGRA format BitmapAlphaMode.Ignore, transform, ExifOrientationMod
decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8, // WriteableBitmap uses BGRA format
BitmapAlphaMode.Ignore,
transform,
ExifOrientationMode.IgnoreExifOrientation, // This sample ignores Exif orientation
ColorManagementMode.DoNotColorManage);
结果是图像在背斜方向上的方向变化为90度//问题
定向正态
但是默认的decoder.GetPixelDataAsync()代码>工作正常
这里的问题是我不能使用默认版本的GetPixelDataSync(),因为我需要使用BitmapTransformation缩放图像
请帮忙
完整代码:
public async Task PrepareCapturedImage(StorageFile originalFile)
{
try
{
BitmapImage capturedImage_ = new BitmapImage();
BitmapDecoder decoder = null;
// the image is sometimes not created and we are trying to access it
await Task.Delay(300);
using (IRandomAccessStream stream = await originalFile.OpenAsync(FileAccessMode.Read))
{
capturedImage_.SetSource(stream);
decoder = await BitmapDecoder.CreateAsync(stream);
}
BitmapTransform transform = new BitmapTransform();
uint newHeight = Convert.ToUInt32(capturedImage_.PixelHeight);
uint newWidth = Convert.ToUInt32(capturedImage_.PixelWidth);
transform.ScaledHeight = newHeight;
transform.ScaledWidth = newWidth;
PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8, // WriteableBitmap uses BGRA format
BitmapAlphaMode.Ignore,
transform,
ExifOrientationMode.IgnoreExifOrientation, // This sample ignores Exif orientation
ColorManagementMode.DoNotColorManage);
// An array containing the decoded image data, which could be modified before being displayed
byte[] sourcePixels = pixelData.DetachPixelData();
using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
{
BitmapEncoder enc = null;
BitmapPropertySet propertySet = new BitmapPropertySet();
enc = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, ras, propertySet);
// write the pixel data to our stream
enc.SetPixelData(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, newWidth, newHeight, decoder.DpiX, decoder.DpiY, sourcePixels);
await enc.FlushAsync();
ras.Seek(0);
BitmapImage image = new BitmapImage();
image.SetSource(ras);
cameraOutputImage.Source = image;
}
}
catch (Exception ex)
{
}
}
用一个普通的图像文件测试你的代码,效果很好,所以我认为问题与你的相机拍摄的图像文件有关。您检查过原始图像文件的方向了吗?你用什么设备来测试你的代码?或者您可以分享您的示例,以便我们在Lumia 640和950XL;上进行测试;。原始图像的方向是旋转270。如果我在BitmapTransformation中将旋转设置为270,并使用标志“RespectExiforOrientation”,则会得到相同的结果。我正在使用Lumia 950。我在这里附加了一个项目,用一个普通的图像文件测试你的代码,它工作得很好,所以我认为这个问题与你的相机拍摄的图像文件有关。您检查过原始图像文件的方向了吗?你用什么设备来测试你的代码?或者您可以分享您的示例,以便我们在Lumia 640和950XL;上进行测试;。原始图像的方向是旋转270。如果我在BitmapTransformation中将旋转设置为270,并使用标志“RespectExiforOrientation”,则会得到相同的结果。我正在使用Lumia 950。我已附加在这里的项目