将Android.Graphics.Bitmap转换为图像

将Android.Graphics.Bitmap转换为图像,android,bitmap,xamarin,Android,Bitmap,Xamarin,我正试图获得如下视图的屏幕截图。我得到位图,我需要将其转换为图像添加到PDF生成器 using (var screenshot = Bitmap.CreateBitmap(200, 100,Bitmap.Config.Argb8888)) { var canvas = new Canvas(screenshot); rootView.Draw(canvas); using (var screenshotOutputStream = new FileStream(scre

我正试图获得如下视图的屏幕截图。我得到位图,我需要将其转换为图像添加到PDF生成器

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();
    }
}
我的问题是如何将
Android.Graphics.Bitmap-->屏幕截图
转换为
图像

我想用来自位图的图像本身替换url

String imageUrl = "myURL";
Image image = Image.GetInstance (new Uri (imageUrl));
document.Add(image);

您可以使用以下方法:

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;
 }

嗨,Udi,在我看来它仍然是位图?我没有在代码中看到
图像
转换?我遗漏了什么吗?假设这一行这样做:screenshot.compress(Bitmap.CompressFormat.JPEG,30,fileOutputStream);
screenshot
来自哪里?屏幕截图类型?问题有“xamarin”标签,为什么是Java?!Xamarin Android不支持System.Drawing.Image。请查看我的三行代码(刚刚添加到我的问题中),它们在
Xamarin.Android
中工作。您是否有任何建议获取视图的屏幕截图并将其分配给图像以生成pdf。这是一个Android.Media.Image。抱歉,我误解了您的提问。什么是MemoryStream&Image.FromArray(..)
android.media.Image
没有
.FromArray()
Bitmap bm = BitmapFactory.DecodeFile (path);
MemoryStream stream = new MemoryStream ();
bm.Compress (Bitmap.CompressFormat.Jpeg, 100, stream);
Image img = Image.FromArray (stream.ToArray());