c# - Saving an image to media library in Windows phone 7 -



c# - Saving an image to media library in Windows phone 7 -

i trying save image image command named image1 in app mainpage phone's media library here code, in writeablebitmap wr = image1; gives me error.

public void saveimageto(string filename = "gage.jpg") { filename += ".jpg"; var mystore = isolatedstoragefile.getuserstoreforapplication(); if (mystore.fileexists(filename)) { mystore.deletefile(filename); } isolatedstoragefilestream myfilestream = mystore.createfile(filename); writeablebitmap wr = image1; // give image source wr.savejpeg(myfilestream, wr.pixelwidth, wr.pixelheight, 0, 85); myfilestream.close(); // create new stream isolated storage, , save jpeg file media library on windows phone. myfilestream = mystore.openfile(filename, filemode.open, fileaccess.read); medialibrary library = new medialibrary(); //byte[] buffer = tobytearray(qrimage); library.savepicture(filename, myfilestream); }

you trying assign control "image1" writeablebitmap object, that's why have error (they 2 different types).

you should initialize writeablebitmap differently, depending on how source of "image1" set.

if "image1" references local image, can initialize corresponding writeablebitmap way:

bitmapimage img = new bitmapimage(new uri(@"images/yourimage.jpg", urikind.relative)); img.createoptions = bitmapcreateoptions.none; img.imageopened += (s, e) => { writeablebitmap wr = new writeablebitmap((bitmapimage)s); };

if want render image command writeablebitmap, can that:

writeablebitmap wr = new writeablebitmap(image1, null);

c# image windows-phone-7 media-library

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -