I am saving image into isolated storage each image have a different imageFileName. But i am having problem to retrieve all the saved image in a listbox. Only managed to retrieve the latest image saved. When i hard code the filepath then can retrieve it. I hope anyoen can help me with the code.. Hopefully anyone can try editing my code. Thanks.
Save code:
private void SaveToLocalStorage(string imageFolder, string imageFileName)
{
imageFileName = App.imagePath;
var isf = IsolatedStorageFile.GetUserStoreForApplication();
if (!isf.DirectoryExists(imageFolder))
{
isf.CreateDirectory(imageFolder);
}
string filePath = Path.Combine(imageFolder, imageFileName);
using (var stream = isf.CreateFile(filePath))
{
var bmp = new WriteableBitmap(inkCanvas, inkCanvas.RenderTransform);
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
}
MessageBox.Show(filePath }
Retrieve code:
private void LoadFromLocalStorage(string imageFolder, string imageFileName )
{
var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
if (!isoFile.DirectoryExists(imageFolder))
{
isoFile.CreateDirectory(imageFolder);
}
string filePath = Path.Combine(imageFolder, imageFileName);
using (var imageStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
{
var imageSource = PictureDecoder.DecodeJpeg(imageStream);
BitmapImage bi = new BitmapImage();
ListBoxItem item = new ListBoxItem();
bi.SetSource(imageStream);
item.Content = new Image() { Source = bi, MaxHeight = 100, MaxWidth = 100 };
listBox1.Items.Add(item);
}
}