Sunday 15 April 2012

windows phone 8.1 - How to save image in picture library in wp8.1 -



windows phone 8.1 - How to save image in picture library in wp8.1 -

how save image app image library in wp8.1 runtime app? helpful links or code snippet?

include first

using microsoft.phone.tasks; using system.windows.media.imaging; using system.threading.tasks; using windows.storage; using windows.graphics.imaging; using system.io.isolatedstorage; using microsoft.xna.framework.media; using system.io;

then declare

bitmapimage bit = new bitmapimage(); string filename; cameracapturetask cameracapturetask;

in constructor

cameracapturetask = new cameracapturetask(); cameracapturetask.completed += new eventhandler<photoresult>(cameracapturetask_completed);

then re-create paste this

void cameracapturetask_completed(object sender, photoresult e) { if (e.taskresult == taskresult.ok) { messagebox.show(e.chosenphoto.length.tostring()); bit.setsource(e.chosenphoto); myimage.source = bit; filename = "wp_" + convert.tostring(datetime.now.ticks) + ".jpg"; using (var isolatedstorage = isolatedstoragefile.getuserstoreforapplication()) { if (isolatedstorage.fileexists(filename)) isolatedstorage.deletefile(filename); isolatedstoragefilestream filestream = isolatedstorage.createfile(filename); bitmapimage bitmap = new bitmapimage(); bitmap.setsource(e.chosenphoto); writeablebitmap wb = new writeablebitmap(bitmap); wb.savejpeg(filestream, wb.pixelwidth, wb.pixelheight, 0, 100); filestream.close(); } //code display photo on page in image command named myimage. //system.windows.media.imaging.bitmapimage bmp = new system.windows.media.imaging.bitmapimage(); //bmp.setsource(e.chosenphoto); //myimage.source = bmp; } }

then phone call methhod ever eyou want

cameracapturetask.show();

to add together media library re-create code given below

var library = new medialibrary(); using (var isolatedstorage = isolatedstoragefile.getuserstoreforapplication()) { isolatedstoragefilestream filestream = isolatedstorage.openfile(filename, filemode.open, fileaccess.readwrite); var pic = library.savepicture(filename, filestream); }

windows-phone-8.1

No comments:

Post a Comment