c# - Weird behavior of image -


i see weird behavior of image.

i have 2 methods wich calculate heatmap image. 1 method works in gui thread, , other 1 in background thread. both methods should same , output png seems good. gui thread created image able loaded in, created 1 background thread not.

i save calculated image file on hard drive , load in again. when load , assign image source not null. when programm leaves allocating method image.source null. don't understand why.

this code:

private void loadimageclicked(object sender, routedeventargs e) {     this.imageheatmap.begininit();     this.imageheatmap.source = new bitmapimage(new uri(@"heatmapimage.png", urikind.relative));     this.imageheatmap.endinit(); } 

and how save image png:

public void savefile(bitmapsource source, string filepath) {     using (var filestream = new filestream(filepath, filemode.create))     {         bitmapencoder encoder = new pngbitmapencoder();         encoder.frames.add(bitmapframe.create(source));         encoder.save(filestream);     } } 

interesting can not view image.source.height property in debug mode. working file able read property. debug looks this:

debug of image.source assignment

error message in english (free translated): "this.image:heatmap.source.height" has thrown exception of type "system.io.ioexception"

is able me understanding problem? because don't understand why can't load image. able open via windows picture viewer.

i think problem metadata don't know - @ moment - how fix it.

when comes images objects in .net have found need force disposed. using .dispose() method of class manipulates image enough release it's hold on file. think closing stream force release not.

edit: it's pretty lousy of down vote because didn't understand response. thought deleting response don't think in community's benefit. here related post explains saying further.

why image.fromfile keep file handle open sometimes?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -