2017-03-02 5 views
-1

C#의 Windows Phone 10 용으로 만들어진 간단한 사진 캡처 기능이 있습니다.미디어 스트림 속성 해상도를 변경하면 사진이 잘립니다. (Windows Mobile 10)

캡처 설정 :

   _captureManager = new MediaCapture(); 

       await _captureManager.InitializeAsync(new MediaCaptureInitializationSettings 
       { 
        StreamingCaptureMode = StreamingCaptureMode.Video, 
        PhotoCaptureSource = PhotoCaptureSource.Photo, 
        AudioDeviceId = string.Empty, 
        VideoDeviceId = cameraId 
       }); 


       var resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo); 

       // Here I choose same resolution as native camera does 
       await _captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolutions[3]); 

내가 사진 캡처 :

using (var imageStream = new InMemoryRandomAccessStream()) 
      { 
       var format = ImageEncodingProperties.CreateJpeg(); 
       var capturefile = await _storeFolder.CreateFileAsync(photoName, CreationCollisionOption.GenerateUniqueName); 

       await _captureManager.CapturePhotoToStreamAsync(format, imageStream); 

..... 
} 

그러나 CapturePhotoToStreamAsync에 내 그림이 잘립니다됩니다. SetMediaStreamPropertiesAsync를 제거 할 때 발생하는 것은 아니지만 내 기본 카메라가 다른 해상도를 선택합니다.

누구든지이 문제의 원인이 될 수 있습니다.

+0

'해상도 [3]': 사진을 캡처 할 때이 후, 내가 원하는 해상도로 캡처 한 이미지를 변경하는 BitmapDecoder를 사용

var _photoResolution = VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo) 

: 먼저 나는에서 사진 해상도 정보를 저장 '? – IInspectable

+0

미디어 스트림 속성 목록의 세 번째 멤버 (내 기본 카메라와 동일한 속성). 지금 진행 중이라는 사실을 염두에 두지 말고 나중에 가로 세로 비율에 따라 프로그래밍 방식으로 최상의 해상도를 선택합니다. 문제는 미디어 스트 램 속성을 변경할 때 내 그림이 잘리는 문제입니다. – user2081328

+1

그것은 마법의 숫자이며 마법의 숫자가 나올 때마다 그것이 무엇을 의미하는지 묻습니다. 귀하의 답변은 매우 계몽 적이지는 않았습니다 (또한 잘못된 것입니다). 네 번째 멤버이지만, 네 번째 멤버에 저장된 내용을 알 수있는 방법이 없습니다. 그것은 당신이 찾고있는 것이거나 전혀 다른 것일 수 있습니다. 도움이 필요할 경우 코드를 읽기보다 어렵게 만들지 마십시오. – IInspectable

답변

0

좋아, 누군가가 필요하면 추가 답변을 찾았습니다. 내 카메라의 해상도는 1.64 *입니다. 이 해상도의 경우 가로 세로 비율 16 : 9 (1.77 *)가 작동하지 않습니다. 그래서 내가 그것을 설정하려 할 때, 그것은 실패 할 것입니다. 이 해상도는 기본 카메라에서 작동하기 때문에 제대로 작동하려면 몇 가지 설정이 있어야한다고 생각했습니다.

하지만 해결 방법을 만들었습니다. `3 기능 -

using (var imageStream = new InMemoryRandomAccessStream()) 
      { 
       var photoName = $"myPhoto.jpg"; 
       var capturefile = await _storeFolder.CreateFileAsync(photoName, CreationCollisionOption.GenerateUniqueName); 

       await _captureManager.CapturePhotoToStreamAsync(format, imageStream); 

       var dec = await BitmapDecoder.CreateAsync(imageStream); 
       var enc = await BitmapEncoder.CreateForTranscodingAsync(imageStream, dec); 

       enc.BitmapTransform.ScaledHeight = _photoResolution.Height; 
       enc.BitmapTransform.ScaledWidth = _photoResolution.Width; 

       // bounds must be set for ScaledHeight and ScaledWidth transform would work, but I don't know why 
       // based on device orientation, I am setting proper value for width and height 
       var bounds = new BitmapBounds 
       { 
        Height = ((deviceOrientation == Enums.DeviceOrientation.Portrait || deviceOrientation == Enums.DeviceOrientation.Flipped) ? _photoResolution.Width : _photoResolution.Height) - 1, 
        Width = ((deviceOrientation == Enums.DeviceOrientation.Portrait || deviceOrientation == Enums.DeviceOrientation.Flipped) ? _photoResolution.Height : _photoResolution.Width) - 1, 
        X = 1, 
        Y = 1 
       }; 
       enc.BitmapTransform.Bounds = bounds; 

       await enc.FlushAsync(); 

       using (var fileStream = await capturefile.OpenStreamForWriteAsync()) 
       { 
        await RandomAccessStream.CopyAsync(imageStream, fileStream.AsOutputStream()); 
       }      
      }