I stack on the line bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream); and I do not know how to continue. The following is my code:
Bitmap bitmap = tv.GetDrawingCache(true);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
Java.IO.File ExternalStorageDirectory = Android.OS.Environment.ExternalStorageDirectory;
Java.IO.File file = new Java.IO.File(ExternalStorageDirectory + Java.IO.File.Separator + "Receipt");
Java.IO.FileOutputStream fileOutputStream = null;
file.CreateNewFile();
fileOutputStream = new Java.IO.FileOutputStream(file);
fileOutputStream.Write(stream.ToArray());
Xamarin - Save bitmap image into resource
Here is a simple demo:
void ExportBitmapAsPNG(Bitmap bitmap)
{
var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filePath = System.IO.Path.Combine(sdCardPath, "test.png");
var stream = new FileStream(filePath, FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.