예제 #1
0
        public RawBitmap Snip(RawBitmap bitmap, Rectangle rect)
        {
            var target = new RawBitmap(rect.Width, rect.Height);

            using (var sourceAdapter = _gdiFactory.CreateAdapter(bitmap))
                using (var targetAdapter = _gdiFactory.CreateAdapter(target))
                    using (var targetGraphics = _gdiFactory.CreateGraphics(targetAdapter.Bitmap))
                    {
                        targetGraphics.DrawImage(
                            sourceAdapter.Bitmap,
                            new Rectangle(0, 0, rect.Width, rect.Height),
                            rect,
                            GraphicsUnit.Pixel);
                    }

            return(target);
        }
예제 #2
0
        public void Write(Stream stream, IRawBitmap rawBitmap)
        {
            if (!(rawBitmap is RawBitmap rawBitmapImpl))
            {
                throw new Exception("Can only work with implementations of RawBitmap for now..");
            }

            using (var adapter = _gdiFactory.CreateAdapter(rawBitmapImpl))
                using (var output = _gdiFactory.CreateBitmap(rawBitmap.Width, rawBitmap.Height))
                    using (var g = _gdiFactory.CreateGraphics(output))
                    {
                        g.DrawImage(adapter.Bitmap, 0, 0);
                        output.Save(stream, ImageFormat.Png);
                    }
        }
예제 #3
0
        public RawBitmap Read(Stream stream)
        {
            using (var source = new Bitmap(stream))
            {
                var result = new RawBitmap
                {
                    Width  = source.Width,
                    Height = source.Height,
                    Data   = new int[source.Width * source.Height]
                };

                using (var adapter = _gdiFactory.CreateAdapter(result))
                    using (var g = _gdiFactory.CreateGraphics(adapter.Bitmap))
                    {
                        g.DrawImage(source, 0, 0);
                    }

                return(result);
            }
        }