• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Drawing.Bitmap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: CalculateGraphicsPathFromBitmap

		// From http://edu.cnzz.cn/show_3281.html
		public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap, Color colorTransparent) 
		{ 
			GraphicsPath graphicsPath = new GraphicsPath(); 
			if (colorTransparent == Color.Empty)
				colorTransparent = bitmap.GetPixel(0, 0); 

			for(int row = 0; row < bitmap.Height; row ++) 
			{ 
				int colOpaquePixel = 0;
				for(int col = 0; col < bitmap.Width; col ++) 
				{ 
					if(bitmap.GetPixel(col, row) != colorTransparent) 
					{ 
						colOpaquePixel = col; 
						int colNext = col; 
						for(colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++) 
							if(bitmap.GetPixel(colNext, row) == colorTransparent) 
								break;
 
						graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1)); 
						col = colNext; 
					} 
				} 
			} 
			return graphicsPath; 
		} 
开发者ID:hanistory,项目名称:hasuite,代码行数:27,代码来源:DrawHelper.cs


示例17: LoadContent

 public void LoadContent()
 {
     tiles = new Bitmap[2];
     tiles[0] = new Bitmap(@"Assets/Tiles/unpassable.png");
     tiles[1] = new Bitmap(@"Assets/Tiles/dirt.png");
     player = new Bitmap(@"Assets/avatar.png");
 }
开发者ID:nielsvh,项目名称:PorkSpleen,代码行数:7,代码来源:OverWorldControl.cs


示例18: CopyTextureToBitmap

        public static Image CopyTextureToBitmap(D3D.Texture2D texture)
        {
            int width = texture.Description.Width;
            if (width % 16 != 0)
                width = MathExtensions.Round(width, 16) + 16;
            Bitmap bmp = new Bitmap(texture.Description.Width, texture.Description.Height, PixelFormat.Format32bppArgb);
            BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
            using (DataStream stream = new DataStream(bData.Scan0, bData.Stride * bData.Height, false, true))
            {
                DataRectangle rect = texture.Map(0, D3D.MapMode.Read, D3D.MapFlags.None);
                using (DataStream texStream = rect.Data)
                {
                    for (int y = 0; y < texture.Description.Height; y++)
                        for (int x = 0; x < rect.Pitch; x+=4)
                        {
                            byte[] bytes = texStream.ReadRange<byte>(4);
                            if (x < bmp.Width*4)
                            {
                                stream.Write<byte>(bytes[2]);	// DXGI format is BGRA, GDI format is RGBA.
                                stream.Write<byte>(bytes[1]);
                                stream.Write<byte>(bytes[0]);
                                stream.Write<byte>(255);
                            }
                        }
                }
            }

            bmp.UnlockBits(bData);
            return bmp;
        }
开发者ID:adrianj,项目名称:Direct3D-Testing,代码行数:30,代码来源:ScreenCapture.cs


示例19: OnPaint

        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            var myImg = new Bitmap("C:\\Users\\phil.SONOCINE\\Pictures\\MyTest.jpg");

            //byte[] bytes = ImageReading.pixels(myImg);

            this.pictureBox1.Image = ImageReading.pixels(myImg); ;
            //grayscale
            //var gsBytes = new List<byte>();
            //for (int i = 0; i < bytes.Length; i+=3)
            //{
            //    var R = bytes[i];
            //    var G = bytes[i+1];
            //    var B = bytes[i+2];
            //    byte gs = (byte)(0.2989 * R + 0.5870 * G + 0.1140 * B);
            //    gsBytes.Add(gs);
            //}

            //using (var ms = new MemoryStream(bytes))
            //{
            //    try
            //    {
            //        ms.Seek(0, SeekOrigin.Begin);
            //        var bmp = Image.FromStream(ms);
            //        e.Graphics.DrawImage(bmp, 0, 0);
            //    }
            //    catch(Exception ex)
            //    {
            //        Console.WriteLine(ex.Message);
            //    }
            //}
        }
开发者ID:pdoh00,项目名称:Sandbox,代码行数:33,代码来源:Form1.cs


示例20: GenerateWallpaper

        /// <summary>
        /// Combine image of WallpaperConfiguration into one big image.
        /// 
        /// </summary>
        /// <returns></returns>
        protected string GenerateWallpaper()
        {
            string path = Path.GetTempFileName();

            // create an image for virtual screen
            Image image = new Bitmap(Configuration.VirtualScreenBounds.Width,
                Configuration.VirtualScreenBounds.Height);
            Graphics gs = Graphics.FromImage(image);

            // generate an image based on the described configuration
            foreach (ScreenConfiguration wallConf in Configuration.Screens)
            {
                // draw image
                IDrawer drawer = Drawers[wallConf.Style];
                drawer.Draw(gs, wallConf);
                gs.Flush();
            }
            image.Save(path, ImageFormat.Jpeg);

            // clean up
            image.Dispose();
            gs.Dispose();

            return path;
        }
开发者ID:gleroi,项目名称:WallPaperSeven,代码行数:30,代码来源:WallpaperService.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Drawing.Brush类代码示例发布时间:2022-05-26
下一篇:
C# Protocols.LdapConnection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap