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


C# Bitmap.GetPixel方法代码示例

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


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

示例1: Start

	// Use this for initialization
	void Start () {


        Bitmap bitmap = new Bitmap("man_ok.png");

        Texture2D tex2D = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false);
        tex2D.name = Path.GetFileNameWithoutExtension("man_ok.png");

        for (int row = 0; row < bitmap.Height; row++)
        {
            for (int col = 0; col < bitmap.Width; col++)
            {
                System.Drawing.Color srcColor = bitmap.GetPixel(col, row);
                UnityEngine.Color tgtColor = new UnityEngine.Color(srcColor.R, srcColor.G, srcColor.B, srcColor.A);
                tex2D.SetPixel(col, row, tgtColor);
            }
        }

        renderer.material.mainTexture = tex2D;

        System.Drawing.Color srcColor1 = bitmap.GetPixel(100, 100);
        UnityEngine.Color tgtColor1 = new UnityEngine.Color(srcColor1.R, srcColor1.G, srcColor1.B, srcColor1.A);
        Debug.Log(tgtColor1.ToString());
        Debug.Log(srcColor1.ToString());

        tex2D.Apply();

        // AssetDatabase.CreateFolder("", "hello");
         //AssetDatabase.CreateAsset(tex2D, "dragon.asset");
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:31,代码来源:ConvertFileToAsset.cs

示例2: ProcessColorMatrix

	public static Color ProcessColorMatrix (Color color, ColorMatrix colorMatrix)
	{
		Bitmap bmp = new Bitmap (64, 64);
		Graphics gr = Graphics.FromImage (bmp);
		ImageAttributes imageAttr = new ImageAttributes ();

		bmp.SetPixel (0,0, color);

		imageAttr.SetColorMatrix (colorMatrix);
		gr.DrawImage (bmp, new Rectangle (0, 0, 64,64), 0,0, 64,64, GraphicsUnit.Pixel, imageAttr);

		Console.WriteLine ("{0} - > {1}", color,  bmp.GetPixel (0,0));
		return bmp.GetPixel (0,0);

	}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:ColorMatrix.cs

示例3: setJointLocations

    /******************************************************************************/

    public UInt16[] setJointLocations(Point p, Bitmap myBitmap)
    {
        //make new square around point
        Rectangle rec = new Rectangle(((p.X)-2), ((p.Y)-2), 5, 5);
        Point[] recPoints = new Point[3];
        recPoints[0] = new Point (rec.X,rec.Y);
        recPoints[0] = new Point(rec.X+rec.Width, rec.Y);
        recPoints[0] = new Point(rec.X+rec.Width, rec.Y+rec.Height);
        recPoints[0] = new Point(rec.X, rec.Y+rec.Height);
        UInt16[] predictionValues = new UInt16[200];
        //create random offset point pairs 200 times

        for (int i = 0; i<200; i++)
        {
        // make sure random points stay in x and y range of rextangle around point
            int offsetX = ran.Next(rec.X, rec.X + rec.Width);
            int offsetY = ran.Next(rec.Y, rec.Y + rec.Height);
            Point newPoint = new Point(offsetX,offsetY);


            int offsetX2 = ran.Next(rec.X, rec.X + rec.Width);
            int offsetY2 = ran.Next(rec.Y, rec.Y + rec.Height);
            Point newPoint2 = new Point(offsetX, offsetY);
            // Double check to make sure its in polygon
            if (IsPointInPolygon(recPoints, newPoint) && IsPointInPolygon(recPoints, newPoint))
            {

                /***********possible need for conversion to greyscale?******/

                Color pixelColour = myBitmap.GetPixel(offsetX, offsetY);
                Color pixelColour2 = myBitmap.GetPixel(offsetX2, offsetY2);
                int valueOne = pixelColour.ToArgb();
                int valueTwo = pixelColour2.ToArgb();

                int prediction = valueOne - valueTwo;
                //        UInt16 conValueOne = Convert.ToUInt16(valueOne);
                //       UInt16 convalueTwo = Convert.ToUInt16(valueOne);


                UInt16 predictionValue = Convert.ToUInt16(prediction);
                
                predictionValues[i] = predictionValue;
                //UInt16 grayValue1 = Grayscale(pixelColour.ToArgb());
            }
        }
        return predictionValues;
            
    }
开发者ID:Rhamill7,项目名称:kinectv2,代码行数:50,代码来源:Tracking.cs

示例4: AverageRectangle

    private static Color AverageRectangle(Bitmap src, int x, int y, int width, int height)
    {
        if (x < 0)
            x = 0;
        if (x + width >= src.Width)
            width = src.Width - x - 1;

        if (y < 0)
            y = 0;
        if (y + height >= src.Height)
            height = src.Height - y - 1;

        if (width <= 0 || height <= 0)
            return Color.Black;

        var clr = default(Color);
        var r = 0;
        var g = 0;
        var b = 0;

        for (var i = 0; i <= height - 1; i++)
            for (var j = 0; j <= width - 1; j++)
            {
                clr = src.GetPixel(x + j, y + i);
                r += clr.R;
                g += clr.G;
                b += clr.B;
            }

        r /= (width * height);
        g /= (width * height);
        b /= (width * height);

        return Color.FromArgb(255, r, g, b);
    }
开发者ID:PavilionVI,项目名称:Redact,代码行数:35,代码来源:Pixelate.cs

示例5: ImgCompare

    private static bool ImgCompare(Bitmap one, Bitmap two)
    {
        if(one.Width == two.Width && one.Height == two.Height)
        {
            int count = 0;

            for(int i = 0; i < one.Width; i++)
            {
                for(int j = 0; j < one.Height; j++)
                {
                    Color oneColor = one.GetPixel(i, j);
                    Color twoColor = two.GetPixel(i, j);

                    if(!SimilarColors(oneColor, twoColor))
                    {
                        count++;
                    }
                }
            }

            Console.WriteLine(count);
            if(count <=15000)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
开发者ID:dicknarby,项目名称:HomeMonitor,代码行数:35,代码来源:ImageChecker.cs

示例6: getArrayFromBitmap

 /// <summary>
 /// Creates byte array from vtkImageData
 /// </summary>
 /// <param name="bmp"></param>
 /// <returns></returns>
 public static byte[] getArrayFromBitmap(Bitmap bmp)
 {
     byte[] arr = new byte[bmp.Width * bmp.Height * numScalarComponents];
     int index = 0;
     for (int i = bmp.Height - 1; i >= 0; i--)
     {
         for (int j = 0; j < bmp.Width; j++)
         {
             arr[index++] = bmp.GetPixel(j, i).R;
             arr[index++] = bmp.GetPixel(j, i).G;
             arr[index++] = bmp.GetPixel(j, i).B;
             if (numScalarComponents > 3)
             {
                 arr[index++] = bmp.GetPixel(j, i).A;
             }
         }
     }
     return arr;
 }
开发者ID:richardbang83,项目名称:activizdotnet,代码行数:24,代码来源:vtkImageDataExtraTests.cs

示例7: smethod_1

 public static void smethod_1(string string_2)
 {
     RSAKey.init("(zB0F6]1(6RCw70lGQY7hA`uORr=5eE8AT<Dsa%@2>{ImO1Cs~3vi\"7&'oQ=j,H");
     Class24.string_0 = RSAKey.GetKeys(Class1.string_3);
     if (Class1.string_10 == "" && Class1.string_11 == "")
     {
         Class24.class23_4 = new Class23(Class24.string_0[0], 16);
         Class24.class23_5 = new Class23(Class24.string_0[1], 16);
     }
     else
     {
         Class24.class23_4 = new Class23(Class1.string_10, 16);
         Class24.class23_5 = new Class23(Class1.string_11, 16);
     }
     Class24.int_0 = Class24.smethod_7();
     Class24.string_1 = string_2;
     string text = Class6.smethod_3("url.prefix", false) + "/gamedata/supersecret?token=";
     if (Class1.string_9 != "")
     {
         text = Class1.string_9;
     }
     WebRequest webRequest = WebRequest.Create(text + string_2);
     webRequest.Headers[HttpRequestHeader.Cookie] = Class1.string_0;
     ((HttpWebRequest)webRequest).UserAgent = Class1.string_1;
     WebResponse response = webRequest.GetResponse();
     Image original = Image.FromStream(response.GetResponseStream());
     Bitmap bitmap = new Bitmap(original);
     int width = bitmap.Width;
     int height = bitmap.Height;
     Debug.WriteLine(text);
     int num = 0;
     byte[] array = new byte[width * height * 4];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             int num2 = bitmap.GetPixel(j, i).ToArgb();
             array[num++] = (byte)(num2 >> 24 & 255);
             array[num++] = (byte)(num2 >> 16 & 255);
             array[num++] = (byte)(num2 >> 8 & 255);
             array[num++] = (byte)(num2 & 255);
         }
     }
     string text2 = Class24.smethod_6(Class24.smethod_5(array), string_2);
     int num3 = (int)text2[0];
     text2 = text2.Substring(1);
     string value = text2.Substring(0, num3);
     text2 = text2.Substring(num3);
     int length = (int)text2[0];
     text2 = text2.Substring(1);
     string value2 = text2.Substring(0, length);
     Class24.class23_0 = new Class23(value, 10);
     Class24.class23_1 = new Class23(value2, 10);
     Class24.smethod_4();
 }
开发者ID:ZelkovaHabbo,项目名称:NF3_Compilable,代码行数:55,代码来源:Class24.cs

示例8: convertImageToGrayscale

 private System.Drawing.Image convertImageToGrayscale(System.Drawing.Image image)
 {
     Bitmap imageToConvert = new Bitmap(image);
     for (int y = 0; y < imageToConvert.Height; y++)
     {
         for (int x = 0; x < imageToConvert.Width; x++)
         {
             Color colour = imageToConvert.GetPixel(x, y);
             int luma = (int)(colour.R * 0.3 + colour.G * 0.59 + colour.B * 0.11);
             imageToConvert.SetPixel(x, y, Color.FromArgb(luma, luma, luma));
         }
     }
     return imageToConvert;
 }
开发者ID:mg393,项目名称:Kindle-Image-Converter,代码行数:14,代码来源:Default.aspx.cs

示例9: Main

 static void Main(string[] args)
 {
     Image imageOne = Image.FromFile("01.bmp");
     Image imageTwo = Image.FromFile("02.bmp");
     Bitmap bit01 = new Bitmap(imageOne);
     Bitmap bit02 = new Bitmap(imageTwo);
     double tmp = 0;
     //MSE Formula
     //(PIXEL 01 - PIXEL 02) ^2
     //sqrt((1/breite*höhe)*raus)
     for (int x = 0; x < bit01.Width; x++)
     {
         for (int y = 0; y < bit01.Height; y++)
         {
             byte gray01 = (byte)(0.299 * bit01.GetPixel(x,y).R + 0.587 * bit01.GetPixel(x,y).G + 0.114 * bit01.GetPixel(x,y).B);
             byte gray02 = (byte)(0.299 * bit02.GetPixel(x, y).R + 0.587 * bit02.GetPixel(x, y).G + 0.114 * bit02.GetPixel(x, y).B);
             tmp += Math.Pow(gray01 - gray02, 2);
         }
     }
     tmp = Math.Sqrt((1 / (double)bit01.Width * (double)bit01.Height) * (double)tmp);
     Console.WriteLine("MSE: " + tmp);
     Console.ReadLine();
 }
开发者ID:Kaifeck,项目名称:MultimediaProcessing,代码行数:23,代码来源:MSE.cs

示例10: GreyScaleImage

    public static void GreyScaleImage(Bitmap bitmap, string savePath)
    {
        for (int i = 0; i < bitmap.Width; i++)
        {
            for (int j = 0; j < bitmap.Height; j++)
            {
                Color pixel = bitmap.GetPixel(i, j);
                //Color newPixel = Color.FromArgb(pixel.G, pixel.B, pixel.R);
                int grayScale = (int)((pixel.R * 0.3) + (pixel.G * 0.59) + (pixel.B * 0.11));
                Color grey = Color.FromArgb(pixel.A, grayScale, grayScale, grayScale);
                bitmap.SetPixel(i, j, grey);
            }
        }

        bitmap.Save(savePath);
    }
开发者ID:iMitaka,项目名称:HackBulgaria,代码行数:16,代码来源:ImageToGrayscale.cs

示例11: img2array

    public float[] img2array(string location, int window = 1)
    {
        float[] grayscale;
           Image image = Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(location)));
           Bitmap img = new Bitmap(image, width, height);

           grayscale = new float[img.Width * img.Height];
           for (int x = 0; x < img.Width; x++)
           {
               for (int y = 0; y < img.Height; y++)
               {
                   Color oc = img.GetPixel(x, y);
                   grayscale[x * img.Height + y] = (255f-(float)(((0.299 * oc.R) + (0.587 * oc.G) + (0.114 * oc.B))));
               }
           }
           img.Dispose();
           image.Dispose();
           grayscale = normalize(grayscale, 0, 1);
           return grayscale;
    }
开发者ID:nikitozzz,项目名称:KCAPTCHA-Recognize,代码行数:20,代码来源:ImageProcess.cs

示例12: CreateImage

	public static void CreateImage (RotateFlipType rotate, int movex, int movey, string text, Bitmap dest, Graphics grdest)
	{
		Color clr;
		Bitmap	bmp = new Bitmap (80, 80, PixelFormat.Format32bppArgb);	
		Graphics gr = Graphics.FromImage (bmp);
		gr.Clear (Color.White);
		
		gr.DrawLine (p, 10.0F, 10.0F, 70.0F, 70.0F);
		gr.DrawLine (p, 10.0F, 15.0F, 70.0F, 15.0F);
		gr.DrawRectangle (p, 10.0F, 10.0F, 60.0F, 60.0F);				
		bmp.RotateFlip (rotate);		
		
		for (int y = 0; y < 80; y++) {
			for (int x = 0; x < 80; x++) {				
				clr = bmp.GetPixel (x,y);
				dest.SetPixel (x+movex, y+movey, clr);
			}
		}							
		
		grdest.DrawString (text, new Font ("Arial", 8), br,  movex+5, movey+85);		
	}
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:ImageRotateFlip.cs

示例13: Awake

 void Awake()
 {
     var gifImage = Image.FromFile(loadingGifPath);
     var dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
     int frameCount = gifImage.GetFrameCount(dimension);
     for (int i = 0; i < frameCount; i++)
     {
         gifImage.SelectActiveFrame(dimension, i);
         var frame = new Bitmap(gifImage.Width, gifImage.Height);
         System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, Point.Empty);
         var frameTexture = new Texture2D(frame.Width, frame.Height);
         for (int x = 0; x < frame.Width; x++)
             for (int y = 0; y < frame.Height; y++)
         {
             System.Drawing.Color sourceColor = frame.GetPixel(x, y);
             frameTexture.SetPixel(frame.Width - 1 - x, y, new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A)); // for some reason, x is flipped
         }
         frameTexture.Apply();
         gifFrames.Add(frameTexture);
     }
 }
开发者ID:sabotai,项目名称:oralPerspectives,代码行数:21,代码来源:AnimatedGifDrawer.cs

示例14: difference

    public float difference(Image OrginalImage, Image SecoundImage)
    {
        float percent = 0;
        try
        {
            float counter = 0;

            Bitmap bt1 = new Bitmap(OrginalImage);
            Bitmap bt2 = new Bitmap(SecoundImage);
            int size_H = bt1.Size.Height;
            int size_W = bt1.Size.Width;

            float total = size_H * size_W;

            Color pixel_image1;
            Color pixel_image2;

            for (int x = 0; x != size_W; x++)
            {

                for (int y = 0; y != size_H; y++)
                {
                    pixel_image1 = bt1.GetPixel(x, y);
                    pixel_image2 = bt2.GetPixel(x, y);

                    if (pixel_image1 != pixel_image2)
                    {
                        counter++;
                    }

                }

            }
            percent = (counter / total) * 100;

        }
        catch (Exception) { percent = 0; }

        return percent;
    }
开发者ID:sangnvus,项目名称:technical-docs,代码行数:40,代码来源:ScreenCapture.cs

示例15: Blur

    public static void Blur(Bitmap image, string savePath)
    {
        int blurSize = 5;
        Bitmap blurred = new Bitmap(image.Width, image.Height);
        Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
        using (Graphics graphics = Graphics.FromImage(blurred))
            graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),
                new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);

        for (int xx = rectangle.X; xx < rectangle.X + rectangle.Width; xx++)
        {
            for (int yy = rectangle.Y; yy < rectangle.Y + rectangle.Height; yy++)
            {
                int avgR = 0, avgG = 0, avgB = 0;
                int blurPixelCount = 0;
                for (int x = xx; (x < xx + blurSize && x < image.Width); x++)
                {
                    for (int y = yy; (y < yy + blurSize && y < image.Height); y++)
                    {
                        Color pixel = blurred.GetPixel(x, y);

                        avgR += pixel.R;
                        avgG += pixel.G;
                        avgB += pixel.B;

                        blurPixelCount++;
                    }
                }

                avgR = avgR / blurPixelCount;
                avgG = avgG / blurPixelCount;
                avgB = avgB / blurPixelCount;
                for (int x = xx; x < xx + blurSize && x < image.Width && x < rectangle.Width; x++)
                    for (int y = yy; y < yy + blurSize && y < image.Height && y < rectangle.Height; y++)
                        blurred.SetPixel(x, y, Color.FromArgb(avgR, avgG, avgB));
            }
        }
        blurred.Save(savePath);
    }
开发者ID:iMitaka,项目名称:HackBulgaria,代码行数:39,代码来源:LinearFilterToImage.cs


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