private Aurigma.GraphicsMill.Bitmap CreatePreviewBitmap(Aurigma.GraphicsMill.Bitmap sourceBitmap, Aurigma.GraphicsMill.Transforms.ResizeMode resizeMode)
        {
            var bitmap = new Aurigma.GraphicsMill.Bitmap();

            using (var resize = new Aurigma.GraphicsMill.Transforms.Resize(new System.Drawing.Size((int)_frame.ImageSize.Width, (int)_frame.ImageSize.Height)))
            {
                resize.ResizeMode = resizeMode;
                resize.ApplyTransform(sourceBitmap, bitmap);
            }
            return(bitmap);
        }
Esempio n. 2
0
        private System.Drawing.Bitmap CreateDrawnImage()
        {
            var converter = new Aurigma.GraphicsMill.Transforms.ColorConverter();

            Aurigma.GraphicsMill.Bitmap interimImage = null;
            System.Drawing.Bitmap       result       = null;

            System.IntPtr dc          = NativeMethods.GetDC(System.IntPtr.Zero);
            float         monitorResX = NativeMethods.GetDeviceCaps(dc, NativeMethods.LOGPIXELSX);
            float         monitorResY = NativeMethods.GetDeviceCaps(dc, NativeMethods.LOGPIXELSY);

            NativeMethods.ReleaseDC(System.IntPtr.Zero, dc);

            float scaleX, scaleY;

            if (_scaleToActualSize)
            {
                float resX = _image.DpiX;
                float resY = _image.DpiY;

                scaleX = resX > VObject.Eps ? monitorResX / resX : 1.0f;
                scaleY = resY > VObject.Eps ? monitorResY / resY : 1.0f;
            }
            else
            {
                scaleX = 1.0f;
                scaleY = 1.0f;
            }
            bool performScale = System.Math.Abs(scaleX - 1.0f) > VObject.Eps || System.Math.Abs(scaleY - 1.0f) > VObject.Eps;

            try
            {
                if (_image.PixelFormat == Aurigma.GraphicsMill.PixelFormat.Format24bppRgb ||
                    _image.PixelFormat == Aurigma.GraphicsMill.PixelFormat.Format32bppRgb ||
                    _image.PixelFormat == Aurigma.GraphicsMill.PixelFormat.Format32bppArgb)
                {
                    if (!performScale)
                    {
                        result = _image.ToGdiPlusBitmap();
                    }
                    else
                    {
                        interimImage = new Aurigma.GraphicsMill.Bitmap();
                        using (Aurigma.GraphicsMill.Transforms.Resize resize = new Aurigma.GraphicsMill.Transforms.Resize())
                        {
                            resize.Width             = (int)(_image.Width * scaleX);
                            resize.Height            = (int)(_image.Height * scaleY);
                            resize.InterpolationMode = scaleToActualSizeInterpolationMode;
                            interimImage             = resize.Apply(_image);
                        }

                        result = interimImage.ToGdiPlusBitmap();
                    }
                }
                else
                {
                    if (_image.PixelFormat.IsIndexed || _image.HasAlpha)
                    {
                        converter.DestinationPixelFormat = Aurigma.GraphicsMill.PixelFormat.Format32bppArgb;
                    }
                    else
                    {
                        converter.DestinationPixelFormat = Aurigma.GraphicsMill.PixelFormat.Format24bppRgb;
                    }

                    interimImage = new Aurigma.GraphicsMill.Bitmap();
                    interimImage = converter.Apply(_image);

                    if (performScale)
                    {
                        interimImage.Transforms.Resize((int)(_image.Width * scaleX), (int)(_image.Height * scaleY));
                    }

                    result = interimImage.ToGdiPlusBitmap();
                }
            }
            catch
            {
                if (result != null)
                {
                    result.Dispose();
                }
                throw;
            }
            finally
            {
                converter.Dispose();

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

            result.SetResolution(monitorResX, monitorResY);
            return(result);
        }