The ImageSource
property of the Button
class is of ImageSource
type, whose value can be set to that of a string representing the path of an image either via assigning the string to the property or using the ImageSource.FromFile()
method. As the ImageSource
type cannot be used with SKBitmap
images, the image represented by the SKBitmap
object can be saved to the disk (preferably in the application cache) and the path to the saved image can be used to initialize the concerned ImageSource
object.
SKBitmap bitmap;
SKImage image = SKImage.FromBitmap(bitmap);
SKData encodedData = image.Encode(SKEncodedImageFormat.Png, 100);
string imagePath = Path.Combine(FileSystem.CacheDirectory, "image.png");
bitmapImageStream = File.Open(imagePath,
FileMode.Create,
FileAccess.Write,
FileShare.None);
encodedData.SaveTo(bitmapImageStream);
bitmapImageStream.Flush(true);
bitmapImageStream.Dispose();
ImageSource imgSrc;
imgSrc = ImageSource.FromFile(imagePath);
// or imgSrc = imagePath;