转换Android.Graphics.Bitmap到图像 [英] Convert Android.Graphics.Bitmap to Image
本文介绍了转换Android.Graphics.Bitmap到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得的视图的屏幕截图如下。我得到位图,我需要将其转换为到图像添加到PDF生成。
使用(VAR截图= Bitmap.CreateBitmap(200,100,Bitmap.Config.Argb8888))
{
VAR帆布=新的Canvas(截图);
rootView.Draw(画布); 使用(VAR screenshotOutputStream =新的FileStream(screenshotPath,System.IO.FileMode.Create))
{
screenshot.Com preSS(Android.Graphics.Bitmap.Com pressFormat.Png,90,screenshotOutputStream);
screenshotOutputStream.Flush();
screenshotOutputStream.Close();
}
}
我的问题是如何转换 Android.Graphics.Bitmap - >屏幕截图
到图片
我要替换图像本身它来自位图的网址。
字符串图片网址=myURL;
形象画像= Image.GetInstance(新的URI(图片网址));
document.Add(图片);
解决方案
您可以使用此方法:
公共位图getScreenshotBmp(){
FileOutputStream中的FileOutputStream = NULL; 文件路径=环境
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 字符串UNIQUEID = UUID.randomUUID()的toString()。 档案文件=新的文件(路径,唯一ID +.JPG);
尝试{
的FileOutputStream =新的FileOutputStream(文件);
}赶上(FileNotFoundException异常五){
e.printStackTrace();
} screenshot.com preSS(Bitmap.Com pressFormat.JPEG,30,FileOutputStream中); 尝试{
fileOutputStream.flush();
fileOutputStream.close();
}赶上(IOException异常五){
e.printStackTrace();
}
返回截图;
}
I am trying to get screenshot of the view as follows. I am getting Bitmap and I need to convert it to to Image to add into PDF generator.
using (var screenshot = Bitmap.CreateBitmap(200, 100,Bitmap.Config.Argb8888))
{
var canvas = new Canvas(screenshot);
rootView.Draw(canvas);
using (var screenshotOutputStream = new FileStream(screenshotPath,System.IO.FileMode.Create))
{
screenshot.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 90, screenshotOutputStream);
screenshotOutputStream.Flush();
screenshotOutputStream.Close();
}
}
My question is how to convert Android.Graphics.Bitmap -->screenshot
to Image
?
I want to replace the url with Image itself which comes from BitMap.
String imageUrl = "myURL";
Image image = Image.GetInstance (new Uri (imageUrl));
document.Add(image);
解决方案
You can use this method:
public Bitmap getScreenshotBmp() {
FileOutputStream fileOutputStream = null;
File path = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String uniqueID = UUID.randomUUID().toString();
File file = new File(path, uniqueID + ".jpg");
try {
fileOutputStream = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
screenshot.compress(Bitmap.CompressFormat.JPEG, 30, fileOutputStream);
try {
fileOutputStream.flush();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return screenshot;
}
这篇关于转换Android.Graphics.Bitmap到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文