locked
How to set up the camera in the specified window to preview? RRS feed

  • Question

  • How to set up the camera in the specified window to preview?

    try
    	{
    		CameraCaptureUI^ dialog = ref new CameraCaptureUI();
    		dialog->PhotoSettings->CroppedAspectRatio = Size(9, 16);
    		dialog->PhotoSettings->AllowCropping = true;  
            dialog->PhotoSettings->Format = Windows::Media::Capture::CameraCaptureUIPhotoFormat::Png;
            dialog->PhotoSettings->MaxResolution = Windows::Media::Capture::CameraCaptureUIMaxPhotoResolution::HighestAvailable;
    		concurrency::task<StorageFile^> (dialog->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this] (StorageFile^ file)
    		{
    			if (nullptr != file)
    			{
    				concurrency::task<Streams::IRandomAccessStream^> (file->OpenAsync(FileAccessMode::Read)).then([this] (Streams::IRandomAccessStream^ stream)
    				{
    					BitmapImage^ bitmapImage = ref new BitmapImage();
    					bitmapImage->SetSource(stream);										 
    					vector<SignPageInfo>::iterator IterRectImage;	
    					for( IterRectImage = m_VecSignPage.begin(); IterRectImage != m_VecSignPage.end(); ++IterRectImage )
    					{		 
    						if( (*IterRectImage).m_SignPageShow->Name->Equals(rect_Name) )
    						{	
    							(*IterRectImage).m_SignPageShow->RectOutImage->ImageSource = bitmapImage;
    							 break;
    						}
    					}
                     
    				});            
    			}
    			else
    			{
    				Windows::UI::Popups::MessageDialog^ msgimage = ref new Windows::UI::Popups::MessageDialog(L"No photo captured");
    				msgimage->ShowAsync();               
    			}
    		});
    	}
    	catch (Platform::Exception^ ex)
    	{
    		Windows::UI::Popups::MessageDialog^ msgimage = ref new Windows::UI::Popups::MessageDialog(ex->Message);
    		msgimage->ShowAsync();       
    	}		
    This camera is open system open full-screen window pictures, how to put the picture window is set to the specified window by yourself?
    Tuesday, August 6, 2013 7:08 AM

Answers

All replies

  • If you want to control the UI for camera capture then use the MediaCapture element instead of the CameraCaptureUI.

    See the Media capture using capture device sample (Windows 8.1)             for an example

    • Marked as answer by Terry.hu Monday, August 12, 2013 4:38 AM
    Tuesday, August 6, 2013 5:39 PM
    Moderator
  • Rob,thanks!

    Now my preview window :

    previewElement->Width =100;
    previewElement->Height =160;

    As height>width ,so that preview isn't full whole window ,What should I do to fill the window?

    Wednesday, August 7, 2013 7:55 AM
  • You can set the Width and Height to match the window you want, but it needs to match the aspect ratio that you are recording or it must letterbox, clip, or stretch.

    --Rob

    Friday, August 9, 2013 11:54 PM
    Moderator