本文整理汇总了C#中System.Drawing.Bitmap类的典型用法代码示例。如果您正苦于以下问题:C# Bitmap类的具体用法?C# Bitmap怎么用?C# Bitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Bitmap类属于System.Drawing命名空间,在下文中一共展示了Bitmap类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Button1_Click
Bitmap image1;
private void Button1_Click(System.Object sender, System.EventArgs e)
{
try
{
// Retrieve the image.
image1 = new Bitmap(@"C:\Documents and Settings\All Users\"
+ @"Documents\My Music\music.bmp", true);
int x, y;
// Loop through the images pixels to reset color.
for(x=0; x<image1.Width; x++)
{
for(y=0; y<image1.Height; y++)
{
Color pixelColor = image1.GetPixel(x, y);
Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
image1.SetPixel(x, y, newColor);
}
}
// Set the PictureBox to display the image.
PictureBox1.Image = image1;
// Display the pixel format in Label1.
Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
}
catch(ArgumentException)
{
MessageBox.Show("There was an error." +
"Check the path to the image file.");
}
}
示例2: new Bitmap(String fileName)
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
Bitmap bmp = new Bitmap("rama.jpg");
Rectangle r = new Rectangle(0, 0, bmp.Width, bmp.Height);
g.DrawImage(bmp, r, r, GraphicsUnit.Pixel);
}
public static void Main() {
Application.Run(new Form1());
}
}