Skia.IO.ImageReader error

Hi I had this error… I’m trying to read an image, resize it and convert it to a byte sequence.

Read file, transform and resize

Transform and Resize
FotoBoothApp-ResizeAndTransformSKImage (Internal)-Transform and Resize

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at SkiaSharp.SkiaApi.sk_image_new_from_bitmap(IntPtr cbitmap)
   at SkiaSharp.SKImage.FromBitmap(SKBitmap bitmap)
   at _VL_Skia_.Graphics.Skia.IO.ImageReader_UC1s8DxbdtUNPDaHW24IK1.Update(Path Filename_In, ReadingMethod Reading_Method_In, Boolean Load_In, SKImage& Output_Out)
   at _SkoobApp_.CreateImageByteStream_N6tLcK1JYrwNafNGSFIxKo.Update(Path Filename_In, Int32 Width_In, Int32 Height_In, Byte[]& Output_Out, Boolean& Has_Changed_Out, SKImage& Sized_Output_Out)
   at _SkoobApp_.UploadProxy_SqsvZRlO45hNlDcPWausPZ.Update(String Url_In, Path Filename_In, Int32 Width_In, Int32 Height_In, Boolean& Uploaded_Out)
   at _SkoobApp_.Uploading_T7KQ76ZJwXzL18EVF2j1L0.Update(Path Input_In, Boolean Send_In)

I äm guessing the image hasn’t all been read when the call is made on the data. This is a pretty low-powered PC so the speed throws up this issue more often but I think it happens on the production machine too.

A couple questions :

  1. Is there a way to confirm that the image has been read entirely?
  2. What do the read methods of the ImageReader do?
  3. Could caching an offscreen renderer mean it may fail to finish creating the new SkiaImage before the frame loop is complete?

Thanks and all the best,


After further probing, the issue seems to be the the image it tries to read hadn’t finished getting written. I found that the target file was 0KB in size, so I’ve added a delay between the file’s creation and the image reading.