c# - Saving Photos (CameraCaptureTask) to Isolated Storage - OutOfMemoryException -


i save photo, taken within app(using cameracapturetask), isolated storage. current problem consumption of ram, leads outofmemoryexception. happens when loading picture image-control.

my app should able take 10 pictures, save them isolated storage, show them in image control , if necessary delete picture good.

lowering resolution of pictures logically fixed exception, that's not way wanted go.

maybe can give me hint.

here code:

private cameracapturetask cctask = new cameracapturetask(); writeablebitmap[] imglist = new writeablebitmap[10]; random rnd = new random();  private void addpicture_button_click(object sender, eventargs e) {     cctask.show();     cctask.completed += cctask_completed; }  void cctask_completed(object sender, photoresult e)     {         if (e.taskresult == taskresult.ok)         {             writeablebitmap writeablebitmap = new writeablebitmap(1600,1200);             writeablebitmap.loadjpeg(e.chosenphoto);              string imagefolder = "unfaelle";             string datetime = datetime.now.tostring().replace("/","");             datetime = datetime.replace(":","");             string imagefilename = "foto_"+datetime+".jpg";             using (var isofile = isolatedstoragefile.getuserstoreforapplication())             {                  if (!isofile.directoryexists(imagefolder))                 {                     isofile.createdirectory(imagefolder);                 }                  string filepath = system.io.path.combine(imagefolder, imagefilename);                 using (var stream = isofile.createfile(filepath))                 {                     writeablebitmap.savejpeg(stream, writeablebitmap.pixelwidth, writeablebitmap.pixelheight, 0, 100);                 }             }              //now read image storage show worked...             bitmapimage imagefromstorage = new bitmapimage();              using (var isofile = isolatedstoragefile.getuserstoreforapplication())             {                 string filepath = system.io.path.combine(imagefolder, imagefilename);                 using (var imagestream = isofile.openfile(                     filepath, filemode.open, fileaccess.read))                 {                     imagefromstorage.setsource(imagestream);                 }             }              rectangle b = new rectangle()             {                 width = 100,                 height = 100,             };              thickness margin = b.margin;             margin.left = 10;             margin.top = 10;             b.margin = margin;              imagebrush imgbrush = new imagebrush();             imgbrush.imagesource = imagefromstorage;             b.fill = imgbrush;             b.tag = system.io.path.combine(imagefolder, imagefilename);             b.tap += ontapped;              pictures_wrappanel.children.add(b);         }     }  private void ontapped(object sender, system.windows.input.gestureeventargs e)         {              rectangle r = sender rectangle;             bitmapimage imagefromstorage = new bitmapimage();              using (var isofile = isolatedstoragefile.getuserstoreforapplication())             {                 string filepath = r.tag.tostring();                 using (var imagestream = isofile.openfile(                     filepath, filemode.open, fileaccess.read))                 {                     imagefromstorage.setsource(imagestream);                 }             }             img.source = imagefromstorage;         } 

thanks lot, if there unclear, feel free ask. maybe there easier way save photo, beginning app development greetings daniel

btw: 1600x1200 2mp, lowered resolution avoid exception, unfortunately delayed

10 pictures resolution of 1600 * 1200 use 80mb of ram. memory limit 90 mb on windows phone 7 , 150 mb on windows phone 8, there's no way you're trying work.

my app should able take 10 pictures, save them isolated storage, show them in image control , if necessary delete picture good.

this approach correct, loading full-sized picture display in thumbnails, total waste of ram. when you're saving picture isolated storage, save copy lower resolution , display copy in thumbnail. then, when user tap on thumbnail, load full-res picture isolated storage display it.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -