我将我的服务编码为thate在我的Windows 8应用程序中拍照。我使用了 CameraCaptureUI API。它可以工作,但结果是,所拍摄的图像是镜像的:左边是右边,反之亦然。 我在 CameraCapture 的 PhotoSettings 中搜索并在互联网上搜索,但没有。
我想也许解决方法是旋转我从相机流中保存的bitmapimage。这是我迄今为止所尝试过的,它不起作用:/
public async Task<IPhoto> TakePhotoAsync(string filename)
{
var dialog = new CameraCaptureUI();
dialog.PhotoSettings.CroppedAspectRatio = new Size(4, 3);
dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
StorageFile file = await dialog.CaptureFileAsync( CameraCaptureUIMode.Photo );
if (file != null)
{
var stream = await file.OpenAsync(FileAccessMode.Read);
//create decoder and encoder
BitmapDecoder dec = await BitmapDecoder.CreateAsync(stream);
BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(stream, dec);
enc.BitmapTransform.Rotation = BitmapRotation.Clockwise180Degrees;
await enc.FlushAsync();
var bitmap = new BitmapImage();
bitmap.SetSource(stream);
return new WPhotos(file);
}
return null;
}
提前感谢您的时间和帮助:)
答案 0 :(得分:1)
答案 1 :(得分:1)
标准化CameraCaptureUI
捕获的照片方向的另一种解决方案是将其解码为SoftwareBitmap
,然后重新编码:
var captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.SmallVga;
var photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo == null) { return false; }
var photoprops = await photo.Properties.GetImagePropertiesAsync();
if (photoprops.Orientation != PhotoOrientation.Normal)
{
using (var readStream = await photo.OpenAsync(FileAccessMode.Read))
{
var decoder = await BitmapDecoder.CreateAsync(readStream);
using (var sb = await decoder.GetSoftwareBitmapAsync())
using (var memStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, memStream);
encoder.SetSoftwareBitmap(sb);
encoder.IsThumbnailGenerated = false;
await encoder.FlushAsync();
// photo data with normalised orientation available in memStream
}
}
}