我正尝试将 SKBitmap
图像作为/转换为 ImageSource
对象,以便通过分配给其 ImageSource
属性在 Button
中使用先前提到的图像,但是就我而言,我无法弄清楚如何将 SKBitmap
对象转换为 ImageSource
。
搜索网络只会出现有关将 ImageSource
转换为 SKBitmap
的文章/问题,但没有相反的情况。
提前致谢。
我正尝试将 SKBitmap
图像作为/转换为 ImageSource
对象,以便通过分配给其 ImageSource
属性在 Button
中使用先前提到的图像,但是就我而言,我无法弄清楚如何将 SKBitmap
对象转换为 ImageSource
。
搜索网络只会出现有关将 ImageSource
转换为 SKBitmap
的文章/问题,但没有相反的情况。
提前致谢。
您可以尝试这个:
SKBitmap bitmap = ...;
// create an image COPY
//SKImage image = SKImage.FromBitmap(bitmap);
// OR
// create an image WRAPPER
SKImage image = SKImage.FromPixels(bitmap.PeekPixels());
// encode the image (defaults to PNG)
SKData encoded = image.Encode();
// get a stream over the encoded data
Stream stream = encoded.AsStream();
img.Source = ImageSource.FromStream(()=> stream);
...
using BarcodeStandard;
using SkiaSharp;
using SkiaSharp.Views.WPF;
...
SKImage image = new Barcode().Encode(Type.Code128A, text, width, height);
...
ImageSource imageSource = WPFExtensions.ToWriteableBitmap(image);
...