当前位置: 首页>>代码示例>>C#>>正文


C# ImageAttributes.SetThreshold方法代码示例

本文整理汇总了C#中System.Drawing.Imaging.ImageAttributes.SetThreshold方法的典型用法代码示例。如果您正苦于以下问题:C# ImageAttributes.SetThreshold方法的具体用法?C# ImageAttributes.SetThreshold怎么用?C# ImageAttributes.SetThreshold使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Imaging.ImageAttributes的用法示例。


在下文中一共展示了ImageAttributes.SetThreshold方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Threshold

        public static Bitmap Threshold(Image bitmap, int thresholdValue)
        {
            ColorMatrix grayscale =  new ColorMatrix(new float[][]{
                new float[]{ 0.30f, 0.30f,  0.30f,  0,  0},
                new float[]{ 0.59f, 0.59f,  0.59f,  0,  0},
                new float[]{ 0.11f, 0.11f,  0.11f,  0,  0},
                new float[]{ 0,     0,      0,      1,  0},
                new float[]{ 0,     0,      0,      0,  1}});

            ImageAttributes attrib = new ImageAttributes();

            attrib.SetColorMatrix(grayscale);
            attrib.SetThreshold(thresholdValue / 255.0f);

            Rectangle dimensions = new Rectangle(0,0, bitmap.Width, bitmap.Height);
            Bitmap output = new Bitmap(dimensions.Width, dimensions.Height, PixelFormat.Format32bppArgb);

            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(output))
            {
                g.DrawImage(bitmap, dimensions, 0, 0, dimensions.Width, dimensions.Height,
                    GraphicsUnit.Pixel, attrib);
            }

            return output;
        }
开发者ID:fpicalausa,项目名称:mangareader,代码行数:25,代码来源:Graphics.cs

示例2: Threshold

        public static Bitmap Threshold(Bitmap original)
        {
            int width = original.Width;
            int height = original.Height;
            Bitmap bmp = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                ImageAttributes threshold = new ImageAttributes();
                threshold.SetThreshold(0.92f);
                //attributes.SetThreshold(0.08f);

                g.DrawImage(original, new Rectangle(0, 0, width, height),
                    0, 0, width, height, GraphicsUnit.Pixel, threshold);

                ImageAttributes invert = new ImageAttributes();
                ColorMap[] map = new ColorMap[2];
                map[0] = new ColorMap();
                map[0].OldColor = Color.Black;
                map[0].NewColor = Color.White;
                map[1] = new ColorMap();
                map[1].OldColor = Color.White;
                map[1].NewColor = Color.Black;
                invert.SetRemapTable(map);

                g.DrawImage(bmp, new Rectangle(0, 0, width, height),
                    0, 0, width, height, GraphicsUnit.Pixel, invert);
            }
            return bmp;
        }
开发者ID:notox,项目名称:Hello-World,代码行数:29,代码来源:Processor.cs

示例3: ConvertToBlackAndWhite

        public void ConvertToBlackAndWhite(Bitmap sourceImage)
        {
            using (Graphics gr = Graphics.FromImage(sourceImage)) // SourceImage is a Bitmap object
            {
                var gray_matrix = new float[][] {
                new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                new float[] { 0,      0,      0,      1, 0 },
                new float[] { 0,      0,      0,      0, 1 }
            };

                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix));
                ia.SetThreshold(0.8f); // Change this threshold as needed
                var rc = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
                gr.DrawImage(sourceImage, rc, 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, ia);
            }
        }
开发者ID:NMBS-FALLON,项目名称:DESign,代码行数:19,代码来源:ImageOperations.cs

示例4: BitmapToMonochrome

        /// <summary>
        /// Convierte el bitmap a blanco y negro utilzando un threshold específico.
        /// </summary>
        /// <param name="sourceImage">Imagen fuente</param>
        /// <param name="threshold">Threshold que se utilizara para determinar si un pixel es blanco o negro</param>
        public static Bitmap BitmapToMonochrome(Bitmap sourceImage, float threshold)
        {
            using (Graphics gr = Graphics.FromImage(sourceImage)) // SourceImage is a Bitmap object
            {
                var gray_matrix = new float[][] {
                new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                new float[] { 0,      0,      0,      1, 0 },
                new float[] { 0,      0,      0,      0, 1 }
                };

                var ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix));
                ia.SetThreshold(threshold);
                var rc = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
                gr.DrawImage(sourceImage, rc, 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, ia);
            }

            return sourceImage;
        }
开发者ID:Celtc,项目名称:KanjiRecognizer,代码行数:26,代码来源:ImageAPI.cs

示例5: MakeGrayscale

        public static Bitmap MakeGrayscale(Bitmap original)
        {
            using (var gr = Graphics.FromImage(original))
            {
                var grayMatrix = new[]
                                      {
                                          new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                                          new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                                          new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                                          new float[] { 0, 0, 0, 1, 0 },
                                          new float[] { 0, 0, 0, 0, 1 }
                                      };

                var ia = new ImageAttributes();
                ia.SetColorMatrix(new ColorMatrix(grayMatrix));
                ia.SetThreshold(0.8f); // Change this threshold as needed
                var rc = new Rectangle(0, 0, original.Width, original.Height);
                gr.DrawImage(original, rc, 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
            }

            return original;
        }
开发者ID:dziedrius,项目名称:osd-gs,代码行数:22,代码来源:MainForm.cs

示例6: ThresholdImage

        /// <summary>
        /// Threshold the image using the given value.
        /// </summary>
        /// <param name="source image ( will be overwritten with thresholded image)"></param>
        /// <param name="the threshold value ( 0..1)"></param>
        public static void ThresholdImage(Image source, float t)
        {
            // create image attributes to blit image into itself with.

            ImageAttributes ia = new ImageAttributes();

            ia.SetThreshold(t);

            // get a graphics for source image

            Graphics g = Graphics.FromImage(source);

            // set compositing mode to copy over

            g.CompositingMode = CompositingMode.SourceCopy;

            // turn off aliasing etc

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            g.SmoothingMode = SmoothingMode.None;

            // create destination rectangle

            Rectangle d = new Rectangle(0, 0, source.Width, source.Height);

            // paint into self

            g.DrawImage(source, d, 0, 0, source.Width, source.Height, GraphicsUnit.Pixel, ia);

            // cleanup

            ia.Dispose();

            g.Dispose();
        }
开发者ID:duncanmeech,项目名称:RedEye,代码行数:41,代码来源:ImageUtility.cs

示例7: Form1_KeyDown

 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     switch (e.KeyCode)
     {
         // 리셋
         case Keys.Space:
             Attr = new ImageAttributes();
             Src = Image.FromFile("오솔길.jpg");
             Threshold = 0.5f;
             Gamma = 1.0f;
             Bright = 0.0f;
             break;
         // 시계 방향 회전
         case Keys.Right:
             Src.RotateFlip(RotateFlipType.Rotate90FlipNone);
             break;
         // 반시계 방향 회전
         case Keys.Left:
             Src.RotateFlip(RotateFlipType.Rotate270FlipNone);
             break;
         // 수평 뒤집기
         case Keys.Up:
             Src.RotateFlip(RotateFlipType.RotateNoneFlipX);
             break;
         // 수직 뒤집기
         case Keys.Down:
             Src.RotateFlip(RotateFlipType.RotateNoneFlipY);
             break;
         // 스레시 홀드 증감
         case Keys.Q:
             if (Threshold < 1) Threshold += 0.1f;
             Attr.SetThreshold(Threshold);
             break;
         case Keys.W:
             if (Threshold > 0) Threshold -= 0.1f;
             Attr.SetThreshold(Threshold);
             break;
         // 감마 증감
         case Keys.E:
             if (Gamma < 5.0) Gamma += 0.1f;
             Attr.SetGamma(Gamma);
             break;
         case Keys.R:
             if (Gamma > 0.1) Gamma -= 0.1f;
             Attr.SetGamma(Gamma);
             break;
         // 밝게
         case Keys.D1:
             if (Bright < 1.0f) Bright += 0.1f;
             float[][] M1 = {
                 new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {Bright, Bright, Bright, 0.0f, 1.0f},
             };
             ColorMatrix Mat1 = new ColorMatrix(M1);
             Attr.SetColorMatrix(Mat1);
             break;
         // 어둡게
         case Keys.D2:
             if (Bright > -1.0f) Bright -= 0.1f;
             float[][] M2 = {
                 new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {Bright, Bright, Bright, 0.0f, 1.0f},
             };
             ColorMatrix Mat2 = new ColorMatrix(M2);
             Attr.SetColorMatrix(Mat2);
             break;
         // 반전
         case Keys.D3:
             float[][] M3 = {
                 new float[] {-1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, -1.0f, 0.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, -1.0f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
             };
             ColorMatrix Mat3 = new ColorMatrix(M3);
             Attr.SetColorMatrix(Mat3);
             break;
         // 그레이 스케일
         case Keys.D4:
             float[][] M4 = {
                 new float[] {0.299f, 0.299f, 0.299f, 0.0f, 0.0f},
                 new float[] {0.587f, 0.587f, 0.587f, 0.0f, 0.0f},
                 new float[] {0.114f, 0.114f, 0.114f, 0.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                 new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
             };
             ColorMatrix Mat4 = new ColorMatrix(M4);
             Attr.SetColorMatrix(Mat4);
             break;
         case Keys.D5:
             ColorMap[] Map = new ColorMap[1];
             Map[0] = new ColorMap();
             Map[0].OldColor = Color.White;
//.........这里部分代码省略.........
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:101,代码来源:Form1.cs

示例8: ChangeColor

        /// <summary>
        /// イメージを2値化する
        /// </summary>
        /// <param name="sourceImage"></param>
        /// <returns></returns>
        private Bitmap ChangeColor(Bitmap sourceImage)
        {
            //RGBの比率(YIQカラーモデル)
            const float r = 1.0F;
            const float g = 1.0F;
            const float b = 1.0F;

            //ColorMatrixにセットする行列を 5 * 5 の配列で用意
            //入力のRGBの各チャンネルを重み付けをした上で、
            //出力するRGBがR = G = B となるような行列をセット
            float[][] matrixElement =
                      {new float[]{r, r, r, 0, 0},
                       new float[]{g, g, g, 0, 0},
                       new float[]{b, b, b, 0, 0},
                       new float[]{0, 0, 0, 1, 0},
                       new float[]{0, 0, 0, 0, 1}};

            //ColorMatrixオブジェクトの作成
            ColorMatrix matrix = new ColorMatrix(matrixElement);

            //ImageAttributesにセット
            ImageAttributes attr = new ImageAttributes();
            attr.SetColorMatrix(matrix);

            //閾値の設定
            attr.SetThreshold(0.5F);    //50%を指定

            int imageWidth = sourceImage.Width;
            int imageHeight = sourceImage.Height;

            //新しいビットマップを用意
            Bitmap changedImage = new Bitmap(imageWidth, imageHeight);

            //新しいビットマップにImageAttributesを指定して
            //元のビットマップを描画
            Graphics graph = Graphics.FromImage(changedImage);

            graph.DrawImage(sourceImage,
                            new Rectangle(0, 0, imageWidth, imageHeight),
                            0, 0, imageWidth, imageHeight,
                            GraphicsUnit.Pixel,
                            attr);

            graph.Dispose();

            return changedImage;
        }
开发者ID:masahoshiro,项目名称:FinalFantasyXIV_ARR_Tools,代码行数:52,代码来源:RankingForm.cs

示例9: monochrome

        public static void monochrome(Bitmap image)
        {
            using (Graphics g = Graphics.FromImage(image))
            {
                var gray_matrix = new float[][]
                {
                    new float[] { 0.299f, 0.299f, 0.299f, 0, 0 },
                    new float[] { 0.587f, 0.587f, 0.587f, 0, 0 },
                    new float[] { 0.114f, 0.114f, 0.114f, 0, 0 },
                    new float[] { 0,      0,      0,      1, 0 },
                    new float[] { 0,      0,      0,      0, 1 }
                };

                var imageAttrib = new System.Drawing.Imaging.ImageAttributes();
                imageAttrib.SetColorMatrix(new System.Drawing.Imaging.ColorMatrix(gray_matrix));
                imageAttrib.SetThreshold((float)0.7);
                var rec = new Rectangle(0, 0, image.Width, image.Height);
                g.DrawImage(image, rec, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttrib);
            }

        }
开发者ID:njruiz,项目名称:ThesisIT,代码行数:21,代码来源:Preprocesses.cs

示例10: ChangeColour

        private Bitmap ChangeColour(Bitmap original, ColorMatrix colorMatrix, bool setThresholdForBitonal)
        {
            //create a blank bitmap the same size as original
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);

            //get a graphics object from the new image
            Graphics g = Graphics.FromImage(newBitmap);

            //create some image attributes
            ImageAttributes attributes = new ImageAttributes();

            //set the color matrix attribute
            attributes.SetColorMatrix(colorMatrix);

            // if the image is required is bitonal set a threshold
            if (setThresholdForBitonal)
                attributes.SetThreshold(0.75f);

            //draw the original image on the new image
            //using the grayscale color matrix
            g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
               0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

            //dispose the Graphics object
            g.Dispose();

            return newBitmap;
        }
开发者ID:britishlibrary,项目名称:SanddragonImageService,代码行数:28,代码来源:ImageHandler.ashx.cs

示例11: createGreyValPic

        public void createGreyValPic(string eingabe_in)
        {
            Color oldColor, greyColor;
            Bitmap helpMap, greyMap;
            int width, height, i, j, greyValue;

            //neue Instanz anlegen, sonst bekommt man eine Zugriffsverletzung
            helpMap = new Bitmap(bildPicturebox.Image);

            width = helpMap.Width;      //Bildbreite bestimmen
            height = helpMap.Height;    //Bildhöhe bestimmen
            greyMap = new Bitmap(width, height);        //Bitmap für das Grauwertbild erstellen

            form1ProgressBar.Invoke(new Action(() =>
            {
                form1ProgressBar.Maximum = height;
                form1ProgressBar.Visible = true;
                form1ProgressBar.Value = 0;
            }));

            for (j = 0; j < height; j++)      //Schleife zum durchlaufen der Bitmap in der  Breite
            {
                for (i = 0; i < width; i++)     //Schleife zum durchlaufen der Bitmap in der Höhe
                {
                    oldColor = helpMap.GetPixel(i, j);      //Farbwert bestimmen
                    greyValue = (int)(0.3 * oldColor.R + 0.6 * oldColor.G + 0.1 * oldColor.B);     //Grauwert berechnen
                    greyColor = Color.FromArgb(greyValue, greyValue, greyValue);        //Colorvariable aus Grauwert erzeugen
                    greyMap.SetPixel(i, j, greyColor);      //Farbe(Grau) setzen
                }

                //falls die bearbeitung abgebrochen wird
                if (grauwertBW.CancellationPending)
                    return;

                grauwertBW.ReportProgress(j);
            }

            //Berechnung des Schwarz-Weiß Bildes
            if (eingabe_in != "grau")
            {
                Graphics gr = Graphics.FromImage(greyMap);
                ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes();
                ia.SetThreshold(0.5f); // Change this threshold as needed
                Rectangle rc = new Rectangle(0, 0, width, height);
                gr.DrawImage(greyMap, rc, 0, 0, width, height, GraphicsUnit.Pixel, ia);
            }

            GC.Collect();

            if (grauwertBW.CancellationPending)
                return;

            bildPicturebox.Invoke(new Action(() =>
            {
                setAndSavePictureBox(greyMap);
            }));
        }
开发者ID:Julius1990,项目名称:Prog3,代码行数:57,代码来源:Form1.cs


注:本文中的System.Drawing.Imaging.ImageAttributes.SetThreshold方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。