0
votes

I used this code to get the image file in the localFolder and I encountered the below problem. The problem is at

BitmapImage src is null even there is data in randomstream

any idea how to overcome this problem? Why BitmapImage is null??



string strFilenm = "SDraw-" + prodId.ToString() + ".png";

var folder_path = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Img");

StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(folder_path);

StorageFile storagefile = await folder.GetFileAsync(strFilenm);

StorageFile jpgFile = await folder.GetFileAsync(strFilenm);                


IRandomAccessStream randomStream = await jpgFile.OpenAsync(FileAccessMode.Read);    

randomStream.Seek(0);  

BitmapImage src = new BitmapImage();

await src.SetSourceAsync(randomStream);   

Image1.Source = src;


2

2 Answers

0
votes

I'm not expert but i think to access file from App LocalFolder you should use something like this:

"ms-appx://LocalFolderName/ImageName.extension"

0
votes

try writing the instance " BitmapImage src = new BitmapImage(); " at class level.

One reason can be that the code might be trying to access a file that does'nt exist.