locked
Capturing Snap from Camera using Win RT RRS feed

  • Question

  • I am Wrting code to capture image from camera.Below is the code I have written. Here method CapturePhotoToStorageFileAsync doesnot return.

            auto MediaCap = ref new Windows::Media::Capture::MediaCapture();
    
    	auto ImageProp = ref new Windows::Media::Capture::ImageEncodingProperties ();
    	
    	ImageProp->Height	= 240;
    	ImageProp->Width	= 320;
    	ImageProp->Subtype	= "JPEG";
    	
    	
    	Windows::Storage::StorageFile^ strFile;
    	auto res = MediaCap->CapturePhotoToStorageFileAsync(ImageProp,strFile);
    
    	res->Completed = ref new AsyncActionCompletedHandler([](IAsyncAction ^action)
    	{
    		//action->GetResults();
    		//action->Start();
    		///action->Close();
    	});
    
    	res->Start();
     }

    Am I missing something here??


    • Edited by chris_vr Wednesday, November 9, 2011 9:24 AM
    Wednesday, November 9, 2011 9:23 AM

Answers

  •  Hi, Chris_vr:

    You should create the file first.

    StorageFileRetrievalOperation^ CreateFileOp = KnownFolders::PicturesLibrary->CreateFileAsync("Test.jpg");
      CreateFileOp->Completed =  ref new AsyncOperationCompletedHandler<StorageFile^>(
        [=](IAsyncOperation<StorageFile^>^ op)
      {
       auto file = op->GetResults();
            
       Do you capture from camera here !!!!! (op->GetResults());

     

       {

      MediaCap->CapturePhotoToStorageFileAsync(ImageProp,op->GetResults());

         res->Completed = ref new AsyncActionCompletedHandler([](IAsyncAction ^action)

       {

         //action->GetResults();

         //action->Start();

        ///action->Close();

       });

      }

       op->Close();
      });



    • Edited by ytshe Thursday, November 10, 2011 2:20 AM
    • Marked as answer by chris_vr Thursday, November 10, 2011 7:23 AM
    Thursday, November 10, 2011 2:18 AM
  • Did you take a look at the Media Capture Sample?  it's in JavaScript but the concepts are similar for C++.

    Two things that I think could have caused the problem in your case:

    1. You need to initialize MediaCapture object by calling "InitializeAsync" before you can start capturing
    2. You need to actually create strFile before you start capturing media to this file.  You can use the method "Windows::Storage::KnownFolders::PicturesLibrary::CreateFileAsync" for this purpose.

    Thanks


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Marked as answer by chris_vr Thursday, November 10, 2011 7:25 AM
    Wednesday, November 9, 2011 3:43 PM

All replies

  • Did you take a look at the Media Capture Sample?  it's in JavaScript but the concepts are similar for C++.

    Two things that I think could have caused the problem in your case:

    1. You need to initialize MediaCapture object by calling "InitializeAsync" before you can start capturing
    2. You need to actually create strFile before you start capturing media to this file.  You can use the method "Windows::Storage::KnownFolders::PicturesLibrary::CreateFileAsync" for this purpose.

    Thanks


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Marked as answer by chris_vr Thursday, November 10, 2011 7:25 AM
    Wednesday, November 9, 2011 3:43 PM
  •  Hi, Chris_vr:

    You should create the file first.

    StorageFileRetrievalOperation^ CreateFileOp = KnownFolders::PicturesLibrary->CreateFileAsync("Test.jpg");
      CreateFileOp->Completed =  ref new AsyncOperationCompletedHandler<StorageFile^>(
        [=](IAsyncOperation<StorageFile^>^ op)
      {
       auto file = op->GetResults();
            
       Do you capture from camera here !!!!! (op->GetResults());

     

       {

      MediaCap->CapturePhotoToStorageFileAsync(ImageProp,op->GetResults());

         res->Completed = ref new AsyncActionCompletedHandler([](IAsyncAction ^action)

       {

         //action->GetResults();

         //action->Start();

        ///action->Close();

       });

      }

       op->Close();
      });



    • Edited by ytshe Thursday, November 10, 2011 2:20 AM
    • Marked as answer by chris_vr Thursday, November 10, 2011 7:23 AM
    Thursday, November 10, 2011 2:18 AM
  • Thanks Raman and ytshe

    I have added code according to java script sample

    I debuged the code I found ImageProp Donot Get Intialize properly.When I checked the value inside ImageProp though it is showing ???, ???,???,???,??? "Unable to read meory".Is New is failing here?

    auto ImageProp = ref new Windows::Media::Capture::ImageEncodingProperties ();

     

     

    • Edited by chris_vr Thursday, November 10, 2011 6:26 AM
    Thursday, November 10, 2011 6:10 AM
  • Can you share your project?  I can take a look.
    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    Thursday, November 10, 2011 5:52 PM