Java 是否正在加载Xamarin中本地保存的图像?
我提出了一种方法,将从CDN获取的位图图像保存到本地存储。查找下面的代码:Java 是否正在加载Xamarin中本地保存的图像?,java,c#,android,xamarin,Java,C#,Android,Xamarin,我提出了一种方法,将从CDN获取的位图图像保存到本地存储。查找下面的代码: /// <summary> /// Method to store the bitmap image fetched from the CDN locally. /// </summary> /// <returns></returns> public bool StoreDownloadedImageLocally(Bitmap i
/// <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;
}
//
///方法存储从CDN本地获取的位图图像。
///
///
public bool StoreDownloadeImage本地(位图图像,字符串扩展名)
{
尝试
{
var directoryPath=绝对路径;
var filePath=System.IO.Path.Combine(directoryPath,扩展名+“.png”);
使用(var stream=newfilestream(filePath,FileMode.Create))
{
image.Compress(Bitmap.CompressFormat.Png,100,流);
}
返回true;
}
捕获(例外)
{
返回false;
}
我现在需要创建一个方法,以便获取刚刚保存的图像。该应用程序需要能够脱机显示图像,从而在下载后将其存储在本地。有什么想法吗
非常感谢。只需使用Bitmapfactory加载即可
string inputPicturePath = "hello.jpg";
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InSampleSize = 4;
Bitmap bitmap = null;
bitmap = BitmapFactory.DecodeFile ( inputPicturePath, options);
只需使用Bitmapfactory加载它
string inputPicturePath = "hello.jpg";
BitmapFactory.Options options = new BitmapFactory.Options ();
options.InSampleSize = 4;
Bitmap bitmap = null;
bitmap = BitmapFactory.DecodeFile ( inputPicturePath, options);
感谢您的回复,尽管我最终使用流读取所有字节。干杯!感谢您的回复,尽管我最终使用流读取所有字节。干杯!