Пример #1
0
        private static void _PerformCopy(SpanBitmap src, ANDROIDBITMAP dst)
        {
            if (src.Info.IsEmpty)
            {
                return;
            }
            if (dst == null)
            {
                return;
            }

            if (dst.IsRecycled || !dst.IsMutable)
            {
                throw new ArgumentNullException(nameof(dst));
            }

            if (!TryGetBitmapInfo(dst.GetBitmapInfo(), dst.IsPremultiplied, out var nfo))
            {
                throw new Diagnostics.PixelFormatNotSupportedException((dst.GetBitmapInfo().Format, dst.Premultiplied), nameof(dst));
            }

            var ptr = dst.LockPixels();

            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentNullException("lock", nameof(dst));
            }

            try { new PointerBitmap(ptr, nfo).AsSpanBitmap().SetPixels(0, 0, src); }
            finally { dst.UnlockPixels(); }
        }
Пример #2
0
        /// <summary>
        /// Copies the pixel data to bitmap, data assumed to be in ARGB format so it will be trasformed to the internal Android ABGR format that bitmaps use while copying.
        /// </summary>
        /// <param name="targetBitmap">The target bitmap.</param>
        /// <param name="data">The data.</param>
        /// <param name="stride">The stride, bitmap width in pixels.</param>
        public static void CopyPixelDataToBitmap(Bitmap targetBitmap, int[] data, int stride)
        {
            if (targetBitmap != null)
            {
                IntPtr ptr = targetBitmap.LockPixels();

                unchecked
                {
                    int value;

                    int[] strideArray = new int[stride];

                    for (int i = 0; i < data.Length; i += stride)
                    {
                        for (int j = 0, k = i; j < stride; ++j, ++k)
                        {
                            value = data[k];

                            strideArray[j] =
                                (int)
                                ((0xFF000000) | ((value & 0xFF) << 16) | (value & 0x0000FF00) | ((value >> 16) & 0xFF));
                        }

                        Marshal.Copy(strideArray, 0, ptr + (i << 2), stride);
                    }
                }
                targetBitmap.UnlockPixels();
            }
        }
        private SkiaSharp.SKSurface CreateSurface(out SkiaSharp.SKImageInfo info)
        {
            // get context details
            info = this.info;

            // if there are no pixels, clean up and return
            if (info.Width == 0 || info.Height == 0)
            {
                Dispose();
                return(null);
            }

            // if the memory size has changed, then reset the underlying memory
            if (bitmap?.Handle == IntPtr.Zero || bitmap?.Width != info.Width || bitmap?.Height != info.Height)
            {
                FreeBitmap();
            }

            // create the bitmap data if we need it
            if (bitmap == null)
            {
                bitmap = ABitmap.CreateBitmap(info.Width, info.Height, ABitmap.Config.Argb8888);
            }

            return(SkiaSharp.SKSurface.Create(info, bitmap.LockPixels(), info.RowBytes));
        }
Пример #4
0
        public static bool CopyTo(ANDROIDBITMAP src, ref MemoryBitmap dst)
        {
            var info = src.GetBitmapInfo().ToInterop();

            var ptr = src.LockPixels();

            try { return(new PointerBitmap(ptr, info).CopyTo(ref dst)); }
            finally { src.UnlockPixels(); }
        }
Пример #5
0
		public FastBitmap(Bitmap bitmap, bool cleanSlate = false)
		{
			int byteCount = bitmap.Width * bitmap.Height * bpp;

			_bytes  = new byte[byteCount];
			_bitmap = bitmap;

			_scan0 = bitmap.LockPixels();

			if (!cleanSlate)
				Marshal.Copy(_scan0, _bytes, 0, byteCount);
		}
Пример #6
0
        public static void Mutate(ANDROIDBITMAP bmp, Action <PointerBitmap> pinContext)
        {
            System.Diagnostics.Debug.Assert(bmp != null);

            if (!TryGetBitmapInfo(bmp.GetBitmapInfo(), bmp.IsPremultiplied, out var info))
            {
                throw new Diagnostics.PixelFormatNotSupportedException(bmp.GetBitmapInfo(), nameof(bmp));
            }

            if (info.BitmapByteSize != bmp.ByteCount)
            {
                throw new InvalidOperationException("Byte Size mismatch");
            }

            var ptr = bmp.LockPixels();

            try { pinContext(new PointerBitmap(ptr, info, !bmp.IsMutable)); }
            finally { bmp.UnlockPixels(); }
        }
Пример #7
0
        private void FixSize()
        {
            int width, height;
            GetPlatformWindowSize(out width, out height);
            if (Width == width && Height == height)
                return;

            Width = width;
            Height = height;

            if (Surface != null)
            {
                Surface.Dispose();
            }

            if (_bitmap != null)
            {
                _bitmap.Dispose();
            }

            _bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
            Surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, _bitmap.LockPixels(), width * 4);
        }