本文整理汇总了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);
}
示例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)));
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例6: ContextMenuModel
public ContextMenuModel(IScreen owner, string name, string displayName, Bitmap image = null)
{
Owner = owner;
Name = name;
DisplayName = displayName;
Image = image;
}
示例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;
}
示例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);
}
}
示例9: Setup
public void Setup()
{
Bitmap bmp = new Bitmap(200, 100);
m_graphics = Graphics.FromImage(bmp);
m_gm = new GraphicsManager(null, m_graphics);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}