我已经制定了一种方法,可以将从CDN中获取的位图图像保存到本地存储中。在下面找到代码:
/// <summary>
/// Method to store the bitmap image fetched from the CDN locally.
/// </summary>
/// <returns></returns>
public bool StoreDownloadedImageLocally(Bitmap image, string extension)
{
try
{
var directoryPath = absolutePath;
var filePath = System.IO.Path.Combine(directoryPath, extension + ".png");
using (var stream = new FileStream(filePath, FileMode.Create))
{
image.Compress(Bitmap.CompressFormat.Png, 100, stream);
}
return true;
}
catch (Exception)
{
return false;
}
我现在需要创建一个方法,以便可以获取刚刚保存的图像。该应用需要能够离线显示图像,因此一旦下载就将其存储在本地。有什么想法吗?
非常感谢。
答案 0 :(得分:4)
只需使用Bitmapfactory加载它
string inputPicturePath = "hello.jpg";
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InSampleSize = 4;
Bitmap bitmap = null;
bitmap = BitmapFactory.DecodeFile ( inputPicturePath, options);