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


C# Bitmap.SetPixel方法代码示例

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


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

示例1: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        int x, y;
        string strValidation = null;
        rnd = new Random();
        Response.ContentType = "image/jpeg";
        Response.Clear();
        Response.BufferOutput = true;
        strValidation = GenerateString();
        Session["strValidation"] = strValidation;
        Font font = new Font("Arial", (float)rnd.Next(17, 20));

        Bitmap bitmap = new Bitmap(200, 50);
        Graphics gr = Graphics.FromImage(bitmap);
        gr.FillRectangle(Brushes.LightGreen, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
        gr.DrawString(strValidation, font, Brushes.Black, (float)rnd.Next(70), (float)rnd.Next(20));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
           // gr.DrawLine(new Pen(Color.White), new Point(0, rnd.Next(50)), new Point(200, rnd.Next(50)));
        for (x = 0; x < bitmap.Width; x++)
            for (y = 0; y < bitmap.Height; y++)
                if (rnd.Next(4) == 1)
                    bitmap.SetPixel(x, y, Color.LightGreen);
        font.Dispose();
        gr.Dispose();
        bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
        bitmap.Dispose();
    }
开发者ID:CaesaRBur,项目名称:WebProject,代码行数:28,代码来源:ImageValidation.aspx.cs

示例2: createImage

 private void createImage(string checkcode)
 {
     if(checkcode ==null||checkcode.Trim() ==string .Empty)
        return;
        Bitmap image = new Bitmap((int)Math.Ceiling(checkcode.Length * 13.1), 22);
        Graphics grahics = Graphics.FromImage(image);
        grahics.Clear(Color.White);
        Random random=new Random() ;
       for (int i = 0; i < 18; i++)
        {
        int x1 = random.Next(image.Width);
        int x2 = random.Next(image.Width);
        int y1 = random.Next(image.Height);
        int y2 = random.Next(image .Height );
        grahics.DrawLine(new Pen(Color.Silver),x1,y1,x2,y2);
        }
     Font font = new Font("Arial", 11, FontStyle.Bold);
        Brush brush = new SolidBrush(Color.Black);
        grahics.DrawString(checkcode ,font,brush ,3,3);
        for (int i = 0; i < 80; i++)
        {
        int width = random.Next(image.Width );
        int heigth = random.Next(image.Height );
        image.SetPixel(width ,heigth ,Color.Silver );
        }
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType="image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        grahics.Dispose();
        image.Dispose();
 }
开发者ID:silverDrops,项目名称:OA,代码行数:33,代码来源:CheckImage.aspx.cs

示例3: DecodeImage

        public static Bitmap DecodeImage(Layer layer)
        {
            if (layer.Rect.Width == 0 || layer.Rect.Height == 0) return null;

            Bitmap bitmap = new Bitmap(layer.Rect.Width, layer.Rect.Height, PixelFormat.Format32bppArgb);

            Parallel.For(0, layer.Rect.Height, y =>
            {
                Int32 rowIndex = y * layer.Rect.Width;

                for (Int32 x = 0; x < layer.Rect.Width; x++)
                {
                    Int32 pos = rowIndex + x;

                    Color pixelColor = GetColor(layer, pos);

                    if (layer.SortedChannels.ContainsKey(-2))
                    {
                        Int32 maskAlpha = GetColor(layer.MaskData, x, y);
                        Int32 oldAlpha = pixelColor.A;

                        Int32 newAlpha = (oldAlpha * maskAlpha) / 255;
                        pixelColor = Color.FromArgb(newAlpha, pixelColor);
                    }

                    lock (bitmap)
                    {
                        bitmap.SetPixel(x, y, pixelColor);
                    }
                }
            });

            return bitmap;
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:34,代码来源:ImageDecoder.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Form["width"] != null && Request.Form["width"] != String.Empty)
        {
            // image dimensions
            int width = Int32.Parse((Request.Form["width"].IndexOf('.') != -1) ? Request.Form["width"].Substring(0, Request.Form["width"].IndexOf('.')) : Request.Form["width"]);
            int height = Int32.Parse((Request.Form["height"].IndexOf('.') != -1) ? Request.Form["height"].Substring(0, Request.Form["height"].IndexOf('.')) : Request.Form["height"]);

            // image
            Bitmap result = new Bitmap(width, height);

            // set pixel colors
            for (int y = 0; y < height; y++)
            {
                // column counter for the row
                int x = 0;
                // get current row data
                string[] row = Request.Form["r" + y].Split(new char[]{','});
                // set pixels in the row
                for (int c = 0; c < row.Length; c++)
                {
                    // get pixel color and repeat count
                    string[] pixel = row[c].Split(new char[] { ':' });
                    Color current_color = ColorTranslator.FromHtml("#" + pixel[0]);
                    int repeat = pixel.Length > 1 ? Int32.Parse(pixel[1]) : 1;

                    // set pixel(s)
                    for (int l = 0; l < repeat; l++)
                    {
                        result.SetPixel(x, y, current_color);
                        x++;
                    }
                }
            }

            // output image

            // image type
            Response.ContentType = "image/jpeg";

            // find image encoder for selected type
            ImageCodecInfo[] encoders;
            ImageCodecInfo img_encoder = null;
            encoders = ImageCodecInfo.GetImageEncoders();
            foreach (ImageCodecInfo codec in encoders)
                if (codec.MimeType == Response.ContentType)
                {
                    img_encoder = codec;
                    break;
                }

            // image parameters
            EncoderParameter jpeg_quality = new EncoderParameter(Encoder.Quality, 100L); // for jpeg images only
            EncoderParameters enc_params = new EncoderParameters(1);
            enc_params.Param[0] = jpeg_quality;

            result.Save(Response.OutputStream, img_encoder, enc_params);
        }
    }
开发者ID:cptfinch,项目名称:algorithm-comparator,代码行数:59,代码来源:export.aspx.cs

示例5: CreateImage

    public static void CreateImage(string RandomCode)
    {
        int imageWidth = (int)(RandomCode.Length * 25);
        Bitmap image = new Bitmap(imageWidth, 25);
        Graphics g = Graphics.FromImage(image);
        Random rand = new Random();
        Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
        string[] font = { "Times New Roman", "Arial"};
        g.Clear(Color.White);
        for (int i = 0; i < RandomCode.Length; i++)
        {
            int cindex = rand.Next(8);
            int findex = rand.Next(2);
            int sindex = rand.Next(14, 17);

            Font f = new Font(font[findex], sindex, FontStyle.Bold);
            Brush b = new SolidBrush(c[cindex]);
            //指定每一个字符的格式
            int ii = 4;
            if ((i + 1) % 2 == 0)
            {
                ii = 2;
            }
            g.DrawString(RandomCode.Substring(i, 1), f, b, i * 22, ii);
            //第一个参数表示显示的字符,第二、三个参数分别表示字体和颜色,
            //第四个参数表示离原点的距离(x坐标),第五个参数表示纵坐标(y坐标)
        }

        for (int i = 0; i < 4; i++)
        {
            int x1 = rand.Next(image.Width);
            int x2 = rand.Next(image.Width);
            int y1 = rand.Next(image.Height);
            int y2 = rand.Next(image.Height);

            g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);

        }

        for (int i = 0; i < 100; i++)
        {
            int x = rand.Next(image.Width);
            int y = rand.Next(image.Height);

            image.SetPixel(x, y, Color.FromArgb(rand.Next()));
        }
        g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        System.Web.HttpContext.Current.Response.ClearContent();
        System.Web.HttpContext.Current.Response.ContentType = "image/Jpeg";
        System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
开发者ID:690312856,项目名称:DIS,代码行数:55,代码来源:VerificationCode.cs

示例6: CreatePic

    //绘制随机码
    private void CreatePic(string checkCode)
    {
        if (checkCode == null || checkCode.Trim() == String.Empty)
            return;
        Bitmap image = new Bitmap(checkCode.Length * 15 + 10, 30);
        Graphics g = Graphics.FromImage(image);
        try
        {
            //生成随机生成器
            Random random = new Random();
            //清空图片背景色
            g.Clear(Color.White);
            //画图片的背景噪音线
            for (int i = 0; i < 25; i++)
            {
                int x1 = random.Next(image.Width);
                int x2 = random.Next(image.Width);
                int y1 = random.Next(image.Height);
                int y2 = random.Next(image.Height);
                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }
            //画图片字体和字号
            Font font = new Font("Arial", 15, (FontStyle.Bold | FontStyle.Italic));
            //初始化画刷
            LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.BlueViolet, Color.Crimson, 1.2f, true);
            g.DrawString(checkCode, font, brush, 2, 2);
            //画图片的前景噪音点
            for (int i = 0; i < 100; i++)
            {
                int x = random.Next(image.Width);
                int y = random.Next(image.Height);
                image.SetPixel(x, y, Color.FromArgb(random.Next()));
            }
            //画图片的边框线
            g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
            // 输出图像
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //将图像保存到指定流
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            //配置输出类型
            Response.ContentType = "image/Gif";
            //输入内容
            Response.BinaryWrite(ms.ToArray());

        }
        finally
        {
            //清空不需要的资源
            g.Dispose();
            image.Dispose();

        }
    }
开发者ID:ZRUIK,项目名称:SETC,代码行数:55,代码来源:CreatePic.aspx.cs

示例7: Main

	static int Main ()
	{
		Bitmap b = new Bitmap (1, 1);
		b.SetPixel (0, 0, Color.FromArgb (0, 128, 0));

		ImageList il = new ImageList ();
		il.Images.Add (b);

		if (Color.FromArgb (0, 128, 0) != (il.Images [0] as Bitmap).GetPixel (0, 0))
			return 1;
		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:12,代码来源:test.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: GenerateBitmap

 static void GenerateBitmap(Bitmap bitmap)
 {
     double scale = 2 * MaxValueExtent / Math.Min(bitmap.Width, bitmap.Height);
     for (int i = 0; i < bitmap.Height; i++)
     {
         double y = (bitmap.Height / 2 - i) * scale;
         for (int j = 0; j < bitmap.Width; j++)
         {
             double x = (j - bitmap.Width / 2) * scale;
             double color = CalcMandelbrotSetColor(new ComplexNumber(x, y));
             bitmap.SetPixel(j, i, GetColor(color));
         }
     }
 }
开发者ID:pombredanne,项目名称:fuzzer-fat-fingers,代码行数:14,代码来源:Mandelbrot.cs

示例10: toBitmap

 public static Bitmap toBitmap(BitMatrix matrix, int width, int height)
 {
     // int width = matrix.Width;
     // int height = matrix.Height;
     Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     for (int x = 0; x < width; x++)
     {
     for (int y = 0; y < height; y++)
     {
         bmap.SetPixel(x, y, matrix[x * matrix.Width / width, y * matrix.Height / height] != false ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF"));
     }
     }
     return bmap;
 }
开发者ID:zwxscience,项目名称:security-and-identification-information-system,代码行数:14,代码来源:ProcInfo.ascx.cs

示例11: CreatCheckCodeImage

    public void CreatCheckCodeImage(string checkCode)
    {
        //不允许验证码为空
        if (checkCode == null || checkCode.Trim() == string.Empty)
        { return; }
        System.Drawing.Bitmap image = new Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);//验证码图片的高度和宽度
        Graphics g = Graphics.FromImage(image);


        Random random = new Random();
        //清空图片背景色
        g.Clear(Color.White);


        for (int i = 0; i < 44; i++)
        {
            int x1 = random.Next(image.Width - i);
            int x2 = random.Next(image.Width);
            int y1 = random.Next(image.Height);
            int y2 = random.Next(image.Height);
            g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
        }


        Font font = new Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
        System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);


        g.DrawString(checkCode, font, brush, 2, 2);
        //画前景噪音点
        for (int i = 0; i < 36; i++)
        {
            int x = random.Next(image.Width);
            int y = random.Next(image.Height);


            image.SetPixel(x, y, Color.FromArgb(random.Next()));
        }


        //画图片的的边框线
        g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        Response.ClearContent();
        Response.ContentType = "image/Gif";
        Response.BinaryWrite(ms.ToArray());

    }
开发者ID:Doarcutine,项目名称:jobskyOA2.0,代码行数:49,代码来源:CheckCodeImage.cs

示例12: 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

示例13: ValidateCode

 private void ValidateCode(string VNum)
 {
     Bitmap image = new Bitmap((int)Math.Ceiling(VNum.Length * 16.0), 24);
     Graphics g = Graphics.FromImage(image);
     try
     {
         //生成随机生成器
         Random random = new Random();
         //清空图片背景色
         g.Clear(Color.WhiteSmoke);
         //画图片的干扰线
         for (int i = 0; i < 10; i++)
         {
             int x1 = random.Next(image.Width);
             int x2 = random.Next(image.Width);
             int y1 = random.Next(image.Height);
             int y2 = random.Next(image.Height);
             g.DrawLine(new Pen(Color.Goldenrod), x1, y1, x2, y2);
         }
         for (int i = 0; i < VNum.Length; i++)
         {
             Font font = new Font("Arial", 16, FontStyle.Bold);
             LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.DarkRed, Color.BlueViolet, 2.5f, true);
             g.DrawString(VNum.Substring(i, 1), font, brush, 2 + i * 14, 1);
         }
         //画图片的前景干扰点
         for (int i = 0; i < 230; i++)
         {
             int x = random.Next(image.Width);
             int y = random.Next(image.Height);
             image.SetPixel(x, y, Color.FromArgb(random.Next()));
         }
         //画图片的边框线
         g.DrawRectangle(new Pen(Color.Gray), 0, 0, image.Width - 1, image.Height - 1);
         //保存图片数据
         MemoryStream stream = new MemoryStream();
         image.Save(stream, ImageFormat.Gif);
         //输出图片
         Response.Clear();
         Response.ContentType = "image/GIF";
         Response.BinaryWrite(stream.ToArray());
     }
     finally
     {
         g.Dispose();
         image.Dispose();
     }
 }
开发者ID:openboy2012,项目名称:GGParadise,代码行数:48,代码来源:CreateCode.aspx.cs

示例14: Bool2Bitmap

 public static Bitmap Bool2Bitmap(bool[][] boolMap)
 {
     Bitmap bmp = new Bitmap(boolMap[0].Length, boolMap.Length);
     using (Graphics g = Graphics.FromImage(bmp)) g.Clear(Color.White);
     for (int y = 0; y < bmp.Height; y++)
     {
         for (int x = 0; x < bmp.Width; x++)
         {
             if (boolMap[y][x])
             {
                 bmp.SetPixel(y, x, Color.Black);
             }
         }
     }
     return bmp;
 }
开发者ID:lekd,项目名称:XNAStickyNoteDetector,代码行数:16,代码来源:Utilities.cs

示例15: 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


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