【发布时间】:2014-09-22 14:01:55
【问题描述】:
我正在尝试将位图图像保存到手机内的目录(图库)中。该应用程序是在 Xamarin 中开发的,因此代码是 C#。
我似乎不知道如何创建目录并保存位图。有什么建议吗?
public void createBitmap(View view){
view.DrawingCacheEnabled = true;
view.BuildDrawingCache (true);
Bitmap m_Bitmap = view.GetDrawingCache(true);
String storagePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
Java.IO.File storageDirectory = new Java.IO.File(storagePath);
//storageDirectory.mkdirs ();
//save the bitmap
//MemoryStream stream = new MemoryStream ();
//m_Bitmap.Compress (Bitmap.CompressFormat.Png, 100, stream);
//stream.Close();
try{
String filePath = storageDirectory.ToString() + "APPNAME.png";
FileOutputStream fos = new FileOutputStream (filePath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
m_Bitmap.Compress (Bitmap.CompressFormat.Png, 100, bos);
bos.Flush();
bos.Close();
} catch (Java.IO.FileNotFoundException e) {
System.Console.WriteLine ("FILENOTFOUND");
} catch (Java.IO.IOException e) {
System.Console.WriteLine ("IOEXCEPTION");
}
【问题讨论】:
标签: c# android bitmap xamarin xamarin.android