Example #1
0
        public static ImageInfo GetImageInformation(string fileName)
        {
            var result = new ImageInfo();

            result.Width  = 0;
            result.Height = 0;
            result.FormattedDimensions = "unknown";
            result.FormattedSize       = "unknown";
            result.SizeInBytes         = 0;

            var fullName = string.Empty;

            if (fileName != null)
            {
                fullName = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, fileName.Replace("/", "\\"));
            }


            if (File.Exists(fullName))
            {
                var f = new FileInfo(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, fileName));
                if (f != null)
                {
                    result.SizeInBytes = f.Length;
                    if (result.SizeInBytes < 1024)
                    {
                        result.FormattedSize = result.SizeInBytes + " bytes";
                    }
                    else
                    {
                        if (result.SizeInBytes < 1048576)
                        {
                            result.FormattedSize = Math.Round(result.SizeInBytes / 1024, 1) + " KB";
                        }
                        else
                        {
                            result.FormattedSize = Math.Round(result.SizeInBytes / 1048576, 1) + " MB";
                        }
                    }
                }
                f = null;

                if (File.Exists(fullName))
                {
                    Image WorkingImage;
                    WorkingImage = Image.FromFile(fullName);
                    if (WorkingImage != null)
                    {
                        result.Width  = WorkingImage.Width;
                        result.Height = WorkingImage.Height;
                        result.FormattedDimensions = result.Width.ToString(CultureInfo.InvariantCulture) + " x " +
                                                     result.Height.ToString(CultureInfo.InvariantCulture);
                    }
                    WorkingImage.Dispose();
                    WorkingImage = null;
                }
            }

            return(result);
        }
Example #2
0
        public static bool CompressJpeg(string filePath, long quality)
        {
            bool   result   = true;
            string fullFile = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, filePath);

            if (File.Exists(fullFile) == true)
            {
                if (quality < 1L)
                {
                    quality = 1L;
                }
                else
                {
                    if (quality > 100L)
                    {
                        quality = 100L;
                    }
                }

                System.Drawing.Image WorkingImage;
                WorkingImage = System.Drawing.Image.FromFile(filePath);

                System.Drawing.Image FinalImage;
                FinalImage = new System.Drawing.Bitmap(WorkingImage.Width, WorkingImage.Height, PixelFormat.Format24bppRgb);

                Graphics G = Graphics.FromImage(FinalImage);
                G.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                G.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                G.CompositingQuality = CompositingQuality.HighQuality;
                G.SmoothingMode      = SmoothingMode.HighQuality;
                G.DrawImage(WorkingImage, 0, 0, WorkingImage.Width, WorkingImage.Height);

                // Dispose working Image so we can save with the same name
                WorkingImage.Dispose();
                WorkingImage = null;

                // Compression Code
                ImageCodecInfo    myCodec         = GetEncoderInfo("image/jpeg");
                Encoder           myEncoder       = Encoder.Quality;
                EncoderParameters myEncoderParams = new EncoderParameters(1);
                EncoderParameter  myParam         = new EncoderParameter(myEncoder, quality);
                myEncoderParams.Param[0] = myParam;
                // End Compression Code

                File.Delete(fullFile);
                FinalImage.Save(fullFile, myCodec, myEncoderParams);
                FinalImage.Dispose();
                FinalImage = null;
            }
            else
            {
                result = false;
            }

            return(result);
        }
Example #3
0
        private void DrawAndDisplayImage()
        {
            if (HeadPoint.IsEmpty)
            {
                using (Image <Bgr, byte> img = WorkingImage.Convert <Bgr, byte>())
                {
                    DisplayImage = ImageService.ToBitmapSource(img);
                }

                return;
            }

            using (Image <Bgr, byte> img = WorkingImage.Convert <Bgr, byte>())
            {
                img.DrawPolyline(BodyContour, true, new Bgr(Color.Yellow));
                img.Draw(new CircleF(HeadPoint, 2), new Bgr(Color.Red));
                PointF midPoint = HeadPoints[1].MidPoint(HeadPoints[3]);
                img.Draw(new LineSegment2DF(midPoint, HeadPoint), new Bgr(Color.Red), 1);

                if (FinalWhiskers != null)
                {
                    if (FinalWhiskers.LeftWhiskers != null && FinalWhiskers.LeftWhiskers.Any())
                    {
                        //currentFrame.Draw(cWhiskers.LeftWhiskers[5].Line, new Bgr(Color.White), 1);

                        foreach (IWhiskerSegment whisker in FinalWhiskers.LeftWhiskers)
                        {
                            Color color = Color.White;
                            img.Draw(whisker.Line, new Bgr(color), 1);
                        }
                    }

                    if (FinalWhiskers.RightWhiskers != null && FinalWhiskers.RightWhiskers.Any())
                    {
                        foreach (IWhiskerSegment whisker in FinalWhiskers.RightWhiskers)
                        {
                            Color color = Color.White;
                            img.Draw(whisker.Line, new Bgr(color), 1);
                        }
                    }
                }

                DisplayImage = ImageService.ToBitmapSource(img);
            }
        }
Example #4
0
        private void UpdateFrameImage()
        {
            WorkingImage = Video.GetGrayFrameImage();
            PointF[] headPoints;
            Point[]  bodyPoints;
            Rbsk.GetHeadAndBody(WorkingImage.Convert <Bgr, byte>(), out headPoints, out bodyPoints);

            HeadPoints = headPoints;
            if (headPoints == null)
            {
                HeadPoint = PointF.Empty;
            }
            else
            {
                HeadPoint = headPoints[2];
            }

            BodyContour = bodyPoints;
            DrawAndDisplayImage();
        }
Example #5
0
        private void Preview()
        {
            using (Image <Gray, byte> gray = WorkingImage.Convert <Gray, byte>())
            {
                Whiskers = Rbsk.ProcessWhiskersForSingleFrame(gray, HeadPoints, BodyContour);

                if (WhiskerSettings.RemoveDuds)
                {
                    FinalWhiskers = ModelResolver.Resolve <IWhiskerCollection>();
                    PointF midPoint    = HeadPoints[1].MidPoint(HeadPoints[3]);
                    Vector orientation = new Vector(HeadPoint.X - midPoint.X, HeadPoint.Y - midPoint.Y);
                    PostProcessWhiskers2(midPoint, orientation, Whiskers, FinalWhiskers);
                }
                else
                {
                    FinalWhiskers = Whiskers;
                }
            }


            PreviewGenerated = true;
            DrawAndDisplayImage();
        }
        private void відкритиToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileWindow = new OpenFileDialog();

            if (openFileWindow.ShowDialog() == DialogResult.OK)
            {
                Bitmap bmp = new Bitmap(openFileWindow.FileName);

                //storing image info
                WorkingImage.Clear();
                WorkingImage.Add(BitmapConverter.BitmapToDoubleRgb(bmp));
                ImageName = Path.GetFileNameWithoutExtension(openFileWindow.FileName);
                toolStripStatusLabel1.Text = ImageName;

                LogOutputTextBox.Text += "Відкрито зображення \"" + ImageName + "\"" + Environment.NewLine + "Ширина зображення :" + bmp.Width + Environment.NewLine + "Висота зображення:" + bmp.Height + Environment.NewLine;
                //fill fields with image height and width
                //textBox1.Text = String.Format("Ширина: {0}{2}Висота: {1}", bmp.Width, bmp.Height, Environment.NewLine);
                //SubdivisionWidthTextBox.Text = bmp.Width.ToString();
                //SubdivisionHeightTextBox.Text = bmp.Height.ToString();

                OutputBitmapOnPictureBox(bmp);
                textBox4.Text = "" + WorkingImage.Count;
            }
        }