Ejemplo n.º 1
0
 public override void Apply(Aurigma.GraphicsMill.Bitmap bitmap)
 {
     base.Apply(bitmap);
     _redEyeRemoval.Progress += new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
     _redEyeRemoval.ApplyTransform(bitmap);
     _redEyeRemoval.Progress -= new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
 }
Ejemplo n.º 2
0
 public override void Apply(Aurigma.GraphicsMill.Bitmap bitmap)
 {
     base.Apply(bitmap);
     bitmap.Progress += new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
     bitmap.Transforms.RotateAndFlip(_rotateFlipType);
     bitmap.Progress -= new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
 }
Ejemplo n.º 3
0
        public virtual void AddImage(Aurigma.GraphicsMill.Bitmap image, object key)
        {
            if (!_imageList.HandleCreated)
            {
                throw new Aurigma.GraphicsMill.UnexpectedException("Handle has not been created.");
            }

            if (key == null)
            {
                throw new System.ArgumentNullException("key");
            }

            lock (this)
            {
                if (_imageList == null)
                {
                    return;
                }

                if (!ContainsKey(key))
                {
                    int index = _AddImageInternal(image, -1);
                    _keysHash.Add(key, index);
                }
            }
        }
Ejemplo n.º 4
0
        public static IBitmapTransform ApplyTransform(Aurigma.GraphicsMill.Bitmap bitmap, System.Windows.Forms.UserControl propertyPage)
        {
            ITransformPropertyPage tpp = (ITransformPropertyPage)propertyPage;

            tpp.Bitmap = bitmap;

            TransformDialog dialog = new TransformDialog();

            dialog.SuspendLayout();
            dialog.ClientSize     = new System.Drawing.Size(propertyPage.Width + 118, propertyPage.Height + 16);
            propertyPage.Location = new System.Drawing.Point(8, 8);
            propertyPage.TabIndex = 0;
            dialog.Controls.Add(propertyPage);

            dialog.buttonOK.Left     = propertyPage.Width + 24;
            dialog.buttonCancel.Left = propertyPage.Width + 24;
            dialog.ResumeLayout(false);

            dialog.Text = tpp.Title;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                return(tpp.Transform);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        public void SetThumbnail(Aurigma.GraphicsMill.Bitmap thumbnail)
        {
            if (thumbnail == null)
            {
                throw new System.ArgumentNullException("thumbnail");
            }

            IImageList imageList = this.Parent.GetImageList(View.Thumbnails);

            if (!HasIcon(View.Thumbnails))
            {
                lock (imageList)
                {
                    lock (this)
                    {
                        if (base.Parent != null)
                        {
                            base.Parent.QueueManager.Remove((IQueueItem)this);
                        }

                        imageList.AddImage(thumbnail, this);
                        _imageIndexKeys[View.Thumbnails] = this;
                    }
                }
            }
            else
            {
                imageList.SetImage(thumbnail, this);
            }

            OnIconChanged(View.Thumbnails);
        }
Ejemplo n.º 6
0
        private void DoTransformBitmap(object bitmapObject)
        {
            Aurigma.GraphicsMill.Bitmap bitmap = (Aurigma.GraphicsMill.Bitmap)bitmapObject;

            int transformsProgressStepCount = 0;

            for (int i = 0; i < _transformIndex; i++)
            {
                transformsProgressStepCount += _transforms[i].TransformProgressStepCount;
            }

            _progressDialog.SetRange(0, transformsProgressStepCount);

            for (int i = 0; i < _transformIndex; i++)
            {
                if (_progressDialog.IsAborted)
                {
                    break;
                }
                _transforms[i].Progress += new Aurigma.GraphicsMill.ProgressEventHandler(TransformProgressEventHandler);
                _transforms[i].Apply(bitmap);
                _transforms[i].Progress -= new Aurigma.GraphicsMill.ProgressEventHandler(TransformProgressEventHandler);
            }

            if (_progressDialog.IsAborted)
            {
                _progressDialog.IsComplete = false;
            }
            else
            {
                _progressDialog.IsComplete = true;
            }

            _progressDialog.End();
        }
Ejemplo n.º 7
0
        public ImageVObject(Aurigma.GraphicsMill.Bitmap image, bool scaleToActualSize, float x, float y)
        {
            if (image == null)
            {
                throw new System.ArgumentNullException("image");
            }

            if (image.IsEmpty)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrBitmapCannotBeEmpty"), "image");
            }

            base.Name = "image";
            _image    = image;

            _scaleToActualSize = scaleToActualSize;

            float widthInPoints  = Aurigma.GraphicsMill.UnitConverter.ConvertPixelsToUnits(this.DrawnImage.HorizontalResolution, this.DrawnImage.Width, Aurigma.GraphicsMill.Unit.Point);
            float heightInPoints = Aurigma.GraphicsMill.UnitConverter.ConvertPixelsToUnits(this.DrawnImage.VerticalResolution, this.DrawnImage.Height, Aurigma.GraphicsMill.Unit.Point);

            _rect       = new RectangleVObject(0, 0, widthInPoints, heightInPoints);
            _rect.Brush = System.Drawing.Brushes.Transparent;
            _rect.Pen   = null;
            _rect.Transform.Translate(x, y);
        }
    /// <summary>
    /// Loads non-RGB image with Aurigma.GraphicsMill.Bitmap, pass it to System.Drawing.Bitmap and
    /// convert it back to Aurigma.GraphicsMill.Bitmap.
    /// </summary>
    private static void ProcessNonRgb()
    {
        // Imagine that you have a legacy application which works with System.Drawing.Bitmap,
        // and you need to work with non-RGB images. You should convert it to RGB with Graphics Mill, cast it
        // to System.Drawing.Bitmap and convert back.
        using (var reader = new Aurigma.GraphicsMill.Codecs.JpegReader("../../../../_Input/Copenhagen_CMYK.jpg"))
            using (var gmBitmap1 = reader.Frames[0].GetBitmap())
            {
                Aurigma.GraphicsMill.Bitmap rgbGmBitmap = null;

                try
                {
                    // Convert a non-RGB image to the RGB color space with the sRGB color profile
                    if (!gmBitmap1.PixelFormat.IsRgb)
                    {
                        rgbGmBitmap = new Aurigma.GraphicsMill.Bitmap(gmBitmap1);
                        rgbGmBitmap.ColorManagement.DestinationProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
                        rgbGmBitmap.ColorManagement.Convert(Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);
                    }

                    using (var sdBitmap = (System.Drawing.Bitmap)(gmBitmap1.PixelFormat.IsRgb ? gmBitmap1 : rgbGmBitmap))
                    {
                        // Here we modify System.Drawing.Bitmap
                        ApplyWatermark(sdBitmap);

                        using (var gmBitmap2 = (Aurigma.GraphicsMill.Bitmap)sdBitmap)
                        {
                            // Convert an RGB image to the source color space (CMYK, grayscale, or Lab)
                            if (!gmBitmap1.PixelFormat.IsRgb)
                            {
                                gmBitmap2.ColorProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb();
                                gmBitmap2.ColorManagement.DestinationProfile = gmBitmap1.ColorProfile;
                                gmBitmap2.ColorManagement.Convert(gmBitmap1.PixelFormat);
                            }

                            // Copy color profile
                            gmBitmap2.ColorProfile = gmBitmap1.ColorProfile;

                            using (var writer = new Aurigma.GraphicsMill.Codecs.JpegWriter("../../../../_Output/ProcessNonRgb.jpg"))
                            {
                                // Copy metadata
                                writer.Exif           = reader.Exif;
                                writer.Iptc           = reader.Iptc;
                                writer.Xmp            = reader.Xmp;
                                writer.AdobeResources = reader.AdobeResources;

                                Aurigma.GraphicsMill.Pipeline.Run(gmBitmap2 + writer);
                            }
                        }
                    }
                }
                finally
                {
                    if (rgbGmBitmap != null)
                    {
                        rgbGmBitmap.Dispose();
                    }
                }
            }
    }
Ejemplo n.º 9
0
        public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (viewport.Width < 1 || viewport.Height < 1 || renderingRegion.Width < 1 || renderingRegion.Height < 1)
            {
                return;
            }

            if (canvas == null)
            {
                throw new System.ArgumentNullException("canvas");
            }
            if (canvas.IsEmpty)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrBitmapCannotBeEmpty"), "canvas");
            }
            if (!viewport.Contains(renderingRegion))
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrRenderingRegionShouldBeInsideViewport"), "renderingRegion");
            }

            System.Drawing.Rectangle viewportInvalidatedRect = CoordinateMapper.WorkspaceToControl(this.InvalidatedRegion, zoom, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, _renderingResolution);
            if (renderingRegion.IntersectsWith(viewportInvalidatedRect) || !_viewportCache.IsEntirelyInCache(zoom, renderingRegion))
            {
                BuildUpViewportImage(canvas, zoom, viewport, viewportInvalidatedRect);
                this.InvalidatedRegion = System.Drawing.RectangleF.Empty;
                _viewportCache.UpdateCache(canvas, zoom, viewport);
            }
            else
            {
                System.Diagnostics.Debug.Assert(_viewportCache.IsEntirelyInCache(zoom, renderingRegion), "At this point we should already have actual image in cache.");
                _viewportCache.DrawCached(canvas, zoom, viewport, renderingRegion);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Retrieves thumbnail for specified file.
        /// </summary>
        /// <param name="pidl">Source object for which info should be retrieved.</param>
        /// <param name="width">Desired thumbnail width.</param>
        /// <param name="height">Desired thumbnail heigth</param>
        /// <param name="image">Reference to variable where to store result thumbnail.</param>
        /// <param name="icon">Reference to variable where to store large icon handle, in case when file thumbnail cannot be created.</param>
        public static void RetrieveThumbnail(Pidl pidl, int width, int height, ref Aurigma.GraphicsMill.Bitmap image, ref IntPtr icon)
        {
            image = null;
            icon  = IntPtr.Zero;

            try
            {
                using (var stream = pidl.Stream)
                    using (var reader = Aurigma.GraphicsMill.Codecs.ImageReader.Create(stream))
                    {
                        if (reader != null)
                        {
                            image = ExtractExifThumbnail(reader, width, height);

                            if (image == null)
                            {
                                image = reader.Frames[0].GetBitmap();
                                image.Transforms.Resize(width, height, Transforms.ResizeInterpolationMode.High, Transforms.ResizeMode.Fit);
                            }
                        }
                    }
            }
            catch
            {
                image = null;
            }

            if (image == null)
            {
                icon = FileInfoRetriever.GetIcon(pidl, false);
            }
        }
Ejemplo n.º 11
0
        public override void Apply(Aurigma.GraphicsMill.Bitmap bitmap)
        {
            base.Apply(bitmap);

            bitmap.Progress += new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
            bitmap.Transforms.Crop(_x, _y, _width, _height);
            bitmap.Progress -= new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Third method associated with the item. It retrieves file thumbnail.
        /// </summary>
        /// <returns>true if succeded; otherwise, false.</returns>
        private bool EvalMethod2()
        {
            if (this.Parent == null)
            {
                return(false);
            }

            Aurigma.GraphicsMill.Bitmap image = null;
            System.IntPtr icon = System.IntPtr.Zero;

            try
            {
                if (this.Parent != null)
                {
                    ThumbnailImageList imageList = (ThumbnailImageList)this.Parent.GetImageList(View.Thumbnails);
                    FileInfoRetriever.RetrieveThumbnail(_pidl, imageList.ThumbnailSize.Width, imageList.ThumbnailSize.Height, ref image, ref icon);
                    if (image == null && icon != System.IntPtr.Zero)
                    {
                        image = ImageListBase.IconToAlphaBitmap(icon);
                    }

                    OnThumbnailLoaded(image);

                    lock (imageList)
                    {
                        lock (this)
                        {
                            _imageIndexKeys[View.Thumbnails] = this;

                            if (this.Parent != null)
                            {
                                _imageIndexKeys[View.Thumbnails] = this;
                                if (imageList.ContainsKey(this))
                                {
                                    imageList.SetImage(image, this);
                                }
                                else
                                {
                                    imageList.AddImage(image, this);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }

                NativeMethods.DestroyIcon(icon);
            }

            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Ignores modifyLayer - not supported by this renderer.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="textLayers"></param>
        /// <param name="showLayerCallback"></param>
        /// <param name="modifyLayer"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap Render(Stream s, out IList<IPsdLayer> layers, RenderLayerDelegate showLayerCallback, ModifyLayerDelegate modifyLayer)
        {
            // Create the resultBitmap object which contains merged bitmap, 
            // and the currentBitmap object which contains current bitmap during iteration. 
            // These object enable you to operate with layers.
            Aurigma.GraphicsMill.Bitmap resultBitmap = new Aurigma.GraphicsMill.Bitmap();
            using (Aurigma.GraphicsMill.Bitmap currentBitmap = new Aurigma.GraphicsMill.Bitmap())
            {
                // Create advanced PSD reader object to read .psd files.
                using (Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(s))
                {

                    // Load the background layer which you will put other layers on. 
                    // Remember that the layer on zero position should be skiped 
                    // because it contains merged bitmap.
                    Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame;
                    using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(1))
                    {
                        frame.GetBitmap(resultBitmap);
                    }

                    //List of layers
                    layers = new List<IPsdLayer>();

                    //This code merges the rest layers with the background layer one by one.
                    for (int i = 2; i < psdReader.FrameCount; i++)
                    {
                        using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(i))
                        {

                            // Do not forget to verify the unknown layer type.  
                            if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)
                            {
                                //Add layers
                                layers.Add(new PsdLayer(frame, i + 1));

                                bool showFrame = showLayerCallback(i - 1, frame.Name, frame.Visible); //Subtract 1 from index so layer 0 is the background layer
                                if (showFrame)
                                {
                                    // Extract the current image from the layer.
                                    frame.GetBitmap(currentBitmap);
                                   
                                    // Draw current layer on the result bitmap. 
                                    // Also check out if the layer is visible or not.
                                    // If the layer is invisible we skip it.
                                    currentBitmap.Draw(currentBitmap, frame.Left, frame.Top, frame.Width, frame.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);
                                    
                                   
                                }
                            }
                        }
                    }
                }
            }
            return resultBitmap.ToGdiplusBitmapDirectly();
        }
Ejemplo n.º 14
0
        //Overload for Aurigma bitmaps
        public static bool CheckForMovement(Aurigma.GraphicsMill.Bitmap aurigmaFile)
        {
            bool verdict = false;

            using (System.Drawing.Bitmap inputFile = aurigmaFile.ToGdiPlusBitmap())
            {
                verdict = AnalyzeImage(inputFile);
            }
            return(verdict);
        }
Ejemplo n.º 15
0
 public override void Apply(Aurigma.GraphicsMill.Bitmap bitmap)
 {
     base.Apply(bitmap);
     foreach (Transform transform in _transforms)
     {
         transform.Progress += new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
         transform.Apply(bitmap);
         transform.Progress -= new Aurigma.GraphicsMill.ProgressEventHandler(ProgressEventHandler);
     }
 }
Ejemplo n.º 16
0
        private void Clear()
        {
            _zoom = -1.0f;

            if (_image != null)
            {
                _image.Dispose();
                _image = null;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Ignores modifyLayer - not supported by this renderer.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="textLayers"></param>
        /// <param name="showLayerCallback"></param>
        /// <param name="modifyLayer"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap Render(Stream s, out IList<IPsdLayer> layers, RenderLayerDelegate showLayerCallback, ModifyLayerDelegate modifyLayer)
        {
            // Create the resultBitmap object which contains merged bitmap,
            // and the currentBitmap object which contains current bitmap during iteration.
            // These object enable you to operate with layers.
            Aurigma.GraphicsMill.Bitmap resultBitmap = new Aurigma.GraphicsMill.Bitmap();
            using (Aurigma.GraphicsMill.Bitmap currentBitmap = new Aurigma.GraphicsMill.Bitmap())
            {
                // Create advanced PSD reader object to read .psd files.
                using (Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(s))
                {

                    // Load the background layer which you will put other layers on.
                    // Remember that the layer on zero position should be skiped
                    // because it contains merged bitmap.
                    Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame;
                    using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(1))
                    {
                        frame.GetBitmap(resultBitmap);
                    }

                    //List of layers
                    layers = new List<IPsdLayer>();

                    //This code merges the rest layers with the background layer one by one.
                    for (int i = 2; i < psdReader.FrameCount; i++)
                    {
                        using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(i))
                        {

                            // Do not forget to verify the unknown layer type.
                            if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)
                            {
                                //Add layers
                                layers.Add(new PsdLayer(frame, i + 1));

                                bool showFrame = showLayerCallback(i - 1, frame.Name, frame.Visible); //Subtract 1 from index so layer 0 is the background layer
                                if (showFrame)
                                {
                                    // Extract the current image from the layer.
                                    frame.GetBitmap(currentBitmap);

                                    // Draw current layer on the result bitmap.
                                    // Also check out if the layer is visible or not.
                                    // If the layer is invisible we skip it.
                                    currentBitmap.Draw(currentBitmap, frame.Left, frame.Top, frame.Width, frame.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);

                                }
                            }
                        }
                    }
                }
            }
            return resultBitmap.ToGdiplusBitmapDirectly();
        }
Ejemplo n.º 18
0
        public Aurigma.GraphicsMill.Bitmap RenderWorkspace(float renderingResolution)
        {
            if (renderingResolution < VObject.Eps)
            {
                throw new System.ArgumentOutOfRangeException("renderingResolution", StringResources.GetString("ExStrValueShouldBeAboveZero"));
            }

            float workspaceWidth, workspaceHeight;

            Aurigma.GraphicsMill.Unit prevUnit = _hostViewer.Unit;
            _hostViewer.Unit = Aurigma.GraphicsMill.Unit.Point;
            try
            {
                workspaceWidth  = _hostViewer.WorkspaceWidth;
                workspaceHeight = _hostViewer.WorkspaceHeight;
            }
            finally
            {
                _hostViewer.Unit = prevUnit;
            }

            System.Drawing.Rectangle controlRectangle = CoordinateMapper.WorkspaceToControl(new System.Drawing.RectangleF(0, 0, workspaceWidth, workspaceHeight), 1.0f, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, renderingResolution);
            controlRectangle.Width  = System.Math.Max(1, controlRectangle.Width);
            controlRectangle.Height = System.Math.Max(1, controlRectangle.Height);

            Aurigma.GraphicsMill.Bitmap result = new Aurigma.GraphicsMill.Bitmap(controlRectangle.Width, controlRectangle.Height, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb, Aurigma.GraphicsMill.RgbColor.Transparent);
            try
            {
                using (var g = result.GetGdiPlusGraphics())
                {
                    CoordinateMapper coordMapper = new CoordinateMapper();
                    coordMapper.Resolution = renderingResolution;
                    coordMapper.Zoom       = 1.0f;
                    coordMapper.Viewport   = controlRectangle;

                    _alwaysUseGdiPlus = true;
                    DrawContent(g, controlRectangle, coordMapper);
                    _alwaysUseGdiPlus = false;
                }
            }
            catch
            {
                if (result != null)
                {
                    result.Dispose();
                }

                throw;
            }

            result.DpiX = renderingResolution;
            result.DpiY = renderingResolution;

            return(result);
        }
Ejemplo n.º 19
0
        private static Aurigma.GraphicsMill.Bitmap ExtractExifThumbnail(Aurigma.GraphicsMill.Codecs.ImageReader reader, int width, int height)
        {
            Aurigma.GraphicsMill.Codecs.ExifDictionary exif = null;
            Aurigma.GraphicsMill.Bitmap result = null;

            try
            {
                Aurigma.GraphicsMill.Codecs.JpegReader jpgReader = reader as Aurigma.GraphicsMill.Codecs.JpegReader;
                if (jpgReader != null)
                {
                    exif = jpgReader.Exif;
                }
                else
                {
                    Aurigma.GraphicsMill.Codecs.TiffReader tiffReader = reader as Aurigma.GraphicsMill.Codecs.TiffReader;
                    if (tiffReader != null)
                    {
                        exif = tiffReader.Exif;
                    }
                    else
                    {
                        Aurigma.GraphicsMill.Codecs.Psd.PsdReader psdReader = reader as Aurigma.GraphicsMill.Codecs.Psd.PsdReader;
                        if (psdReader != null)
                        {
                            exif = psdReader.Exif;
                        }
                    }
                }

                if (exif != null && exif.Contains(Aurigma.GraphicsMill.Codecs.ExifDictionary.Thumbnail))
                {
                    Aurigma.GraphicsMill.Bitmap exifThumbnail = (Aurigma.GraphicsMill.Bitmap)exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Thumbnail];
                    if (exifThumbnail.Width >= width || exifThumbnail.Height >= height)
                    {
                        exifThumbnail.Transforms.Resize(width, height, Transforms.ResizeInterpolationMode.High, Aurigma.GraphicsMill.Transforms.ResizeMode.Shrink);
                        result = exifThumbnail;
                    }
                    else
                    {
                        exifThumbnail.Dispose();
                    }
                }
            }
            catch
            {
                if (exif != null)
                {
                    exif.Dispose();
                }
                exif   = null;
                result = null;
            }

            return(result);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Method generates actual image for specified viewport.
        /// </summary>
        private void BuildUpViewportImage(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle invalidatedRect)
        {
            if (canvas.Width != viewport.Width || canvas.Height != viewport.Height)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrCanvasAndViewportDimsShouldBeEqual"));
            }

            // We should take into account 2 issues here
            // 1) Shift or resize of the viewport.
            // 2) Invalidated areas.
            //
            // Note: Current implementation may draw twice invalidatedRect in some case. Taking this case
            // into account would cause code complication. I think that it is a rather rare case, because invalidatedRect
            // is usually empty during scrolling. On the other hand, it is not empty during
            // object editing, but in such case viewportOrigin is not changed. In both of these most regular cases
            // invalidatedRect will be drawn once.

            // Drawing actual cached region of the viewportOrigin.
            System.Drawing.Rectangle   cachedRegion        = _viewportCache.GetActualRegion(zoom, viewport);
            System.Drawing.Rectangle[] cachedActualRegions = VObjectsUtils.SubstractRectangle(cachedRegion, invalidatedRect);

            for (int i = 0; i < cachedActualRegions.Length; i++)
            {
                if (cachedActualRegions[i].Width < 1 || cachedActualRegions[i].Height < 1)
                {
                    continue;
                }

                using (var canvasGdiGraphics = canvas.GetGraphics())
                {
                    _viewportCache.DrawCached(canvasGdiGraphics, zoom, viewport, cachedActualRegions[i]);
                }
            }

            // Drawing non-cached parts of the viewportOrigin image.
            invalidatedRect.Intersect(viewport);
            if (invalidatedRect.Width > 0 && invalidatedRect.Height > 0)
            {
                DrawNoncachedArea(canvas, zoom, viewport, invalidatedRect);
            }

            System.Drawing.Rectangle[] newRegions = VObjectsUtils.SubstractRectangle(viewport, cachedRegion);
            for (int i = 0; i < newRegions.Length; i++)
            {
                newRegions[i].Intersect(viewport);

                if (newRegions[i].Width < 1 || newRegions[i].Height < 1)
                {
                    continue;
                }

                DrawNoncachedArea(canvas, zoom, viewport, newRegions[i]);
            }
        }
Ejemplo n.º 22
0
        protected override void DrawNoncachedArea(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (_renderBackground)
            {
                DrawViewportBackground(canvas, viewport, renderingRegion);
            }

            for (int i = 0; i < _childRenderers.Length; i++)
            {
                _childRenderers[i].Render(canvas, zoom, viewport, renderingRegion);
            }
        }
Ejemplo n.º 23
0
        protected override TaskOutput Execute(TaskInput input, ITaskContext context)
        {
            foreach (var file in input.Files)
            {
                Rectangle cropRectangle;
                bool      cropped = false;
                if (TryGetCropRectangle(file, out cropRectangle))
                {
                    try
                    {
                        using (var readStream = new FileStream(file.Path, FileMode.Open))
                        {
                            using (var reader = FormatManager.CreateFormatReader(readStream))
                            {
                                using (var frame = reader.LoadFrame(0))
                                {
                                    if ((cropRectangle.X > 0 || cropRectangle.Y > 0) && (cropRectangle.Width < frame.Width || cropRectangle.Height < frame.Height))
                                    {
                                        using (var resultBitmap = new Bitmap(frame.Width, frame.Height, Aurigma.GraphicsMill.PixelFormat.Format32bppArgb))
                                        {
                                            frame.GetBitmap(resultBitmap);
                                            resultBitmap.Transforms.Crop(cropRectangle);

                                            if (reader.MediaFormat == FormatManager.JpegFormat)
                                            {
                                                resultBitmap.Save(file.Path + ".tmp", new JpegEncoderOptions(95, false));
                                            }
                                            else
                                            {
                                                resultBitmap.Save(file.Path + ".tmp", FormatManager.CreateEncoderOptions(reader.MediaFormat));
                                            }
                                        }
                                        cropped = true;
                                    }
                                }
                            }
                        }

                        if (cropped)
                        {
                            File.Delete(file.Path);
                            File.Move(file.Path + ".tmp", file.Path);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.ErrorException(string.Format("Error acquired while cropping file {0}", file.Path), ex);
                    }
                }
            }
            return(new TaskOutput(input.Files, input.Params));
        }
Ejemplo n.º 24
0
        private string LoadImage(PictureBox imgPictureBox, TextBox txtCyanX, TextBox txtCyanY, TextBox txtMagentaX, TextBox txtMagentaY, TextBox txtYellowX, TextBox txtYellowY, TextBox txtBlackX, TextBox txtBlackY)
        {
            OpenFileDialog open = new OpenFileDialog();

            if (open.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmp = new Bitmap(open.FileName);
                imgPictureBox.Image = bmp;
                Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(open.FileName);
                Bitmap cyanBitmap    = (Bitmap)bitmap.Channels[Aurigma.GraphicsMill.Channel.Cyan];
                Bitmap MagentaBitmap = (Bitmap)bitmap.Channels[Aurigma.GraphicsMill.Channel.Magenta];
                Bitmap yellowBitmap  = (Bitmap)bitmap.Channels[Aurigma.GraphicsMill.Channel.Yellow];
                Bitmap blackBitmap   = (Bitmap)bitmap.Channels[Aurigma.GraphicsMill.Channel.Black];


                int cyanXPosition = GetLenghtToTheFirstLine(cyanBitmap);
                int cyanYPosition = GetHeightToTheFirstLine(cyanBitmap);

                int magentaXPosition = GetLenghtToTheFirstLine(MagentaBitmap);
                int magentaYPosition = GetHeightToTheFirstLine(MagentaBitmap);

                int yellowXPosition = GetLenghtToTheFirstLine(yellowBitmap);
                int yellowYPosition = GetHeightToTheFirstLine(yellowBitmap);

                int blackXPosition = GetLenghtToTheFirstLine(blackBitmap);
                int blackYPosition = GetHeightToTheFirstLine(blackBitmap);

                int magentaErrorX = cyanXPosition - magentaXPosition;
                int magentaErrorY = cyanYPosition - magentaYPosition;

                int yellowErrorX = cyanXPosition - yellowXPosition;
                int yellowErrorY = cyanYPosition - yellowYPosition;

                int blackErrorX = cyanXPosition - blackXPosition;
                int blackErrorY = cyanYPosition - blackYPosition;

                txtCyanX.Text = cyanXPosition.ToString();
                txtCyanY.Text = cyanYPosition.ToString();

                txtMagentaX.Text = magentaErrorX.ToString();
                txtMagentaY.Text = magentaErrorY.ToString();

                txtYellowX.Text = yellowErrorX.ToString();
                txtYellowY.Text = yellowErrorY.ToString();

                txtBlackX.Text = blackErrorX.ToString();
                txtBlackY.Text = blackErrorY.ToString();
            }

            return("");
        }
Ejemplo n.º 25
0
        internal static Aurigma.GraphicsMill.Bitmap ConvertToNonextendedRgb(Aurigma.GraphicsMill.Bitmap image)
        {
            if (image.PixelFormat.ColorSpace == Aurigma.GraphicsMill.ColorSpace.Rgb && !image.PixelFormat.IsExtended)
            {
                return(image);
            }

            Aurigma.GraphicsMill.Transforms.ColorConverter converter = new Aurigma.GraphicsMill.Transforms.ColorConverter();
            Aurigma.GraphicsMill.Bitmap resultImage = new Aurigma.GraphicsMill.Bitmap();
            converter.DestinationPixelFormat = image.HasAlpha ? Aurigma.GraphicsMill.PixelFormat.Format32bppArgb : Aurigma.GraphicsMill.PixelFormat.Format24bppRgb;
            resultImage = converter.Apply(image);

            return(resultImage);
        }
Ejemplo n.º 26
0
        public ImageRubberband(Aurigma.GraphicsMill.Bitmap image)
        {
            if (image == null)
            {
                throw (new ArgumentNullException("image"));
            }

            _image          = image;
            this.GripSize   = 8;
            this.MaskStyle  = Aurigma.GraphicsMill.WinControls.MaskStyle.None;
            this.ResizeMode = Aurigma.GraphicsMill.WinControls.ResizeMode.Proportional;
            this.Ratio      = System.Convert.ToDouble(_image.Width) / System.Convert.ToDouble(_image.Height);
            this.Erasable   = false;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Saves a copy of the specified image in the cache.
        /// </summary>
        /// <param name="image">New actual image of the viewport.</param>
        /// <param name="zoom">Current zoom value.</param>
        /// <param name="viewport">Viewport position and coordinates.</param>
        public void UpdateCache(Aurigma.GraphicsMill.Bitmap image, float zoom, System.Drawing.Rectangle viewport)
        {
            if (image == null)
            {
                throw new System.ArgumentNullException("image");
            }
            if (viewport.Width != image.Width || viewport.Height != image.Height)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrImageAndViewportDimsShouldBeEqual"), "image");
            }

            _zoom     = zoom;
            _viewport = viewport;

            _image = new Aurigma.GraphicsMill.Bitmap(image);
        }
Ejemplo n.º 28
0
        private void DrawViewportBackground(Aurigma.GraphicsMill.Bitmap canvas, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            using (Aurigma.GraphicsMill.Drawing.Graphics g = canvas.GetGraphics())
            {
                System.Drawing.Rectangle screenRect = renderingRegion;
                screenRect.X -= viewport.X;
                screenRect.Y -= viewport.Y;

                if (_workspaceBackgroundStyle == Aurigma.GraphicsMill.WinControls.WorkspaceBackgroundStyle.Grid)
                {
                    int gridPatternSize = 2 * bgGridCellSize;
                    int patternOffsetX  = renderingRegion.X % gridPatternSize,
                        patternOffsetY  = renderingRegion.Y % gridPatternSize;

                    CreateBackgroundGridTemplate(renderingRegion.Width + gridPatternSize);

                    System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(0, 0, _bgGridTemplate.Width, _bgGridTemplate.Height),
                                             dstRect = new System.Drawing.Rectangle(renderingRegion.Location, srcRect.Size);
                    dstRect.Offset(-viewport.X, -viewport.Y);
                    dstRect.Offset(-patternOffsetX, -patternOffsetY);

                    g.SetClip(new System.Drawing.Rectangle(renderingRegion.X - viewport.X, renderingRegion.Y - viewport.Y, renderingRegion.Width, renderingRegion.Height));
                    try
                    {
                        int templateRepeats = (int)System.Math.Ceiling((float)(renderingRegion.Height + patternOffsetY) / _bgGridTemplate.Height);
                        for (int j = 0; j < templateRepeats; j++)
                        {
                            g.DrawImage(_bgGridTemplate, dstRect, /*srcRect,*/ Aurigma.GraphicsMill.Transforms.CombineMode.Copy, 1.0f, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.NearestNeighbour);
                            dstRect.Offset(0, _bgGridTemplate.Height);
                        }
                    }
                    finally
                    {
                        g.ResetClip();
                    }
                }
                else if (_workspaceBackgroundStyle == Aurigma.GraphicsMill.WinControls.WorkspaceBackgroundStyle.Solid)
                {
                    g.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor1), screenRect);
                }
                else
                {
                    g.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(_backColor), screenRect);
                }
            }
        }
Ejemplo n.º 29
0
        public override void Dispose()
        {
            try
            {
                if (_bgGridTemplate != null)
                {
                    _bgGridTemplate.Dispose();
                    _bgGridTemplate = null;
                }

                DisposeLayerRenders();
            }
            finally
            {
                base.Dispose();
            }
        }
Ejemplo n.º 30
0
    public Aurigma.GraphicsMill.Bitmap RenderRegion(string regionName, float dpi)
    {
        Layer        renderedLayer = null;
        List <Layer> hiddenLayers  = new List <Layer>(_canvasViewer.Canvas.Layers.Count);

        foreach (Layer l in _canvasViewer.Canvas.Layers)
        {
            if (l.Name == regionName)
            {
                renderedLayer = l;
            }
            else if (l.Visible)
            {
                l.Visible = false;
                hiddenLayers.Add(l);
            }
        }
        if (renderedLayer == null)
        {
            //TODO: throw exception
        }

        // Temporary remove region from rendered layer.
        RectangleRegion rr = renderedLayer.Region;

        renderedLayer.Region = null;

        //render canvas
        Aurigma.GraphicsMill.Bitmap bp = _canvasViewer.Canvas.RenderWorkspace(dpi, Aurigma.GraphicsMill.ColorSpace.Rgb);

        // Restore region back.
        renderedLayer.Region = rr;

        //crop region
        Rectangle r = new Rectangle(Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Left),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Top),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Width),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Height));

        bp.Transforms.Crop(r);

        //revert hidden layers
        hiddenLayers.ForEach(delegate(Layer l) { l.Visible = true; });
        return(bp);
    }
Ejemplo n.º 31
0
        public static Aurigma.GraphicsMill.Bitmap GreyscaleAndThreshold(Aurigma.GraphicsMill.Bitmap inputBitmap)
        {
            //Apply the Auto-level
            inputBitmap.ColorAdjustment.AutoLevels(0.001f);

            // apply the greyscale filter
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);

            System.Drawing.Bitmap trueBWBitmap = filter.Apply((System.Drawing.Bitmap)inputBitmap);

            //Apply the threshold filter
            Threshold thresh = new Threshold(128);

            thresh.ApplyInPlace(trueBWBitmap);

            //Send it on back
            return((Aurigma.GraphicsMill.Bitmap)trueBWBitmap);
        }
Ejemplo n.º 32
0
        private void ApplyCorrectionsToThumbnail()
        {
            using (var bmp = new Aurigma.GraphicsMill.Bitmap(_filePath))
            {
                int preHeight = bmp.Height;
                int preWidth = bmp.Width;

                if (preHeight > preWidth)
                {
                    bmp.Transforms.Resize(0, 200, ResizeInterpolationMode.High);
                }
                else
                {
                bmp.Transforms.Resize(200, 0, ResizeInterpolationMode.High);
                    
                }

                int thisHeight = bmp.Height;
                int thisWidth = bmp.Width;

                Aurigma.GraphicsMill.Bitmap adjBmp = Processor.ProcessBitmap(bmp, thumbCorrection, thisWidth, thisHeight);
                imageBox.Image = (Image)adjBmp;
            }
        }