Ejemplo n.º 1
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.º 2
0
        private void CreateBackgroundGridTemplate(int width)
        {
            if (width < 1)
            {
                throw new System.ArgumentOutOfRangeException("width", StringResources.GetString("ExStrValueShouldBeAboveZero"));
            }
            if (_bgGridTemplate != null && _bgGridTemplate.Width >= width)
            {
                return;
            }

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

            _bgGridTemplate = new Aurigma.GraphicsMill.Bitmap(width, 2 * bgGridCellSize, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

            using (Aurigma.GraphicsMill.Drawing.Graphics g = _bgGridTemplate.GetGraphics())
            {
                Aurigma.GraphicsMill.Drawing.SolidBrush brush0 = new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor1),
                                                        brush1 = new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor2);

                System.Drawing.Rectangle cellRect = new System.Drawing.Rectangle(0, 0, bgGridCellSize, bgGridCellSize);

                int n = (int)System.Math.Ceiling((float)width / (2.0f * bgGridCellSize));
                for (int i = 0; i < n; i++)
                {
                    g.FillRectangle(brush0, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                    g.FillRectangle(brush1, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                }

                cellRect.Location = new System.Drawing.Point(0, bgGridCellSize);
                for (int i = 0; i < n; i++)
                {
                    g.FillRectangle(brush1, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                    g.FillRectangle(brush0, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                }
            }
        }
Ejemplo n.º 3
0
        private void Clear()
        {
            _zoom = -1.0f;

            if (_image != null)
            {
                _image.Dispose();
                _image = null;
            }
        }
Ejemplo n.º 4
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.º 5
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.º 6
0
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }

                bitmap = new Aurigma.GraphicsMill.Bitmap(openFileDialog1.FileName);

                if (bitmapViewer1.Bitmap != null)
                {
                    var b = bitmapViewer1.Bitmap;
                    b.Dispose();
                }
                ;

                bitmapViewer1.Bitmap = new Aurigma.GraphicsMill.Bitmap(bitmap);

                trackBarHue.Enabled = true;
            }
        }
Ejemplo n.º 7
0
        public static Aurigma.GraphicsMill.Bitmap FindAreaOfInterest(Aurigma.GraphicsMill.Bitmap interestBitmap)
        {
            //If it's a large scan, squish it down to standard scan size.
            //Otherwise the pattern will never match
            //difference is the size of a standard scan as compared to a large one
            double difference = 0.7522935779816514;

            if ((interestBitmap.Width > 4000) || (interestBitmap.Height > 4000))
            {
                int newWidth  = (int)(interestBitmap.Width * difference);
                int newHeight = (int)(interestBitmap.Height * difference);
                interestBitmap.Transforms.Resize(newWidth, newHeight);
            }

            //Have to desaturate now so we can use histogram standard deviation to pick area of interest
            interestBitmap.ColorAdjustment.Desaturate();

            //Save whole pic in case the first block isn't interesting,
            //We'll use that copy to walk through the remaining blocks.
            Aurigma.GraphicsMill.Bitmap wholePic = new Aurigma.GraphicsMill.Bitmap(interestBitmap);

            //Crop it down to sample size
            interestBitmap.Transforms.Crop(0, 0, blocksize, blocksize);

            var histogram = interestBitmap.Statistics.GetSumHistogram();

            //If the first block in the image isn't "interesting" enough...
            if (histogram.StandardDeviation < 50)
            {
                int width  = wholePic.Width;
                int height = wholePic.Height;
                int YPos   = 0;

                while (histogram.StandardDeviation < 40)
                {
                    //...then walk through all the blocks until you find an interesting one.
                    //Increment X position
                    for (int XPos = 0; XPos < width; XPos += blocksize)
                    {
                        if (XPos > width - blocksize)
                        {
                            XPos = width - blocksize;
                        }
                        Aurigma.GraphicsMill.Bitmap testPic = new Aurigma.GraphicsMill.Bitmap(wholePic);

                        testPic.Transforms.Crop(XPos, YPos, blocksize, blocksize);

                        //Use histogram to get brightness and standard deviation
                        histogram = testPic.Statistics.GetSumHistogram();
                        float deviation  = histogram.StandardDeviation;
                        float brightness = histogram.Median;

                        //If you've found an interesting block, bail out.
                        if ((deviation > 50) && (brightness > 70) && (brightness < 230))
                        {
                            interestBitmap = new Aurigma.GraphicsMill.Bitmap(testPic);
                            break;
                        }
                        if (XPos == width - blocksize)
                        {
                            if (YPos == height - blocksize)
                            {
                                //We've reached the last block of the image
                                //Since no interesting area was found, we will end up using last block (lower right corner).
                                //In reality, there's almost zero chance of movement if we didn't find it interesting,
                                //but we'll return that last corner and check it anyway.
                                return(interestBitmap);
                            }
                            //Increment Y position
                            YPos += blocksize;
                            if (YPos > height - blocksize)
                            {
                                YPos = height - blocksize;
                            }
                        }
                        testPic.Dispose();
                    }
                }

                wholePic.Dispose();
            }
            //return area of interest.
            return(interestBitmap);
        }
Ejemplo n.º 8
0
        public static bool AnalyzeImage(System.Drawing.Bitmap inputBitmap)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            if (inputBitmap.Height < blocksize || inputBitmap.Width < blocksize)
            {
                return(false);
            }
            movementBitmap = BuildMovementBitmap();

            //Clone movement image to 24-bit small Image - Workaround to fix PixelFormat
            System.Drawing.Bitmap movementPattern = new System.Drawing.Bitmap(movementBitmap.Width, movementBitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            using (Graphics gr = Graphics.FromImage(movementPattern))
            {
                gr.DrawImage(movementBitmap, new Rectangle(0, 0, movementPattern.Width, movementPattern.Height));
            }

            bool IsThereMovement = false;

            Aurigma.GraphicsMill.Bitmap analyzeBitmap = new Aurigma.GraphicsMill.Bitmap(inputBitmap);

            //Get an area of interest
            analyzeBitmap = FindAreaOfInterest(analyzeBitmap);

            //Process area of interest bitmap into B&W we can analyze
            analyzeBitmap = GreyscaleAndThreshold(analyzeBitmap);

            //Have to turn it back into 24-bit or the pattern matching won't work
            analyzeBitmap.ColorManagement.Convert(Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

            //...Aaaaaaand back to a system Bitmap
            System.Drawing.Bitmap matchBitmap = analyzeBitmap.ToGdiPlusBitmap();

            // create template matching algorithm's instance
            // (We set similarity threshold at top of code to 90%)
            ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(THRESHOLD);

            // find all matchings with specified above similarity
            TemplateMatch[] matches = tm.ProcessImage(matchBitmap, movementPattern);

            //Find any matches?
            if (matches.Length > 0)
            {
                TemplateMatch match = matches[0];
                IsThereMovement = true;
            }

            movementBitmap.Dispose();
            analyzeBitmap.Dispose();
            matchBitmap.Dispose();
            movementPattern.Dispose();

            stopWatch.Stop();
            TimeSpan ts = stopWatch.Elapsed;

            MessageBox.Show("Processed in " + ts.TotalSeconds + " seconds.");

            return(IsThereMovement);
        }
Ejemplo n.º 9
0
        protected override int _AddImageInternal(Bitmap image, int destinationIndex)
        {
            if (_imageList == null)
            {
                throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("InternalImageListCannotBeNull"));
            }

            int result = -1;

            Aurigma.GraphicsMill.Bitmap imgResult = null;

            try
            {
                CreateListImage(_imageList.ImageSize, _listItemBackgroundColor, _listItemBackgroundImage, _listItemForegroundImage, image, out imgResult);

                try
                {
                    if (destinationIndex != -1)
                    {
                        _imageList.Images[destinationIndex] = imgResult.ToGdiPlusBitmap();
                        result = destinationIndex;
                    }
                    else
                    {
                        _imageList.Images.Add(imgResult.ToGdiPlusBitmap());
                        result = _imageList.Images.Count - 1;
                    }
                }
                catch (System.InvalidOperationException)
                {
                    if (_nextIndexToRewrite.Count > 0)
                    {
                        int index = (int)_nextIndexToRewrite.Dequeue();
                        ReplaceImage(index, imgResult.ToGdiPlusBitmap());
                        result = index;
                    }
                    else
                    {
                        throw;
                    }
                }

                if (result != -1 && result != 0)
                {
                    _nextIndexToRewrite.Enqueue(result);
                }
            }
            catch
            {
                result = -1;
            }
            finally
            {
                if (imgResult != null)
                {
                    imgResult.Dispose();
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        protected override int _AddImageInternal(Aurigma.GraphicsMill.Bitmap image, int destinationIndex)
        {
            if (image == null)
            {
                return(-1);
            }

            int result = -1;

            lock (this)
            {
                if (_imageList == null)
                {
                    throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("InternalImageListCannotBeNull"));
                }

                bool disposeImage = false;
                if (_imageList.ImageSize.Width != image.Width || _imageList.ImageSize.Height != image.Height)
                {
                    Aurigma.GraphicsMill.Bitmap imageCopy = ConvertToNonextendedRgb(image);
                    if (imageCopy == image)
                    {
                        imageCopy = new Aurigma.GraphicsMill.Bitmap(image);
                    }

                    imageCopy.Transforms.Resize(_imageList.ImageSize.Width, _imageList.ImageSize.Height, Transforms.ResizeInterpolationMode.High, Transforms.ResizeMode.Shrink);

                    int destX = (_imageList.ImageSize.Width - imageCopy.Width) / 2,
                        destY = (_imageList.ImageSize.Height - imageCopy.Height) / 2;

                    Aurigma.GraphicsMill.Bitmap resultImage = new Aurigma.GraphicsMill.Bitmap(
                        _imageList.ImageSize.Width,
                        _imageList.ImageSize.Height,
                        Aurigma.GraphicsMill.PixelFormat.Format32bppArgb,
                        new Aurigma.GraphicsMill.RgbColor(0xff, 0xff, 0xff, 0x0));

                    resultImage.Draw(imageCopy, destX, destY, image.Width, image.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Copy, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Low);
                    imageCopy.Dispose();

                    image        = resultImage;
                    disposeImage = true;
                }

                if (destinationIndex != -1)
                {
                    _imageList.Images[destinationIndex] = image.ToGdiPlusBitmap();
                    result = destinationIndex;
                }
                else
                {
                    _imageList.Images.Add(image.ToGdiPlusBitmap());
                    result = _imageList.Images.Count - 1;
                }

                if (disposeImage)
                {
                    image.Dispose();
                }
            }

            return(result);
        }