Eth*_*len 2 .net c# silverlight visual-studio windows-phone-7
我希望创建一个函数,在一个BitmapImage独立存储中的本地Windows Phone 7设备上将其作为JPEG保存并保存:
static public void saveImageLocally(string barcode, BitmapImage anImage)
{
// save anImage as a JPEG on the device here
}
Run Code Online (Sandbox Code Playgroud)
我该如何做到这一点?我假设我用了IsolatedStorageFile某种方式?
谢谢.
编辑:
以下是我到目前为止发现的内容......任何人都可以确认这是否是正确的方法吗?
static public void saveImageLocally(string barcode, BitmapImage anImage)
{
WriteableBitmap wb = new WriteableBitmap(anImage);
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fs = isf.CreateFile(barcode + ".jpg"))
{
wb.SaveJpeg(fs, wb.PixelWidth, wb.PixelHeight, 0, 100);
}
}
}
static public void deleteImageLocally(string barcode)
{
using (IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication())
{
MyStore.DeleteFile(barcode + ".jpg");
}
}
static public BitmapImage getImageWithBarcode(string barcode)
{
BitmapImage bi = new BitmapImage();
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var fs = isf.OpenFile(barcode + ".jpg", FileMode.Open))
{
bi.SetSource(fs);
}
}
return bi;
}
Run Code Online (Sandbox Code Playgroud)
要保存它:
var bmp = new WriteableBitmap(bitmapImage);
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = storage.CreateFile(@"MyFolder\file.jpg"))
{
bmp.SaveJpeg(stream, 200, 100, 0, 95);
stream.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
是的,您在编辑中添加的内容正是我之前所做的:)它的工作原理.
| 归档时间: |
|
| 查看次数: |
8897 次 |
| 最近记录: |