wp7に画像アプリがあります。
class Images
{
public string Title {get;set;}
public string Path {get;set;}
}
ページレベルでは、タイトルとパス(アプリに対して)をリストにバインドします。
私が必要としているのは、ユーザーがリストアイテムをクリックすると、WindowsPhone7の画像ギャラリーでそれぞれの画像が開きます。
wp7に画像アプリがあります。
class Images
{
public string Title {get;set;}
public string Path {get;set;}
}
ページレベルでは、タイトルとパス(アプリに対して)をリストにバインドします。
私が必要としているのは、ユーザーがリストアイテムをクリックすると、WindowsPhone7の画像ギャラリーでそれぞれの画像が開きます。
質問を明確にする必要がPath
ありますが、分離されたストレージ内の画像の場所だと思います。Image
それがxamlでの画像の名前であることを提供する
img.Source = GetImage(LoadIfExists(image.Path));
LoadIfExists
分離ストレージ内のファイルのバイナリデータを返し、GetImageはそれを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;
}
画像を画像ライブラリに書き込みたい場合は、基本的に同じプロセスであり、このMSDN記事で説明されているようにを呼び出すことSavePictureToCameraRoll()
で終了します。MediaLibrary