You should clarify your question, but I suppose Path
is the location of your image in isolated storage. Providing that Image
is the name of your Image in xaml
img.Source = GetImage(LoadIfExists(image.Path));
LoadIfExists
returns the binary data for a file in Isolated Storage, and GetImage returns it as a WriteableBitmap
:
public static WriteableBitmap GetImage(byte[] buffer)
{
int width = buffer[0] * 256 + buffer[1];
int height = buffer[2] * 256 + buffer[3];
long matrixSize = width * height;
WriteableBitmap retVal = new WriteableBitmap(width, height);
int bufferPos = 4;
for (int matrixPos = 0; matrixPos < matrixSize; matrixPos++)
{
int pixel = buffer[bufferPos++];
pixel = pixel << 8 | buffer[bufferPos++];
pixel = pixel << 8 | buffer[bufferPos++];
pixel = pixel << 8 | buffer[bufferPos++];
retVal.Pixels[matrixPos] = pixel;
}
return retVal;
}
public static byte[] LoadIfExists(string fileName)
{
byte[] retVal;
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
if (iso.FileExists(fileName))
{
using (IsolatedStorageFileStream stream = iso.OpenFile(fileName, FileMode.Open))
{
retVal = new byte[stream.Length];
stream.Read(retVal, 0, retVal.Length);
}
}
else
{
retVal = new byte[0];
}
}
return retVal;
}
If you want to write the image into the Picture Library, it's basically the same process, ending by calling SavePictureToCameraRoll()
of MediaLibrary
as explained on this MSDN Article