예제 #1
0
파일: Form1.cs 프로젝트: mitice/foo
        private void menuItem2_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("time1: " + DateTime.Now, ToString());
            Rotate rotateFilter = new Rotate(-15, AForge.Imaging.InterpolationMethod.Bicubic, true);

            //rotateFilter.KeepSize = true;
            Debug.WriteLine("time2: " + DateTime.Now, ToString());
            pictureBox1.Image = rotateFilter.Apply(new Bitmap(pictureBox1.Image));
            Debug.WriteLine("time3: " + DateTime.Now, ToString());
            pictureBox1.Refresh();
            Debug.WriteLine("time4: " + DateTime.Now, ToString());
        }
예제 #2
0
        private void ResizeAndPrintImage(System.Drawing.Graphics graphics, bool rotateImage, Size dstSize, Point leftTopPosition)
        {
            Size   printImageSize;
            Bitmap printImage;
            bool   disposePrintImage = false;

            // Preparing source image for printing
            if (rotateImage)
            {
                printImage = new Bitmap();

                Rotate rotate = new Rotate(90);
                printImage        = rotate.Apply(_image);
                disposePrintImage = true;

                printImageSize        = new Size();
                printImageSize.Width  = _actualImageSize.Height;
                printImageSize.Height = _actualImageSize.Width;
            }
            else
            {
                printImage     = _image;
                printImageSize = _actualImageSize;
            }

            // Calculating resize params, crop rectangles and correcting output position
            Size resizeSize = CalculateImageSizeForPrint(printImageSize, dstSize);

            leftTopPosition.X += Math.Max(0, (dstSize.Width - resizeSize.Width) / 2);
            leftTopPosition.Y += Math.Max(0, (dstSize.Height - resizeSize.Height) / 2);

            Rectangle cropRect = new Rectangle(0, 0, Math.Min(dstSize.Width, resizeSize.Width), Math.Min(dstSize.Height, resizeSize.Height));

            cropRect.X = Math.Max(0, (resizeSize.Width - dstSize.Width) / 2);
            cropRect.Y = Math.Max(0, (resizeSize.Height - dstSize.Height) / 2);

            // Printing
            if (resizeSize.Height > 0 && resizeSize.Width > 0)
            {
                StripPrint(printImage, graphics, leftTopPosition, resizeSize, cropRect);
            }

            // CleanUp
            if (disposePrintImage)
            {
                printImage.Dispose();
            }
        }
예제 #3
0
 public void OnRotate(Rotate rotate)
 {
     rotate.Apply(world);
 }
예제 #4
0
        private void CropAndPrintImage(System.Drawing.Graphics graphics, bool rotateImage, Size dstSize, Point leftTopPosition)
        {
            // Rotating source image if needed (if RotationAllowed == true && aspect ratio of rotated on 90
            // degree image is better for placing into specified sizes).
            Bitmap printImage;
            bool   disposePrintImage = false;
            Size   imageSize         = new Size();

            if (rotateImage)
            {
                printImage = new Bitmap();

                Rotate rotate = new Rotate(90);
                printImage        = rotate.Apply(_image);
                disposePrintImage = true;

                imageSize.Width  = _actualImageSize.Height;
                imageSize.Height = _actualImageSize.Width;
            }
            else
            {
                printImage = _image;
                imageSize  = _actualImageSize;
            }

            // Correcting crop rectangle - if DstSize is greater than ImageSize -
            // no need to crop => DstSize should be equal to ImageSize.
            if ((dstSize.Width >= imageSize.Width && dstSize.Height > imageSize.Height) ||
                (dstSize.Width > imageSize.Width && dstSize.Height >= imageSize.Height))
            {
                leftTopPosition.X += (int)Math.Round((float)(dstSize.Width - imageSize.Width) / 2.0f);
                leftTopPosition.Y += (int)Math.Round((float)(dstSize.Height - imageSize.Height) / 2.0f);

                dstSize = imageSize;
            }

            // Calculating crop parameters, correcting output coordinates
            int cropX      = (int)Math.Round((float)(imageSize.Width - dstSize.Width) / 2.0),
                cropY      = (int)Math.Round((float)(imageSize.Height - dstSize.Height) / 2.0),
                cropWidth  = Math.Min(dstSize.Width, imageSize.Width),
                cropHeight = Math.Min(dstSize.Height, imageSize.Height);

            if (cropX < 0)
            {
                cropX = 0;
            }

            if (cropY < 0)
            {
                cropY = 0;
            }

            if (imageSize.Width < dstSize.Width)
            {
                leftTopPosition.X += (int)Math.Round((float)(dstSize.Width - imageSize.Width) / 2);
            }

            if (imageSize.Height < dstSize.Height)
            {
                leftTopPosition.Y += (int)Math.Round((float)(dstSize.Height - imageSize.Height) / 2);
            }

            // Calling StripPrint() for real printing.
            if (cropWidth > 0 && cropHeight > 0)
            {
                StripPrint(printImage, graphics, leftTopPosition, imageSize, new Rectangle(cropX, cropY, cropWidth, cropHeight));
            }

            // Cleanup
            if (disposePrintImage)
            {
                printImage.Dispose();
            }
        }
예제 #5
0
        /// <summary>
        /// Se realiza:
        /// <para>1. Se posiciona la marca de agua de acuerdo a los <see cref="TissotIndicatrix"/> (Top, Bottom y del 1 - 8)</para>
        /// <para>2. Se realiza la deformación <see cref="Fisheye.Convert(FisheyeBitmap)"/></para>
        /// <para>3. Se realiza la deformación <see cref="Fisheye.ToLandscape(FisheyeBitmap)"/></para>
        /// <para>4. Se posiciona la marca de agua de acuerdo a los <see cref="TissotIndicatrix"/> de la posición del centro (9 - 12)</para>
        /// </summary>
        public void Prepare()
        {
            int            size = 0;
            AbstractBitmap img  = null;

            foreach (var indicatrix in _indicatrixes.Where(i => i.Position != Position.Center))
            {
                // Se conserva la relacion aspecto de acuerdo al ancho de la imagen

                if (_imageWatermark.Width > _imageWatermark.Height)
                {
                    size = (indicatrix.MaxWidth * _imageWatermark.Height) / _imageWatermark.Width;

                    img = Resize.Apply(_imageWatermark, indicatrix.MaxWidth, size);
                }
                else
                {
                    size = (indicatrix.MaxHeight * _imageWatermark.Width) / _imageWatermark.Height;

                    img = Resize.Apply(_imageWatermark, size, indicatrix.MaxHeight);
                }

                img = Rotate.Apply(img, indicatrix.Angle);

                var posX = indicatrix.X - (img.Width / 2);
                var posY = indicatrix.Y - (img.Height / 2);

                if (indicatrix.Position == Position.Top)
                {
                    this._topFisheye.InsertImageUnmanaged(img, posX, posY);
                }
                else
                {
                    img._image.RotateFlip(RotateFlipType.RotateNoneFlipXY);

                    this._bottomFisheye.InsertImageUnmanaged(img, posX, posY);
                }
            }

            // Se realiza la deformación fisheye

            var feTop    = Fisheye.Convert(this._topFisheye);
            var feBottom = Fisheye.Convert(this._bottomFisheye);

            // Se deforman los fisheye a landscape

            feBottom = Fisheye.ToLandscape(feBottom);

            feTop = Fisheye.ToLandscape(feTop);
            feTop._image.RotateFlip(RotateFlipType.RotateNoneFlipXY);

            // Se insertan en el bitmap "watermak"

            _waterMark.InsertImageUnmanaged(feTop, 0, 0);
            _waterMark.InsertImageUnmanaged(feBottom, 0, feBottom.Height);

            // Se insertan aquellos indicatrix que pertenezcan al centro de la imagen

            foreach (var indicatrix in _indicatrixes.Where(i => i.Position == Position.Center))
            {
                if (_imageWatermark.Width > _imageWatermark.Height)
                {
                    size = (indicatrix.MaxWidth * _imageWatermark.Height) / _imageWatermark.Width;

                    img = Resize.Apply(_imageWatermark, indicatrix.MaxWidth, size) as WatermarkBitmap;
                }
                else
                {
                    size = (indicatrix.MaxHeight * _imageWatermark.Width) / _imageWatermark.Height;

                    img = Resize.Apply(_imageWatermark, size, indicatrix.MaxHeight) as WatermarkBitmap;
                }

                _waterMark.InsertImageUnmanaged(img, indicatrix.X - img.Width / 2, indicatrix.Y - img.Height / 2);
            }

            //_waterMark.Save(@"C:\Users\Euler\Pictures\WMpreared2.png", ImageFormat.Png);
        }