DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Save Camera Captures in Media Library for Windows Phone

Save Camera Captures in Media Library for Windows Phone

Dhananjay Kumar user avatar by
Dhananjay Kumar
·
Feb. 09, 12 · Mobile Zone · Interview
Like (0)
Save
Tweet
3.33K Views

Join the DZone community and get the full member experience.

Join For Free
i n this post we will see the way to capture a photo using camera and saving that in media library.

cameracapturetask chooser is used to capture photo using windows phone camera. to work with cameracapturetask , first you need add namespace:

image


then define a global variable:

image


in constructor of the page, you need to instantiate cameracapturetask and attach completed event handler.

image


next you need to show camera to user. you can call show function anywhere as per your business requirement however i am calling it on click event of a button as below,

image

now in the completed event of the cameracapturetask we need to save the image in media library. to work with medialibrary, you need to add reference of microsoft.xna.framework. after adding the reference add below namespace:

image


in completed event of cameracapturetask, make instance of medialibrary and call savepicture method as below:

image


as you see savepicture function takes two input parameters. it takes name of picture as one input parameter and picture stream as another. in this example we are saving picture taken from camera. you may also save picture downloaded from services as stream.

for your reference full source code is given as below:

using system;
using system.collections.generic;
using system.linq;
using system.net;
using system.windows;
using system.windows.controls;
using system.windows.documents;
using system.windows.input;
using system.windows.media;
using system.windows.media.animation;
using system.windows.shapes;
using microsoft.phone.controls;
using microsoft.phone.tasks;
using microsoft.xna.framework.media;

namespace phoneapp17
{
public partial class mainpage : phoneapplicationpage
{
// constructor
cameracapturetask cameratask;
public mainpage()
{
initializecomponent();
cameratask = new cameracapturetask();
cameratask.completed += new eventhandler<photoresult>(cameratask_completed);

}

void cameratask_completed(object sender, photoresult e)
{
if (e.taskresult == taskresult.ok)
{
medialibrary medialibrary = new medialibrary();
medialibrary.savepicture("givenameofimage", e.chosenphoto);

}
}

private void btnshowcamera_click(object sender, routedeventargs e)
{
cameratask.show();
}
}
}


in this way you can save picture to media library. i hope this post is useful. thanks for reading.


source: http://debugmode.net/2012/02/07/capture-picture-from-camera-and-save-in-media-library-in-windows-phone/
Windows Phone Library Media (communication)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Writing Beautiful, Optimized, and Better .NET Code With NDepend Static Analysis
  • Unified Observability Exporters: Metrics, Logs, and Tracing
  • Complete Guide to TestOps
  • Event-Driven Order Processing Program

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo