2013-05-12 2 views
0

내가 데스크톱 응용 프로그램에서 사진을 클릭하고 클립 보드에 복사 윈도우 8의 미디어 캡처 클래스를 사용하고 있습니다.느린 카메라 캡처

async public void UseCamera(int x, int y) 
    { 
     MediaCapture _mediaCapture = new MediaCapture(); 
     var _ImageFormat = ImageEncodingProperties.CreatePng(); 
     var _fileStream = new InMemoryRandomAccessStream(); 
     MediaCaptureInitializationSettings _cameraSettings1 = new MediaCaptureInitializationSettings(); 
     DeviceInformationCollection _deviceInformationCollection = null; 
     IReadOnlyList<IMediaEncodingProperties> res; 

     _deviceInformationCollection = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); 

     if (x > _deviceInformationCollection.Count - 1) 
     { 
      MessageBox.Show("Device Not found"); 
     } 

     else 
     { 
      _cameraSettings1.VideoDeviceId = _deviceInformationCollection[x].Id; 
      _cameraSettings1.AudioDeviceId = ""; 
      _cameraSettings1.PhotoCaptureSource = PhotoCaptureSource.VideoPreview; 
      _cameraSettings1.StreamingCaptureMode = StreamingCaptureMode.Video; 

      await _mediaCapture.InitializeAsync(_cameraSettings1); 

      res = _mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); 

      uint maxResolution = 0; 
      List<int> indexMaxResolution = new List<int>(); 
      if (res.Count >= 1) 
      { 
       for (int i = 0; i < res.Count; i++) 
       { 
        VideoEncodingProperties vp = (VideoEncodingProperties)res[i]; 

        if (vp.Width > maxResolution) 
        { 
         indexMaxResolution.Add(i); 
         maxResolution = vp.Width; 
        } 
       } 

       indexMaxResolution.Reverse(); 
       if (y > indexMaxResolution.Count()) 
       { 
        MessageBox.Show("Maximum supported resolution index : " + (indexMaxResolution.Count - 1).ToString()); 
       } 

       //this is the part that I believe is the trouble maker 


       else 
       { 
        await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, res[indexMaxResolution.ElementAt(y)]); 
        await _mediaCapture.CapturePhotoToStreamAsync(_ImageFormat, _fileStream); 

        Clipboard.SetImage(Image.FromStream(_fileStream.AsStream())); 
       } 
      } 
     } 
    } 

:

내 함수는 함수를 두 인수로 입력, 1) 원하는 장치 (앞, 뒷면 또는 USB 웹캠) 및 2) 원하는 해상도 여기

이다 얻어 이 기능은 작동하지만 문제는 매우 느립니다. 사진을 찍는 데 약 4-5 초가 걸립니다. 아무도 내가 잘못 가고있는 것을 말해 줄 수 있고, 어떻게하면 속도를 높일 수 있습니까? 내 카메라를 테스트하고 있기 때문에 클릭을 취할 수 @ 초당 약 2 사진 ..

답변

0

을 당신이 속도의 증가를 볼 수 있습니다 초기화 기능으로 모든 초기화 및 디바이스 정보 쿼리를 이동합니다. 내 경험 수집 장치 정보에

가 느립니다. 시간이 캡처 할 때, 오직 필요한 일을 수행해야 있도록

봅니다 가능한 선행으로 많은 일을 수행 할 수있다.

+0

내가 너무 ... 내가 세 가지 카메라를 초기화 및 프로그램 실행에 손 전에 해상도를 나열 것을 시도했다. 카메라 초기화 및 해상도 인덱싱이 매우 빠르게 수행되고 있습니다. 실제로 캡처가 느려지는 것 같아요. –

+0

이미지를 메모리에 유지하고 필요할 때만 쓸 수 있습니다. 클립 보드가 너무 느릴 수도 있습니다. 이것이 내가 아는 한 당신이 바꿀 수있는 유일한 것입니다. 일부 타이머를 추가하면 가장 느린 부분을 정확히 찾아 낼 수 있습니다. –

관련 문제