转换Android.Graphics.Bitmap到图像

编程入门 行业动态 更新时间:2024-10-27 07:27:15
本文介绍了转换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 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(); } screenshotpress(Bitmap.CompressFormat.JPEG, 30, fileOutputStream); try { fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } return screenshot; }

更多推荐

转换Android.Graphics.Bitmap到图像

本文发布于:2023-07-26 19:06:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Android   Graphics   Bitmap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!