Exemplo n.º 1
0
        public SKData Encode(SKPixelSerializer serializer)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            return(GetObject <SKData> (SkiaApi.sk_image_encode_with_serializer(Handle, serializer.Handle)));
        }
Exemplo n.º 2
0
        public SKData Encode(SKPixelSerializer serializer)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            // try old data
            var encoded = EncodedData;

            if (encoded != null)
            {
                if (serializer.UseEncodedData(encoded.Data, (ulong)encoded.Size))
                {
                    return(encoded);
                }
                else
                {
                    encoded.Dispose();
                    encoded = null;
                }
            }

            // get new data (raster)
            if (!IsTextureBacked)
            {
                using (var pixmap = PeekPixels()) {
                    return(serializer.Encode(pixmap));
                }
            }

            // get new data (texture / gpu)
            // this involves a copy from gpu to cpu first
            if (IsTextureBacked)
            {
                var info = new SKImageInfo(Width, Height, ColorType, AlphaType, ColorSpace);
                using (var temp = new SKBitmap(info))
                    using (var pixmap = temp.PeekPixels()) {
                        if (pixmap != null && ReadPixels(pixmap, 0, 0))
                        {
                            return(serializer.Encode(pixmap));
                        }
                    }
            }

            // some error
            return(null);
        }