internal void GenerateOriginalGene()
        {
            workingGene = new Gene();
            int initialPolygonsCount = NrOfPolygons / 2 + random.Next(NrOfPolygons / 2);

            workingGene.InitialFill((Bitmap)OriginalImage.Clone(), NrOfPolygons, initialPolygonsCount);
        }
Example #2
0
        private void ApplyEffectsNegative()
        {
            System.Drawing.Bitmap             bmp;
            System.Drawing.Imaging.BitmapData bmData;
            System.IntPtr ptr;
            int           nOffSet, x, y, tamanho;

            bmp     = (System.Drawing.Bitmap)OriginalImage.Clone();
            bmData  = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            ptr     = bmData.Scan0;
            nOffSet = bmData.Stride - bmp.Width * 3;
            switch (m_enumEffectDirection)
            {
            case PictureBox.Directions.Horizontal:
                break;

            case PictureBox.Directions.Vertical:
                tamanho = (int)((bmp.Height * m_nPercentage) / 100);
                for (y = tamanho; y < bmp.Height - 1; y++)
                {
                    for (x = 0; x < (bmp.Width * 3) - 1; x++)
                    {
                        System.Runtime.InteropServices.Marshal.WriteByte(ptr, 0, (byte)(255 - System.Runtime.InteropServices.Marshal.ReadByte(ptr, 0)));
                        ptr = new System.IntPtr(ptr.ToInt32() + 1);
                    }
                }
                break;
            }
            bmp.UnlockBits(bmData);
            this.Image = bmp;
            this.Refresh();
        }
Example #3
0
        /// <summary>
        /// Scales this image so that it fits a certain width and height.
        /// </summary>
        /// <param name="width">the width to fit</param>
        /// <param name="height">the height to fit</param>
        /// <returns>
        /// Returns this instance scaled.
        /// </returns>
        public XlsxImage ScaleToFit(float width, float height)
        {
            if (this.Equals(XlsxImage.Null))
            {
                return(this);
            }

            if (Image == null)
            {
                return(this);
            }

            _hasScaledPercent = false;
            _hasScaledFit     = true;
            _scaleX           = width;
            _scaleY           = height;

            var original            = (Image)OriginalImage.Clone();
            var originalWithEffects = original;

            if (Configuration.Effects != null)
            {
                originalWithEffects = original.ApplyEffects(Configuration.Effects);
            }

            ProcessedImage = (Image)originalWithEffects.ScaleToFit(width, height).Clone();

            return(this);
        }
Example #4
0
        public override async Task <Bitmap> Process()
        {
            if (OriginalImage == null)
            {
                return(await DefaultResult());
            }

            var clone = (Bitmap)OriginalImage.Clone();

            ProcessedImage = await Task.Run(() => clone.ForEachPixel(pixel => pixel.Grayscale()));

            return(ProcessedImage);
        }
Example #5
0
        public override async Task <Bitmap> Process()
        {
            if (OriginalImage == null)
            {
                return(await DefaultResult());
            }

            var bitmap = (Bitmap)OriginalImage.Clone();

            return(await Task.Run(() => bitmap.ForEachPixel(p => p.Grayscale()))
                   //.ContinueWith(task => task.Result.MedianFilter((Bitmap)bitmap.Clone(), 3))
                   .ContinueWith(task => task.Result.ApplyForstnerDetector(2, 4))
                   .ContinueWith(task => bitmap.MarkAreas(task.Result)));
        }
Example #6
0
        public override async Task <Bitmap> Process()
        {
            if (OriginalImage == null)
            {
                return(await DefaultResult());
            }

            var clone1 = (Bitmap)OriginalImage.Clone();
            var clone2 = (Bitmap)OriginalImage.Clone();

            await Task.Run(() => clone1.ApplyMatrix3X3(_matrix1));

            await Task.Run(() => clone2.ApplyMatrix3X3(_matrix2));

            ProcessedImage = await Task.Run(() => clone1.ModifyColorsUsingBitmap(clone2,
                                                                                 (color1, color2) => MergeFirstColorWithSecond(color1, color2).Grayscale()));

            return(ProcessedImage);
        }
Example #7
0
 private void resetToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MakeEntireImageUndoable();
     Image = OriginalImage.Clone() as byte[];
     DrawImage();
 }
Example #8
0
        private void buttonCreateMeme_Click(object sender, RoutedEventArgs e)
        {
            var meme = new Meme();

            meme.textTop.Text    = TopText;
            meme.textBottom.Text = BottomText;
            meme.Owner           = this;
            meme.ShowDialog();
            if (String.IsNullOrWhiteSpace(TopText) && String.IsNullOrWhiteSpace(BottomText))
            {
                return;
            }
            var fontFamily = System.Drawing.FontFamily.Families.FirstOrDefault(ff => ff.Name == FontName);

            if (fontFamily == null)
            {
                fontFamily = System.Drawing.FontFamily.GenericSansSerif;
            }
            EditedImage           = (Bitmap)OriginalImage.Clone();
            Graphic               = Graphics.FromImage(EditedImage);
            Graphic.SmoothingMode = SmoothingMode.AntiAlias;
            int   pointSize       = 1;
            Font  font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
            SizeF lastMeasurement = SizeF.Empty;

            System.Drawing.Point drawPoint = System.Drawing.Point.Empty;
            GraphicsPath         path      = new GraphicsPath();

            if (!String.IsNullOrWhiteSpace(TopText))
            {
                while (lastMeasurement.Width < SourceSize.Width - 25 && pointSize < Settings.Current.MemeMaxFontSize)
                {
                    pointSize++;
                    font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
                    lastMeasurement = Graphic.MeasureString(TopText, font);
                }
                pointSize--;
                font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
                lastMeasurement = Graphic.MeasureString(TopText, font);
                drawPoint       = new System.Drawing.Point((int)(SourceSize.Width / 2), 0);
                path            = new GraphicsPath();
                path.AddString(TopText, fontFamily, (int)System.Drawing.FontStyle.Bold, Graphic.DpiY * pointSize / 72, drawPoint, new StringFormat()
                {
                    Alignment = StringAlignment.Center
                });
                Graphic.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, pointSize / 4), path);
                Graphic.FillPath(System.Drawing.Brushes.White, path);
                pointSize       = 1;
                font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
                lastMeasurement = SizeF.Empty;
            }

            if (!String.IsNullOrWhiteSpace(BottomText))
            {
                while (lastMeasurement.Width < SourceSize.Width - 25 && pointSize < Settings.Current.MemeMaxFontSize)
                {
                    pointSize++;
                    font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
                    lastMeasurement = Graphic.MeasureString(BottomText, font);
                }
                pointSize--;
                font            = new Font(fontFamily, pointSize, System.Drawing.FontStyle.Bold);
                lastMeasurement = Graphic.MeasureString(BottomText, font);
                drawPoint       = new System.Drawing.Point((int)(SourceSize.Width / 2), (int)SourceSize.Height - (int)lastMeasurement.Height);
                path            = new GraphicsPath();
                path.AddString(BottomText, fontFamily, (int)System.Drawing.FontStyle.Bold, Graphic.DpiY * pointSize / 72, drawPoint, new StringFormat()
                {
                    Alignment = StringAlignment.Center
                });
                Graphic.DrawPath(new System.Drawing.Pen(System.Drawing.Brushes.Black, pointSize / 4), path);
                Graphic.FillPath(System.Drawing.Brushes.White, path);
            }

            Graphic.Save();
            using (var ms = new MemoryStream())
            {
                EditedImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ImageSourceFrame = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
                imageMain.Source = ImageSourceFrame;
            }
        }
Example #9
0
        private void ApplyEffectsBlackAndWhite()
        {
            System.Drawing.Bitmap             bmp;
            System.Drawing.Imaging.BitmapData bmData;
            System.IntPtr ptr;
            int           nOffSet, x, y, tamanho, red, blue, green;
            byte          bVal;

            bmp    = (System.Drawing.Bitmap)OriginalImage.Clone();
            bmData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            ptr    = bmData.Scan0;
            switch (m_enumEffectDirection)
            {
            case PictureBox.Directions.Horizontal:
                nOffSet = bmp.Height;
                tamanho = (int)((bmp.Width * m_nPercentage) / 100);
                for (y = 0; y < bmp.Height; y++)
                {
                    for (x = 0; x < bmData.Width + 1; x++)
                    {
                        if (x >= tamanho)
                        {
                            blue  = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 0);
                            green = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 1);
                            red   = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 2);
                            bVal  = (byte)(0.299 * red + 0.587 * green + 0.114 * blue);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 0, bVal);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 1, bVal);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 2, bVal);
                        }
                        ptr = new System.IntPtr(ptr.ToInt32() + 3);
                    }
                    ptr = bmData.Scan0;
                    ptr = new System.IntPtr(ptr.ToInt32() + (bmData.Stride * y));
                }
                ptr = new System.IntPtr(ptr.ToInt32() + nOffSet);
                break;

            case PictureBox.Directions.Vertical:
                nOffSet = bmData.Stride - bmp.Width * 3;
                tamanho = (int)((bmp.Height * m_nPercentage) / 100);
                for (y = tamanho; y < bmp.Height - 1; y++)
                {
                    for (x = 0; x < bmp.Width - 1; x++)
                    {
                        blue  = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 0);
                        green = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 1);
                        red   = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 2);
                        bVal  = (byte)(0.299 * red + 0.587 * green + 0.114 * blue);
                        System.Runtime.InteropServices.Marshal.WriteByte(ptr, 0, bVal);
                        System.Runtime.InteropServices.Marshal.WriteByte(ptr, 1, bVal);
                        System.Runtime.InteropServices.Marshal.WriteByte(ptr, 2, bVal);
                        ptr = new System.IntPtr(ptr.ToInt32() + 3);
                    }
                }
                ptr = new System.IntPtr(ptr.ToInt32() + nOffSet);
                break;

            case PictureBox.Directions.FromOutsideToInside:
                int nLeft = 0, nTop, nRight, nButton;
                nLeft   = 20;
                nTop    = nLeft;
                nTop    = 20;
                nRight  = bmp.Width - 20;
                nButton = bmp.Height - 20;
                nOffSet = (bmp.Width - 1) * 3;
                for (y = 0; y < bmp.Height - 1; y++)
                {
                    if ((nTop <= y) && (y <= nButton))
                    {
                        for (x = 0; x < bmp.Width - 1; x++)
                        {
                            blue  = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 0);
                            green = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 1);
                            red   = System.Runtime.InteropServices.Marshal.ReadByte(ptr, 2);
                            bVal  = (byte)(0.299 * red + 0.587 * green + 0.114 * blue);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 0, bVal);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 1, bVal);
                            System.Runtime.InteropServices.Marshal.WriteByte(ptr, 2, bVal);
                            ptr = new System.IntPtr(ptr.ToInt32() + 3);
                        }
                    }
                    else
                    {
                        ptr = new System.IntPtr(ptr.ToInt32() + nOffSet);
                    }
                }
                break;
            }
            bmp.UnlockBits(bmData);
            this.Image = bmp;
            this.Refresh();
        }