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


C# Drawing.Bitmap类代码示例

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


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

示例1: TakeSnapshot

 private void TakeSnapshot()
 {
     var stamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");
     Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
     Graphics.FromImage(bmp).CopyFromScreen(0, 0, 0, 0, bmp.Size);
     bmp.Save(@"C:\Temp\" + stamp + ".jpg", ImageFormat.Jpeg);
 }
开发者ID:FrontFabric,项目名称:Link,代码行数:7,代码来源:FrmMain.cs

示例2: DrawDebugInfo

        private void DrawDebugInfo(Bitmap frame, VisionResults results)
        {
            using (var g = Graphics.FromImage(frame))
            {
                /*{
                    var thresholdString = string.Format("Threshold: {0}", HoughTransform.CannyThreshold);
                    var linkingString = string.Format("Linking: {0}", HoughTransform.CannyThresholdLinking);

                    g.FillRectangle(Brushes.White, 5, 5, 100, 50);
                    g.DrawString(thresholdString, SystemFonts.DefaultFont, Brushes.Crimson, new PointF(10, 10));
                    g.DrawString(linkingString, SystemFonts.DefaultFont, Brushes.Crimson, new PointF(10, 30));
                }*/

                if (showCircles)
                    foreach (var circle in results.Circles)
                    {
                        g.DrawEllipse(ellipsePen, circle.X - circle.Radius, circle.Y - circle.Radius, circle.Radius * 2, circle.Radius * 2);
                        g.DrawString(circle.Intensity.ToString(), SystemFonts.DefaultFont, Brushes.Orange, circle.X, circle.Y);
                    }

                if (showLines)
                    foreach (var line in results.Lines)
                    {
                        g.DrawLine(linePen, line.P1, line.P2);
                        g.DrawString(line.Length.ToString("0.00"), SystemFonts.DefaultFont, Brushes.OrangeRed, line.P2);
                    }

                if (results.TrackingBall)
                {
                    g.DrawRectangle(camshiftPen, results.TrackWindow);
                    g.DrawLine(camshiftPen, results.TrackCenter, Point.Add(results.TrackCenter, new Size(1, 1)));
                }
            }
        }
开发者ID:martikaljuve,项目名称:Robin,代码行数:34,代码来源:MainForm.cs

示例3: Mark

        public Image Mark( Image image, string waterMarkText )
        {
            WatermarkText = waterMarkText;

            Bitmap originalBmp = (Bitmap)image;

            // avoid "A Graphics object cannot be created from an image that has an indexed pixel format." exception
            Bitmap tempBitmap = new Bitmap(originalBmp.Width, originalBmp.Height);
            // From this bitmap, the graphics can be obtained, because it has the right PixelFormat
            Graphics g = Graphics.FromImage(tempBitmap);

            using (Graphics graphics = Graphics.FromImage(tempBitmap))
            {
                // Draw the original bitmap onto the graphics of the new bitmap
                g.DrawImage(originalBmp, 0, 0);
                var size =
                    graphics.MeasureString(WatermarkText, Font);
                var brush =
                    new SolidBrush(Color.FromArgb(255, Color));
                graphics.DrawString
                    (WatermarkText, Font, brush,
                    GetTextPosition(image, size));
            }

            return tempBitmap as Image;
        }
开发者ID:Esri,项目名称:arcobjects-sdk-community-samples,代码行数:26,代码来源:ApplyWatermark.cs

示例4: Apply

        public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode)
        {
            Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert);

            if (applyRect.Width == 0 || applyRect.Height == 0)
            {
                // nothing to do
                return;
            }
            GraphicsState state = graphics.Save();
            if (Invert)
            {
                graphics.SetClip(applyRect);
                graphics.ExcludeClip(rect);
            }
            ColorMatrix grayscaleMatrix = new ColorMatrix(new[] {
                new[] {.3f, .3f, .3f, 0, 0},
                new[] {.59f, .59f, .59f, 0, 0},
                new[] {.11f, .11f, .11f, 0, 0},
                new float[] {0, 0, 0, 1, 0},
                new float[] {0, 0, 0, 0, 1}
            });
            using (ImageAttributes ia = new ImageAttributes())
            {
                ia.SetColorMatrix(grayscaleMatrix);
                graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia);
            }
            graphics.Restore(state);
        }
开发者ID:Grifs99,项目名称:ShareX,代码行数:29,代码来源:GrayscaleFilter.cs

示例5: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count != 1)
         return;
     OpenFileDialog od = new OpenFileDialog();
     od.Filter = "Bitmap file (*.bmp)|*.bmp";
     od.FilterIndex = 0;
     if (od.ShowDialog() == DialogResult.OK)
     {
         Section s = listView1.SelectedItems[0].Tag as Section;
         try
         {
             Bitmap bmp = new Bitmap(od.FileName);
             s.import(bmp);
             bmp.Dispose();
             pictureBox1.Image = s.image();
             listView1.SelectedItems[0].SubItems[3].Text = s.cnt.ToString();
             button4.Enabled = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
开发者ID:winterheart,项目名称:game-utilities,代码行数:25,代码来源:Form1.cs

示例6: ContextMenuModel

 public ContextMenuModel(IScreen owner, string name, string displayName, Bitmap image = null)
 {
     Owner = owner;
     Name = name;
     DisplayName = displayName;
     Image = image;
 }
开发者ID:roycornelissen,项目名称:ServiceInsight,代码行数:7,代码来源:ContextMenuModel.cs

示例7: decodeBinary

 public static byte[] decodeBinary(Bitmap bmp)
 {
     byte[] bytes = null;
     try
     {
         int wSize = bmp.Width, hSize = bmp.Height;
         MemoryStream stream = new MemoryStream();
         for (int w = 0; w < wSize; w++)
         {
             for (int h = 0; h < hSize; h++)
             {
                 Color color = bmp.GetPixel(w, h);
                 if (color.R == 0 && color.G == 0 && color.B == 0) stream.WriteByte(color.A);
                 else break;
             }
         }
         bytes = stream.ToArray();
         stream = null;
     }
     catch (Exception e)
     {
         bytes = null;
     }
     return bytes;
 }
开发者ID:JhetoX,项目名称:PNGEncryption,代码行数:25,代码来源:Program.cs

示例8: PasteIconWithScale

 public void PasteIconWithScale(byte[] bytes, int x, int y, double scale)
 {
     using (Bitmap icon = new Bitmap(new MemoryStream(bytes), false))
     {
         PasteIcon(icon, x, y, scale);
     }
 }
开发者ID:MoonDav,项目名称:TileRendering,代码行数:7,代码来源:Icon2TileRendering.cs

示例9: Setup

		public void Setup()
		{
			Bitmap bmp = new Bitmap(200, 100);
			m_graphics = Graphics.FromImage(bmp);

			m_gm = new GraphicsManager(null, m_graphics);
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:7,代码来源:RowTests.cs

示例10: AddImage

        public void AddImage(BackgroundImageClass image)
        {
            var imageBytes = webClientWrapper.DownloadBytes(image.ImageUrl);
            Bitmap bitmap = null;
            using (var originalBitmap = new Bitmap(new MemoryStream(imageBytes)))
            {
                using (var writer = new SpriteWriter(image.Width ?? originalBitmap.Width, image.Height ?? originalBitmap.Height))
                {
                    var width = image.Width ?? originalBitmap.Width;
                    if (width > originalBitmap.Width)
                        width = originalBitmap.Width;
                    var height = image.Height ?? originalBitmap.Height;
                    if (height > originalBitmap.Height)
                        height = originalBitmap.Height;
                    var x = image.XOffset.Offset < 0 ? Math.Abs(image.XOffset.Offset) : 0;
                    var y = image.YOffset.Offset < 0 ? Math.Abs(image.YOffset.Offset) : 0;

                    writer.WriteImage(originalBitmap.Clone(new Rectangle(x, y, width, height), originalBitmap.PixelFormat));
                    bitmap = writer.SpriteImage;
                    if ((originalBitmap.Width * originalBitmap.Height) > (bitmap.Width * bitmap.Height))
                        Size += writer.GetBytes("image/png").Length;
                    else
                        Size += imageBytes.Length;
                }
            }
            images.Add(bitmap);
            Width += bitmap.Width;
            if (Height < bitmap.Height) Height = bitmap.Height;
        }
开发者ID:colintho,项目名称:RequestReduce,代码行数:29,代码来源:SpriteContainer.cs

示例11: ResizeBitmap

 private Bitmap ResizeBitmap(Bitmap bmp)
 {
     ResizeBilinear resizer = new ResizeBilinear(pb_loaded.Width, pb_loaded.Height);
     bmp = resizer.Apply(bmp);
     //bmp.Save(fileNameCounter+"resized.png");
     return bmp;
 }
开发者ID:wesleyteixeira,项目名称:poker,代码行数:7,代码来源:Form1.cs

示例12: Binariz

        public Bitmap Binariz(Bitmap bm)
        {
            int x = bm.Width;
            int y = bm.Height;

            Bitmap result = new Bitmap(x, y);

            for (int pixX = 0; pixX < x; pixX++)
                for (int pixY = 0; pixY < y; pixY++)
                {

                    int rd, gr, bl;

                    if (bm.GetPixel(pixX, pixY).R  < 100)
                        rd = 0;
                    else
                        rd = 255;

                    if (bm.GetPixel(pixX, pixY).G  < 100)
                        gr = 0;
                    else
                        gr = 255;

                    if (bm.GetPixel(pixX, pixY).B  < 100)
                        bl = 0;
                    else
                        bl = 255;

                    result.SetPixel(pixX, pixY, Color.FromArgb((byte)rd, (byte)gr, (byte)bl));
                }

            return result;
        }
开发者ID:core0,项目名称:Image-Proccessing,代码行数:33,代码来源:Form1.cs

示例13: ToolBarDeleteButton

 public ToolBarDeleteButton()
 {
     Bitmap button = new Bitmap(Properties.Resources.DeleteButton, new Size(50, 50));
     Bitmap buttonPressed = new Bitmap(Properties.Resources.DeleteButtonPressed, new Size(50, 50));
     this.BackgroundImage = button;
     this.PressedImage = buttonPressed;
 }
开发者ID:MaitRaidmae,项目名称:AppAnalyzerWinForms,代码行数:7,代码来源:ToolBarDeleteButton.cs

示例14: DrawBitmap

 public Bitmap DrawBitmap(int theight, int twidth)
 {
     Bitmap bitmap3;
     Bitmap bitmap = new Bitmap(this.Width, this.Height);
     Rectangle targetBounds = new Rectangle(0, 0, this.Width, this.Height);
     this.MyBrowser.DrawToBitmap(bitmap, targetBounds);
     Image image = bitmap;
     Bitmap bitmap2 = new Bitmap(twidth, theight, image.PixelFormat);
     Graphics graphics = Graphics.FromImage(bitmap2);
     graphics.CompositingQuality = CompositingQuality.HighSpeed;
     graphics.SmoothingMode = SmoothingMode.HighSpeed;
     graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
     Rectangle rect = new Rectangle(0, 0, twidth, theight);
     graphics.DrawImage(image, rect);
     try
     {
         bitmap3 = bitmap2;
     }
     catch
     {
         bitmap3 = null;
     }
     finally
     {
         image.Dispose();
         image = null;
         this.MyBrowser.Dispose();
         this.MyBrowser = null;
     }
     return bitmap3;
 }
开发者ID:xiluo,项目名称:document-management,代码行数:31,代码来源:WebPageBitmap.cs

示例15: LoadTexture

		public static int LoadTexture(string filename)
		{
			var bitmap = new Bitmap (filename);

			int id = GL.GenTexture ();

			BitmapData bmpData = bitmap.LockBits (
				new Rectangle (0, 0, bitmap.Width, bitmap.Height),
				ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

			GL.BindTexture (TextureTarget.Texture2D, id);

			GL.TexImage2D (TextureTarget.Texture2D, 0,
				PixelInternalFormat.Rgba,
				bitmap.Width, bitmap.Height, 0,
				OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
				PixelType.UnsignedByte,
				bmpData.Scan0);

			bitmap.UnlockBits (bmpData);

			GL.TexParameter (TextureTarget.Texture2D,
				TextureParameterName.TextureMinFilter, 
				(int)TextureMinFilter.Linear);

			GL.TexParameter (TextureTarget.Texture2D,
				TextureParameterName.TextureMagFilter, 
				(int)TextureMagFilter.Linear);

			return id;
		}
开发者ID:PieterMarius,项目名称:PhysicsEngine,代码行数:31,代码来源:OpenGLUtilities.cs


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