Testing Photos with WP7 Emulator

Update (06/08) – You can now capture images with your webcam and send it straight to your app. Check out my source code here.

Quick tip if you’re using the April Refresh SDK. If you’ve tried calling the PhotoChooserTask from the WP7 emulator, you’ve probably noticed that there aren’t any images to import. You can take a ‘picture’ from the CameraCaptureTask and use the static ChooserListener class to grab the image. However, it is a very basic picture (simply a square on background), so if you’re developing image-editing apps, it may not be too suitable for testing. Instead, what you can do in the emulator is to launch the Internet Explorer application. Find the image you want to use. Click and hold on the image, and you’ll have the option to Save or Share the image. Simply save it and head back into your app. Launch the PhotoChooserTask and you’ll be able to see that image. You can the use the ChooserListener class to grab the image selected from the user. This method seems to provide a better testing opportunity than the image obtained from the camera. Here’s what I used to obtain the photo using the ChooserListener class (I’ve removed some code specific to my project):

Update: Now that the beta version is out, you can find out how to use the camera and test photos on MSDN:
Code Samples
Photos for Windows phone

The code below has only been tested on the April SDK. Visit the links above for code that works on the beta version of the SDK.


ChooserListener.ChooserCompleted += (sender, e) =>
{
//cast the events to a PhotoResult
var eventArgs = (TaskEventArgs<PhotoResult>)e;
//get the photo chosen by the user
var picture = eventArgs.Result.ChosenPhoto;
//create a new bitmap image
BitmapImage imgBitmap = new BitmapImage();
//set the bitmaps source as the photo (stream) selected by the user
imgBitmap.SetSource(picture);
//imgPlaceholder is an Image control in the XAML
imgPlaceholder.Source = imgBitmap;
};

@keyboardP

Share

2 Responses to Testing Photos with WP7 Emulator

  1. A Capsis says:

    I am working with the photochooser task and managed to upload the little black square to azure table.
    but I would like to try a real image… was not able to see anything after hold and save… any suggestions?

    • keyboardp says:

      Hi,
      I haven’t tried using this method with the Azure platform. However, in theory, if you can see it in the emulator via Internet Explorer app, you should be able to save the image. By ‘real image’, I assume you mean a normal picture from the internet?

      When you close the emulator, I believe the image is deleted so try doing this:
      1) Open a new session of the emulator
      2) Click on the IE icon and visit http://www.bing.com.
      3) Click and hold the Bing logo in the top left hand corner
      4) You should see a save/share option. Click on save.
      5) now click on the button with the Windows logo at the bottom of the emulator (in the middle)
      6) run your application with something like this:
      private void button1_Click(object sender, RoutedEventArgs e)
      {

      PhotoChooserTask pTask = new PhotoChooserTask();
      pTask.Show();
      }
      7) This should launch the photo chooser and you should be able to see the Bing image you saved.

      Hope that helps and let me know if this works and, if not, at what step it stopped working.

Leave a reply to A Capsis Cancel reply