Forum Libraries, Components, and Plugins

Android bitmap conversion

Hello,
How to convert rapidly ; An Android.Graphics.Bitmap
To a SkiaSharp.SKBitmap
Thx,
cjacquel

Posts

  • mattleibowmattleibow ZAXamarin Team Xamurai

    This is easy to do, you just need to have the SkiaSharp.Views NuGet package installed. Then, there are extension methods:

    skiaBitmap = androidBitmap.ToSKBitmap();
    androidBitmap = skiaBitmap.ToBitmap();
    

    There are also a few others, like: ToSKImage and ToSKPixmap.

    NOTE: these all make copies of the pixel data. To avoid memory issue, you can dispose of the original as soon as the method returns.

  • Chris94Chris94 Member ✭✭

    Hello,
    ToSKBitmap no longer exist in Xamarin, could you help ?
    Thx,
    Christophe

  • HanHan Member

    Below is a sample code how to convert Andriod bitmap Barcode to stream

    using ZXing.Mobile;
    using SkiaSharp.Views;
    using SkiaSharp.Views.Android;

    private SKBitmap convertBarcodeToSKBitmap()
    {
    var barcodeWriter = new ZXing.Mobile.BarcodeWriter
    {
    Format = ZXing.BarcodeFormat.CODE_39,
    Options = new ZXing.Common.EncodingOptions
    {
    Width = 50,
    Height = 50,
    Margin = 5
    }
    };
    var barcode = barcodeWriter.Write("1234567");
    SKBitmap _bitmap = SkiaSharp.Views.Android.AndroidExtensions.ToSKBitmap(barcode);

            return _bitmap;
        }
    
Sign In or Register to comment.