Example #1
0
        private void powerTransformMenuItem_Click(object sender, EventArgs e)
        {
            double pow  = double.Parse(paramsTextBox.Text);
            byte   fMax = SourceImage.Cast <byte>().Max();

            ApplyTransform((x) => FixRange((int)(255 * Math.Pow((double)x / fMax, pow))));
        }
        /// <summary>
        /// Create SourceImageViewModel for Detail View
        /// </summary>
        /// <param name="sourceImage">sourceImage</param>
        /// <returns>SourceImageViewModel with all data ready to be displayed</returns>
        public static SourceImageViewModel GetSourceImageViewModel(SourceImage sourceImage, List <ThumbImage> thumbs)
        {
            if (sourceImage == null)
            {
                return(null);
            }

            // Build sizes component
            StringBuilder sizes = new StringBuilder();

            foreach (ThumbImage thumb in thumbs)
            {
                sizes.Append(thumb.RelativePath);
                sizes.Append(" ");
                sizes.Append(thumb.Width);
                sizes.Append("w, ");
            }

            return(new SourceImageViewModel
            {
                ID = sourceImage.ID,
                FileName = sourceImage.FileName,
                AltText = sourceImage.AltText,
                FallbackPath = sourceImage.RelativePath,
                Width = sourceImage.Width.ToString(),
                Height = sourceImage.Height.ToString(),
                FileFormat = sourceImage.Format.ToString(),
                Thumbnails = thumbs,
                Metadata = sourceImage.Metadata,
                Sizes = sourceImage.Format == Format.SVG ? "" : sizes.ToString(),
                FileSize = sourceImage.FileSize.ToString(),
                HumanSize = sourceImage.getFileSize()
            });
        }
        private static SourceImage GetIntensityMap(SourceImage sourceImage, int workerMin, int range)
        {
            var newSourceImage = new SourceImage();

            newSourceImage.Height = sourceImage.Height;
            newSourceImage.Width  = sourceImage.Width;
            newSourceImage.Pixels = new Pixel[newSourceImage.Width * newSourceImage.Height];
            for (int y = 0; y < sourceImage.Height; y++)
            {
                for (int x = 0; x < sourceImage.Width; x++)
                {
                    Color c         = sourceImage.GetPixel(x, y);
                    var   intensity = (int)(c.GetBrightness() * 255);

                    if (intensity >= workerMin && intensity <= workerMin + range)
                    {
                        newSourceImage.SetPixel(x, y, c);
                    }
                    else
                    {
                        newSourceImage.SetPixel(x, y, Color.Black);
                    }
                }
            }

            return(newSourceImage);
        }
Example #4
0
        public override void OnDestroy()
        {
            base.OnDestroy();

            // force our image view to release its references to our bitmaps
            ImageView.SetImageBitmap(null);

            // free the resources we're done with
            if (SourceImage != null)
            {
                SourceImage.Dispose( );
                SourceImage = null;
            }

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

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

            // free the cropped image
            if (CroppedImage != null)
            {
                CroppedImage.Dispose( );
                CroppedImage = null;
            }

            SetMode(CropMode.None);
        }
Example #5
0
 public void Save(string filename)
 {
     if (IsReady)
     {
         SourceImage.Save(filename);
     }
 }
 public ImageSetterManipulator() : base(new CodedImage {
     Size = new Size(1, 1)
 })
 {
     SourceImage.Pixels[0] = ColorBytes.ToArgb(0, 255, 255, 255);
     SourceImage.CompletePalette();
 }
Example #7
0
 private void OpenButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (ResultImage.Image == null)
         {
             openFile.Filter = "Image Files(*.PNG)|*.PNG";
             if (openFile.ShowDialog() == DialogResult.OK)
             {
                 sFileName     = openFile.FileName;
                 FileName.Text = sFileName;
                 image         = new Bitmap(openFile.FileName);
                 if (image.Size.Height == 256 && image.Size.Width == 256)
                 {
                     SourceImage.Image = image;
                     SourceImage.Invalidate();
                     FileInfo imageInfo = new FileInfo(sFileName);
                     sourceSizeInKBytes = Convert.ToInt32(imageInfo.Length / 1024);
                 }
                 else
                 {
                     DialogResult rezult = MessageBox.Show("Incorrect image size! Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         else
         {
             DialogResult rezult = MessageBox.Show("You can't open image now.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch (Exception exception)
     {
         DialogResult rezult = MessageBox.Show("Error opening image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #8
0
        internal static long GetDrawingFitness(DnaDrawing newDrawing, SourceImage sourceImage, Bitmap bgImage, Bitmap fgImage)
        {
            long error = 0;

            if (bmp == null)
            {
                bmp = new Bitmap(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb);
                g   = Graphics.FromImage(bmp);
            }

            if (bgImage != null)
            {
                g.DrawImage(bgImage, 0, 0);
            }
            else
            {
                g.Clear(Color.Black);
            }


            Renderer.Render(newDrawing, g, 1);

            if (fgImage != null)
            {
                g.DrawImage(fgImage, 0, 0);
            }

            BitmapData bd = bmp.LockBits(
                new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
                ImageLockMode.ReadOnly,
                PixelFormat.Format32bppArgb);

            unchecked
            {
                unsafe
                {
                    fixed(Pixel *psourcePixels = sourceImage.Pixels)
                    {
                        int    partitionEnd = sourceImage.Height * sourceImage.Width;
                        var    p1           = (Pixel *)bd.Scan0.ToPointer();
                        Pixel *p2           = psourcePixels;

                        for (int i = 0; i < partitionEnd; i++, p1++, p2++)
                        {
                            int R = p1->R - p2->R;
                            int G = p1->G - p2->G;
                            int B = p1->B - p2->B;
                            error += R * R + G * G + B * B;
                        }
                    }
                }
            }

            bmp.UnlockBits(bd);


            // error += newDrawing.Polygons.Count * 3 ;
            return(error);
        }
Example #9
0
 public TileSourceImage()
 {
     // Test image for binding
     SourceImage = BitmapFactory.New(512, 512);
     // Closed green polyline with P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)
     int[] p = new int[] { 10, 5, 20, 40, 30, 30, 7, 8, 10, 5 };
     SourceImage.DrawPolyline(p, Colors.Green);
 }
Example #10
0
        private void MedianFilterMethod()
        {
            sw.Restart();
            this.SourceImage = Operations.MedianFilter((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
Example #11
0
 public void SetImage(string path)
 {
     ClearDataAndImages();
     SourceImageFullSize = new Image <Bgr, byte>(path);
     SourceImage         = ResizeImage(SourceImageFullSize.Mat, 50).ToImage <Bgr, byte>();
     //SourceImage = ResizeImage(SourceImage.Mat, 50).ToImage<Bgr, byte>();
     FinalPreviewImage = SourceImage.Copy().Mat;
 }
Example #12
0
 public void Dispose()
 {
     if (SourceImage != null)
     {
         SourceImage.Dispose();
         SourceImage = null;
     }
 }
Example #13
0
        public ActionResult DeleteConfirmed(int id)
        {
            SourceImage sourceImage = _db.SourceImages.Find(id);

            _db.SourceImages.Remove(sourceImage ?? throw new InvalidOperationException());
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #14
0
 private void SourceImageChanged()
 {
     if (SourceImage != null)
     {
         OriginalImage = SourceImage.Copy();
     }
     ProjectChanged();
 }
Example #15
0
 /// <summary>
 /// Gets the cropped image.
 /// </summary>
 /// <returns>WriteableBitmap</returns>
 public async Task <WriteableBitmap> GetCroppedBitmapAsync()
 {
     if (SourceImage == null)
     {
         return(null);
     }
     return(await SourceImage.GetCroppedBitmapAsync(_currentCroppedRect));
 }
Example #16
0
        /// <summary>
        /// Adds image(s) to project. Optionally it can also show open image dialog.
        /// </summary>
        private void AddImagesToProject(bool showDialog = false)
        {
            if (showDialog)
            {
                addImagesDialog.Multiselect      = true;
                addImagesDialog.RestoreDirectory = false;
                addImagesDialog.InitialDirectory = parentDirectory + "\\Renders\\";
                addImagesDialog.FilterIndex      = Model.AddImagesFilterIndex;
                if (addImagesDialog.ShowDialog(this) == DialogResult.OK)
                {
                    AddImagesToProject();
                }

                return;
            }

            // Note: as we keep dialog alive, we simply take the data from it. Not ideal way of doing things, but reduces the need to add additional state to the class or use separate function for handling.
            Model.AddImagesFilterIndex = addImagesDialog.FilterIndex;

            bool rejected = false;

            foreach (string file in addImagesDialog.FileNames)
            {
                bool found = false;
                for (int i = 0; i < Model.Images.Count; i++)
                {
                    if (file == Model.Images[i].Filename)
                    {
                        found    = true;
                        rejected = true;
                        break;
                    }
                }

                if (found)
                {
                    continue;
                }

                var image = new SourceImage(file);
                if (!image.IsImageValid)
                {
                    continue;
                }

                Model.Images.Add(image);
                imageForms.Add(new ImageForm {
                    MdiParent = this
                });
                projectListBox.Items.Add(Path.GetFileName(file).ToProjectItemTitle());
            }

            if (rejected == true)
            {
                MessageBox.Show("Duplicate files are not allowed", "Duplicates Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #17
0
        private void SobelEdgeDetectorMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.SobelEdgeDetector((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
Example #18
0
        private void HistogramEqualizationMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.HistogramEqualization((Bitmap)SourceImage.Clone());
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
        void addCroppedImages(List <Face> detectedFaces, List <UIImage> images = null)
        {
            croppedImages = images ?? new List <UIImage> ();

            foreach (var face in detectedFaces)
            {
                croppedImages.Add(SourceImage.Crop(face.FaceRectangle));
            }
        }
Example #20
0
 private void CreateCroppedImage()
 {
     CroppedImage = new Image <Rgba32>(CropArea.Width, CropArea.Height);
     CroppedImage = SourceImage.Clone(
         ctx => ctx.Resize(CropArea.Width, CropArea.Height, new SixLabors.ImageSharp.Processing.Processors.Transforms.BicubicResampler(), CropArea, new Rectangle(0, 0, CroppedImage.Width, CroppedImage.Height), true));
     if (CroppedImageRotationDegrees > 0.0)
     {
         CroppedImage.Mutate(i => i.Rotate(CroppedImageRotationDegrees));
     }
 }
Example #21
0
        public void SetImage(Bitmap image)
        {
            Image <Bgr, byte> img = image.ToImage <Bgr, byte>();

            ClearDataAndImages();
            SourceImageFullSize = img;
            SourceImage         = ResizeImage(SourceImageFullSize.Mat, 50).ToImage <Bgr, byte>();
            //SourceImage = ResizeImage(SourceImage.Mat, 50).ToImage<Bgr, byte>();
            FinalPreviewImage = SourceImage.Copy().Mat;
        }
Example #22
0
        /// <summary>
        /// Save the cropped image to a file.
        /// </summary>
        /// <param name="imageFile">The target file.</param>
        /// <param name="encoderId">The encoderId of BitmapEncoder</param>
        /// <returns></returns>
        public async Task SaveCroppedBitmapAsync(StorageFile imageFile, Guid encoderId)
        {
            if (SourceImage == null)
            {
                return;
            }
            var croppedBitmap = await SourceImage.GetCroppedBitmapAsync(_currentCroppedRect);

            await croppedBitmap.RenderToFile(imageFile, encoderId);
        }
Example #23
0
 public ActionResult Edit([Bind(Include = "ID,Path,AltText")] SourceImage sourceImage)
 {
     if (ModelState.IsValid)
     {
         _db.IsModified(sourceImage);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sourceImage));
 }
Example #24
0
 protected virtual void CopySourceImageCore()
 {
     ManipulatedImage.Size = SourceImage.Size;
     int[] sourcePixels, manipulatedPixels;
     using (SourceImage.LockPixels(out sourcePixels))
         using (ManipulatedImage.LockPixels(out manipulatedPixels))
         {
             sourcePixels.CopyTo(manipulatedPixels, 0);
         }
 }
Example #25
0
        private void HarrisMethod()
        {
            this.SourceImage = Operations.Grayscale((Bitmap)SourceImage.Clone());
            sw.Restart();
            this.SourceImage = Operations.HarrisCornerDetector((Bitmap)SourceImage.Clone());
            //this.SourceImage = Operations.Treshold((Bitmap)SourceImage.Clone(),135);
            sw.Stop();

            this.ElapsedTimeMessage = string.Format("A művelet időtartama: {0} ms.", sw.ElapsedMilliseconds);
        }
Example #26
0
 public Color ReadPixel(Point p)
 {
     if (IsReady)
     {
         if (p.X >= 0 && p.Y >= 0 && p.X < SourceImage.Width && p.Y < sourceImage.Height)
         {
             return(SourceImage.GetPixel(p.X, p.Y));
         }
     }
     return(Color.Empty);
 }
Example #27
0
        private static SourceImage GetSourceImage()
        {
            Bitmap bitmap = Resources.MonaLisa;
            var    image  = new SourceImage
            {
                Pixels = SetupSourceColorMatrix(bitmap),
                Width  = bitmap.Width,
                Height = bitmap.Height
            };

            return(image);
        }
 public void Fill(Point point)
 {
     if (MouseColor != null && point.X >= 0 && point.X < SourceImage.Size.Width && point.Y >= 0 && point.Y < SourceImage.Size.Height)
     {
         using (SuspendUpdateVisualImage())
             using (SourceImage.Palette.SuppressRemoveColorsWithoutOccurrences())
                 using (UndoRedo.BeginMultiActionsUndoRedoStep(UndoRedoProvider.UndoRedoActionFillRegion))
                 {
                     ImagePainter.Fill(SourceImage, MouseColor, point.X, point.Y);
                     SourceImage.TriggerImageChanged();
                 }
     }
 }
        protected override void OnUntouchedCore(Point imagePoint)
        {
            touchedPointerStyle = TouchPointerStyle.None;
            touchedPoint        = VisualZoomCropController.TouchPoint.None;
            touchedCell         = new Point(-1, -1);

            if (suspendImageChangedEventOnTouch)
            {
                SourceImage.TriggerImageChanged();
                suspendImageChangedEventOnTouch = false;
            }
            base.OnUntouchedCore(imagePoint);
        }
Example #30
0
        // GET: Image/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SourceImage sourceImage = _db.SourceImages.Find(id);

            if (sourceImage == null)
            {
                return(HttpNotFound());
            }
            return(View(sourceImage));
        }
Example #31
0
 public unsafe void Load(byte[] buffer)
 {
     if (buffer == null)
     {
         return;
     }
     string theString;
     fixed (byte* pBuffer = &buffer[0])
     {
         theString = BufferReader.ReadString(pBuffer, buffer.Length);
     }
     Tokenizer tokenizer = new Tokenizer(theString, _datExpressions, addNewLine: true);
     tokenizer.First();
     Tokenizer.Token token;
     Character currentCharacter;
     while ((token = tokenizer.Current()) != null)
     {
         if (token.Type == CommonParser.EXPRESSION_COMMENT || token.Type == Tokenizer.EXPRESSION_END_OF_LINE)
         {
             CommonParser.GoToValue(tokenizer);
             continue;
         }
         if (token.Type != Tokenizer.EXPRESSION_NUMBER)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
         }
         currentCharacter = new Character(uint.Parse(token.Value));
         if ((token = tokenizer.Next()).Type != EXPRESSION_IMAGE && token.Type != EXPRESSION_TEXTURE)
         {
             throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
         }
         ISource source = null;
         switch (token.Type)
         {
             case EXPRESSION_IMAGE:
                 SourceImage sourceImage = new SourceImage();
                 token = tokenizer.Next();
                 if (token.Type == EXPRESSION_SOURCE_STANDARD)
                 {
                     sourceImage.Type = SourceImageType.STANDARD;
                 }
                 else if (token.Type == EXPRESSION_SOURCE_CLASSIC)
                 {
                     sourceImage.Type = SourceImageType.CLASSIC;
                 }
                 else
                 {
                     throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", token);
                 }
                 sourceImage.X = int.Parse(token.Match.Groups["X"].Value);
                 sourceImage.Y = int.Parse(token.Match.Groups["Y"].Value);
                 sourceImage.Width = int.Parse(token.Match.Groups["Width"].Value);
                 sourceImage.Height = int.Parse(token.Match.Groups["Height"].Value);
                 source = sourceImage;
                 break;
             case EXPRESSION_TEXTURE:
                 SourceTexture sourceTexture = new SourceTexture();
                 token = tokenizer.Next();
                 if (token.Type != Tokenizer.EXPRESSION_NUMBER)
                 {
                     throw new OpenSAGEException(ErrorCode.AptParser, "Token '$TOKEN$' was not recognized", "token", tokenizer.Current());
                 }
                 sourceTexture.Id = int.Parse(token.Value);
                 source = sourceTexture;
                 break;
         }
         currentCharacter.Source = source;
         _characters.Add(currentCharacter);
         tokenizer.Next();
     }
 }