I'm trying to save a image from Bitmap and share it in whatsapp, but, when I save it in my phone and try to open it, the image goes all black, so, when I share it, I share a black image. In other phone that I tested, I could open the saved image, but in this phone that I'm testing, I can't. Both are the same Android version. In this phone that appears a black image, I can see on the preview (gallery) the photo, but, it goes black when I try to open it.
This is my code to save the bitmap:
public SKBitmap SaveImage(float ySize, SKBitmap bmpFormatted, SKBitmap standardBmp, int SKCanvasHeight)
{
float width = (float)screenSize.Width;
bmpFormatted = new SKBitmap((int)width, SKCanvasHeight);
SKRectI rect = new SKRectI(0, 0, (int)width, (int)ySize);
standardBmp.ExtractSubset(bmpFormatted, rect);
SKData data = bmpFormatted.Encode(SKEncodedImageFormat.Png, 100);
byte[] bmpByte = data.ToArray();
string directory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
string path = Path.Combine(directory, "bmpSaved.png");
File.WriteAllBytes(path, bmpByte);
return bmpFormatted;
}
And this is my code to share the saved bitmap:
string directory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
string path = Path.Combine(directory, "bmpSaved.png");
var _context = Android.App.Application.Context;
Intent sendIntent = new Intent(global::Android.Content.Intent.ActionSend);
sendIntent.PutExtra(global::Android.Content.Intent.ExtraText, "Whatsapp");
sendIntent.SetType("image/*");
sendIntent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse("file://" + path));
_context.StartActivity(Intent.CreateChooser(sendIntent, "Share"));
return Task.FromResult(0);
Is there any kind of difference or another way to do it? Because I need to it works in both phones. Any ideas?