I can't exactly pin this one down, but with _some_ images on Android the call to ToBitmap will come back with null. It appears to be failing on the internal call to success = skiaBitmap.CopyPixelsTo(ptr, bmp.Width * bmp.RowBytes);
I'm having the same issue. Seems to be images whose height is greater than their width.
I have identified the problem. I will submit a pull request to fix the issue
Pull request submitted.
https://github.com/mono/SkiaSharp/pull/340
Thanks for the PR. I have merged it in and should be building soon:
https://jenkins.mono-project.com/view/Components/job/Components-SkiaSharp-Windows/
https://jenkins.mono-project.com/view/Components/job/Components-SkiaSharp/
https://jenkins.mono-project.com/view/Components/job/Components-SkiaSharp-Linux/
I don't believe that this issue was resolved with the fix in 1.59.0. If you take a look at the dstSize parameter of SKBitmap.CopyPixelsTo it is not actually referencing or using it at all. With 1.59.0, my Android application now crashes with the following exception.
[mono-rt] at (wrapper managed-to-native) SkiaSharp.SkiaApi.sk_pixmap_read_pixels (intptr,SkiaSharp.SKImageInfo&,intptr,intptr,int,int) <0x00007>
[mono-rt] at SkiaSharp.SKPixmap.ReadPixels (SkiaSharp.SKImageInfo,intptr,int,int,int) [0x00013] in <7398af18bbfa455c8a1e84f1a7eb063a>:0
[mono-rt] at SkiaSharp.SKPixmap.ReadPixels (SkiaSharp.SKImageInfo,intptr,int) [0x00006] in <7398af18bbfa455c8a1e84f1a7eb063a>:0
I am going to see if I can cook up a different solution in the meantime. I will follow-up if I come up with anything useful.
@michaelstonis Thanks for reporting this. This is actually a new issue.
With v1.58, I was able to make use of the native copy function. But, in v1.59, Google removed that function. As a result, I wrote the equivalent function using managed code. Is this process, I added a new method, SKPixmap.ReadPixels. However, this did not get enough testing and I missed the fact that the marshalling was not correct.
The current function is this:
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public extern static bool sk_pixmap_read_pixels(sk_pixmap_t cpixmap, ref SKImageInfo dstInfo, IntPtr dstPixels, IntPtr dstRowBytes, int srcX, int srcY);
This is mostly correct, except for the SKImageInfo type. This should have been the SKImageInfoNative type. I will fix this and get a new version out ASAP.
@mattleibow I really appreciate the quick turnaround. Did this version replace the current release of 1.59 in nuget or will this be a new release?
It will be in a new version. I am just doing a few things and should be out soon.
@michaelstonis I think this is done, but you can test this with this nugget package: https://jenkins.mono-project.com/view/Components/job/Components-SkiaSharp/250/Azure/processDownloadRequest/ArtifactsFor-250/7bfebaa59df9a4b842ceb3dcb9b392d9452eeb62/output/SkiaSharp.1.59.0.1.nupkg
I have made a few other changes as well, so I _may_ bump the version a bit higher to v1.59.1
@michaelstonis I pushed out a release that should have fixed the issue: https://github.com/mono/SkiaSharp/releases/tag/v1.59.1
Thank you @mattleibow. I just gave it a shot and it looks to be working perfectly. Thanks for your help!
Most helpful comment
@michaelstonis Thanks for reporting this. This is actually a new issue.
With v1.58, I was able to make use of the native copy function. But, in v1.59, Google removed that function. As a result, I wrote the equivalent function using managed code. Is this process, I added a new method,
SKPixmap.ReadPixels. However, this did not get enough testing and I missed the fact that the marshalling was not correct.The current function is this:
This is mostly correct, except for the
SKImageInfotype. This should have been theSKImageInfoNativetype. I will fix this and get a new version out ASAP.