GetPixels() 공개 메소드

public GetPixels ( ) : IntPtr
리턴 System.IntPtr
예제 #1
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 = new SKBitmap(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul);

            IntPtr length;
            var pixels = _bitmap.GetPixels(out length);

            // Wrap the bitmap in a Surface and keep it cached
            Surface = SKSurface.Create(_bitmap.Info, pixels, _bitmap.RowBytes);
        }
예제 #2
0
        public static SKBitmap Decode(SKCodec codec, SKImageInfo bitmapInfo)
        {
            if (codec == null)
            {
                throw new ArgumentNullException(nameof(codec));
            }

            // construct a color table for the decode if necessary
            SKColorTable colorTable = null;
            int          colorCount = 0;

            if (bitmapInfo.ColorType == SKColorType.Index8)
            {
                colorTable = new SKColorTable();
            }

            // read the pixels and color table
            var    bitmap = new SKBitmap(bitmapInfo, colorTable);
            IntPtr length;
            var    result = codec.GetPixels(bitmapInfo, bitmap.GetPixels(out length), colorTable, ref colorCount);

            if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput)
            {
                bitmap.Dispose();
                bitmap = null;
            }
            return(bitmap);
        }
예제 #3
0
        public static SKBitmap Decode(SKCodec codec)
        {
            var info = codec.Info;

            // construct a color table for the decode if necessary
            SKColorTable colorTable = null;
            int          colorCount = 0;

            if (info.ColorType == SKColorType.Index8)
            {
                colorTable = new SKColorTable();
            }

            // read the pixels and color table
            var    bitmap = new SKBitmap(info, colorTable);
            IntPtr length;
            var    result = codec.GetPixels(info, bitmap.GetPixels(out length), colorTable, ref colorCount);

            if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput)
            {
                bitmap.Dispose();
                bitmap = null;
            }
            return(bitmap);
        }
예제 #4
0
		public static SKBitmap FromImage (SKImage image)
		{
			if (image == null) {
				throw new ArgumentNullException (nameof (image));
			}

			var info = new SKImageInfo (image.Width, image.Height, SKImageInfo.PlatformColorType, image.AlphaType);
			var bmp = new SKBitmap (info);
			if (!image.ReadPixels (info, bmp.GetPixels (), info.RowBytes, 0, 0)) {
				bmp.Dispose ();
				bmp = null;
			}
			return bmp;
		}
예제 #5
0
        public static SKBitmap Decode(SKCodec codec, SKImageInfo bitmapInfo)
        {
            if (codec == null)
            {
                throw new ArgumentNullException(nameof(codec));
            }

            // read the pixels and color table
            var    bitmap = new SKBitmap(bitmapInfo);
            IntPtr length;
            var    result = codec.GetPixels(bitmapInfo, bitmap.GetPixels(out length));

            if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput)
            {
                bitmap.Dispose();
                bitmap = null;
            }
            return(bitmap);
        }
        public BitmapHelper(string path)
        {
            Bitmap bitmap;

            try
            {
                bitmap = Bitmap.Decode(File.OpenRead(path));
            }
            catch (Exception)
            {
                bitmap = new Bitmap(10, 10);
                for (int i = 0; i < 10; i++)
                {
                    for (int w = 0; w < 10; w++)
                    {
                        bitmap.SetPixel(i, w, SKColors.White);
                    }
                }
            }


            IntPtr ptr   = bitmap.GetPixels();
            int    bytes = Math.Abs(bitmap.RowBytes) * bitmap.Height;

            byte[] rgbValues = new byte[bytes];
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
            colors = new SKColor[bitmap.Width, bitmap.Height];
            for (int counter = 0; counter < rgbValues.Length; counter += 4)
            {
                int i_am = counter / 4;
                colors[i_am % bitmap.Width, i_am / bitmap.Width]
                    =
                        new SKColor(
                            rgbValues[counter + 2],
                            rgbValues[counter + 1],
                            rgbValues[counter + 0],
                            rgbValues[counter + 3]);
            }
            bitmap.Dispose();
        }
예제 #7
0
        public IBitmapImpl LoadBitmap(System.IO.Stream stream)
        {
            using (var s = new SKManagedStream(stream))
            {
                using (var codec = SKCodec.Create(s))
                {
                    var info = codec.Info;
                    var bitmap = new SKBitmap(info.Width, info.Height, SKImageInfo.PlatformColorType, info.IsOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul);

                    IntPtr length;
                    var result = codec.GetPixels(bitmap.Info, bitmap.GetPixels(out length));
                    if (result == SKCodecResult.Success || result == SKCodecResult.IncompleteInput)
                    {
                        return new BitmapImpl(bitmap);
                    }
                    else
                    {
                        throw new ArgumentException("Unable to load bitmap from provided data");
                    }
                }
            }
        }
예제 #8
0
 private static SKSurface CreateSurface(SKBitmap bitmap)
 {
     IntPtr length;
     return SKSurface.Create(bitmap.Info, bitmap.GetPixels(out length), bitmap.RowBytes);
 }
예제 #9
0
		public static SKBitmap Decode (SKCodec codec, SKImageInfo bitmapInfo)
		{
			if (codec == null) {
				throw new ArgumentNullException (nameof (codec));
			}

			// construct a color table for the decode if necessary
			SKColorTable colorTable = null;
			int colorCount = 0;
			if (bitmapInfo.ColorType == SKColorType.Index8)
			{
				colorTable = new SKColorTable ();
			}

			// read the pixels and color table
			var bitmap = new SKBitmap (bitmapInfo, colorTable);
			IntPtr length;
			var result = codec.GetPixels (bitmapInfo, bitmap.GetPixels (out length), colorTable, ref colorCount);
			if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) {
				bitmap.Dispose ();
				bitmap = null;
			}
			return bitmap;
		}
예제 #10
0
        public override void DrawImage(ActualImage actualImage, double x, double y)
        {
            //create Gdi bitmap from actual image
            int w = actualImage.Width;
            int h = actualImage.Height;
            switch (actualImage.PixelFormat)
            {
                case Agg.PixelFormat.ARGB32:
                    {

                        using (SKBitmap newBmp = new SKBitmap(actualImage.Width, actualImage.Height))
                        {
                            newBmp.LockPixels();
                            byte[] actualImgBuffer = ActualImage.GetBuffer(actualImage);
                            System.Runtime.InteropServices.Marshal.Copy(
                            actualImgBuffer,
                            0,
                            newBmp.GetPixels(),
                             actualImgBuffer.Length);
                            newBmp.UnlockPixels();
                        }
                        //newBmp.internalBmp.LockPixels();
                        //byte[] actualImgBuffer = ActualImage.GetBuffer(actualImage);

                        //System.Runtime.InteropServices.Marshal.Copy(
                        //     actualImgBuffer,
                        //     0,
                        //      newBmp.internalBmp.GetPixels(),
                        //      actualImgBuffer.Length);

                        //newBmp.internalBmp.UnlockPixels();
                        //return newBmp;

                        //copy data from acutal buffer to internal representation bitmap
                        //using (MySkBmp bmp = MySkBmp.CopyFrom(actualImage))
                        //{
                        //    _skCanvas.DrawBitmap(bmp.internalBmp, (float)x, (float)y);
                        //}
                    }
                    break;
                case Agg.PixelFormat.RGB24:
                    {
                    }
                    break;
                case Agg.PixelFormat.GrayScale8:
                    {
                    }
                    break;
                default:
                    throw new NotSupportedException();
            }
        }
예제 #11
0
		public static void BitmapDecoder(SKCanvas canvas, int width, int height)
		{
			var assembly = typeof(Demos).GetTypeInfo().Assembly;
			var imageName = assembly.GetName().Name + ".color-wheel.png";

			canvas.Clear(SKColors.White);

			// load the embedded resource stream
			using (var resource = assembly.GetManifestResourceStream(imageName))
			using (var stream = new SKManagedStream(resource))
			using (var codec = SKCodec.Create(stream))
			using (var paint = new SKPaint())
			using (var tf = SKTypeface.FromFamilyName("Arial"))
			{
				var info = codec.Info;

				paint.IsAntialias = true;
				paint.TextSize = 14;
				paint.Typeface = tf;
				paint.Color = SKColors.Black;

				// decode the image
				using (var bitmap = new SKBitmap(info.Width, info.Height, info.ColorType, info.IsOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul))
				{
					IntPtr length;
					var result = codec.GetPixels(bitmap.Info, bitmap.GetPixels(out length));
					if (result == SKCodecResult.Success || result == SKCodecResult.IncompleteInput)
					{
						var x = 25;
						var y = 25;

						canvas.DrawBitmap(bitmap, x, y);
						x += bitmap.Info.Width + 25;
						y += 14;

						canvas.DrawText(string.Format("Result: {0}", result), x, y, paint);
						y += 20;

						canvas.DrawText(string.Format("Size: {0}px x {1}px", bitmap.Width, bitmap.Height), x, y, paint);
						y += 20;

						canvas.DrawText(string.Format("Pixels: {0} @ {1}b/px", bitmap.Pixels.Length, bitmap.BytesPerPixel), x, y, paint);
					}
				}
			}
		}