Пример #1
0
        public void Resize(Bitmap src, Bitmap dst, object options = null)
        {
            var scaleX = (double)dst.Width / src.Width;
            var scaleY = (double)dst.Height / src.Height;
            var scale  = Math.Max(scaleX, scaleY);

            if (Math.Abs(scaleX - 2) < 0.0001 && Math.Abs(scaleY - 2) < 0.0001)
            {
                doubler.Double(src, dst);
                return;
            }
            if (Math.Abs(scaleX - 4) < 0.0001 && Math.Abs(scaleY - 4) < 0.0001)
            {
                Four(src, dst);
                return;
            }

            if (scale > 2)
            {
                var temp       = new byte[src.Width * src.Height * src.Channel * src.Depth << 1];
                var handle     = GCHandle.Alloc(temp, GCHandleType.Pinned);
                var tempBitmap = new Bitmap(handle.AddrOfPinnedObject(),
                                            4 * src.Width * src.Channel * (src.Depth >> 3),
                                            4 * src.Width, 4 * src.Height, src.Depth, src.Channel);
                Four(src, tempBitmap);
                resizer.Resize(tempBitmap, dst);
                handle.Free();
                return;
            }

            if (scale > 1)
            {
                var temp       = new byte[src.Width * src.Height * src.Channel * src.Depth >> 1];
                var handle     = GCHandle.Alloc(temp, GCHandleType.Pinned);
                var tempBitmap = new Bitmap(handle.AddrOfPinnedObject(),
                                            2 * src.Width * src.Channel * (src.Depth >> 3),
                                            2 * src.Width, 2 * src.Height, src.Depth, src.Channel);
                doubler.Double(src, tempBitmap);
                resizer.Resize(tempBitmap, dst);
                handle.Free();
                return;
            }

            resizer.Resize(src, dst);
        }
Пример #2
0
        public BitmapSource GetPartial(IResizer resizer, Int32Rect pos, double scale)
        {
            var src    = source.GetBitmap(pos);
            var result = Misc.AllocWriteableBitmap(
                (int)(pos.Width * scale), (int)(pos.Height * scale), src.Depth, src.Channel);

            result.Lock();

            var dst = Misc.BitmapOfWritableBitmap(result);

            resizer.Resize(src, dst);

            result.AddDirtyRect(new Int32Rect(0, 0, result.PixelWidth, result.PixelHeight));
            result.Unlock();

            result.Freeze();
            return(result);
        }
Пример #3
0
 public void Resize(Bitmap src, Bitmap dst, object options = null)
 {
     resizer.Resize(src, dst, option);
 }