本文整理汇总了C#中System.Drawing.Bitmap.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetBounds方法的具体用法?C# Bitmap.GetBounds怎么用?C# Bitmap.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDraftImage
// creates a new "DRAFT" sample image
private Bitmap CreateDraftImage()
{
string sText = "DRAFT";
Bitmap destination = new Bitmap(400, 400);
using (Graphics g = Graphics.FromImage(destination))
{
GraphicsUnit units = GraphicsUnit.Pixel;
g.Clear(Color.White);
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
g.DrawString(sText, new Font(
"Arial",
90,
FontStyle.Bold,
GraphicsUnit.Pixel),
new SolidBrush(
Color.FromArgb(64, Color.Black)),
destination.GetBounds(ref units),
stringFormat);
}
return destination;
}
示例2: getRegionFast
//Uses pointers to scan through the bitmap a LOT faster
//Make sure to check "Allow unsafe code" in the project properties
public static unsafe Region getRegionFast(Bitmap bitmap, Color transparencyKey, int tolerance)
{
//Bounds
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = bitmap.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.Left, (int)boundsF.Top,
(int)boundsF.Width, (int)boundsF.Height);
int yMax = (int)boundsF.Height;
int xMax = (int)boundsF.Width;
//Transparency Color
if (tolerance <= 0) tolerance = 1;
//Lock Image
BitmapData bitmapData = bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
uint* pixelPtr = (uint*)bitmapData.Scan0.ToPointer();
//Stores all the rectangles for the region
GraphicsPath path = new GraphicsPath();
//Scan the image, looking for lines that are NOT the transperancy color
for (int y = 0; y < yMax; y++)
{
byte* basePos = (byte*)pixelPtr;
for (int x = 0; x < xMax; x++, pixelPtr++)
{
//Go on with the loop if its transperancy color
if (colorsMatch(pixelPtr, transparencyKey, tolerance))
continue;
//Line start
int x0 = x;
//Find the next transparency colored pixel
while (x < xMax && !colorsMatch(pixelPtr, transparencyKey, tolerance))
{
x++;
pixelPtr++;
}
//Add the line as a rectangle
path.AddRectangle(new Rectangle(x0, y, x - x0, 1));
}
//Go to next line
pixelPtr = (uint*)(basePos + bitmapData.Stride);
}
//Create the Region
Region outputRegion = new Region(path);
//Clean Up
path.Dispose();
bitmap.UnlockBits(bitmapData);
return outputRegion;
}
示例3: Bitmap1bitFeatures
public void Bitmap1bitFeatures ()
{
string sInFile = getInFile ("bitmaps/1bit.png");
using (Bitmap bmp = new Bitmap (sInFile)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
Assert.AreEqual (PixelFormat.Format1bppIndexed, bmp.PixelFormat);
Assert.AreEqual (0, bmp.Palette.Flags, "Palette.Flags");
Assert.AreEqual (2, bmp.Palette.Entries.Length, "Palette.Entries");
Assert.AreEqual (-16777216, bmp.Palette.Entries[0].ToArgb (), "Palette.0");
Assert.AreEqual (-1, bmp.Palette.Entries[1].ToArgb (), "Palette.1");
Assert.AreEqual (288, bmp.Width, "bmp.Width");
Assert.AreEqual (384, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (288, rect.Width, "rect.Width");
Assert.AreEqual (384, rect.Height, "rect.Height");
Assert.AreEqual (288, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (384, bmp.Size.Height, "bmp.Size.Height");
}
}
示例4: UnsafeBitmap
/// <summary>
/// Create an instance from an existing bitmap
/// </summary>
/// <param name="bitmap">The bitmap</param>
public UnsafeBitmap(Bitmap bitmap)
{
this.bitmap = bitmap;
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF bounds = bitmap.GetBounds(ref unit);
size = new Point((int)bounds.Width, (int)bounds.Height);
}
示例5: Object
public Object(Bitmap i, string n, Point location)
{
image = i;
name = n;
GraphicsUnit units = GraphicsUnit.Point;
RectangleF boundingBox = image.GetBounds(ref units);
physics = new Physics(location, boundingBox);
}
示例6: drawImageFromHex
public static Image drawImageFromHex(char hex)
{
Image img = new Bitmap(20, 20);
using (Graphics gfx = Graphics.FromImage(img))
{
GraphicsUnit gfu = GraphicsUnit.Pixel;
gfx.FillRectangle(new SolidBrush(Color.Red), img.GetBounds(ref gfu));
gfx.DrawString(hex.ToString(), new Font("Arial", 10), new SolidBrush(Color.Black), Point.Empty);
}
return img;
}
示例7: SmallQuestionIcon
public static Icon SmallQuestionIcon()
{
Bitmap bitmap = new Bitmap(16, 16);
Graphics g = Graphics.FromImage(bitmap);
GraphicsUnit unit = GraphicsUnit.Pixel;
g.FillRectangle(Brushes.White, bitmap.GetBounds(ref unit));
g.DrawString("?",new Font("Arial",9),Brushes.Black,new PointF(2,2));
g.Flush();
return Make(Image.FromHbitmap(bitmap.GetHbitmap()), 16, true);
}
示例8: BitmapWidget
public BitmapWidget (System.Drawing.Bitmap b)
{
this.b = b;
GraphicsUnit unit = GraphicsUnit.Pixel;
//
// Quick hack to make stuff not too large
//
RectangleF bounds = b.GetBounds (ref unit);
bounds.Height = System.Math.Min (bounds.Height, 600);
bounds.Width = System.Math.Min (bounds.Width, 400);
SetSizeRequest ((int) bounds.Width, (int) bounds.Height);
}
示例9: Bitmap8bitsFeatures
/* Checks bitmap features on a know 1bbp bitmap */
/* Checks bitmap features on a know 1bbp bitmap */
private void Bitmap8bitsFeatures (string filename)
{
using (Bitmap bmp = new Bitmap (filename)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
Assert.AreEqual (PixelFormat.Format8bppIndexed, bmp.PixelFormat);
Assert.AreEqual (110, bmp.Width, "bmp.Width");
Assert.AreEqual (100, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (110, rect.Width, "rect.Width");
Assert.AreEqual (100, rect.Height, "rect.Height");
Assert.AreEqual (110, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (100, bmp.Size.Height, "bmp.Size.Height");
}
}
示例10: Bitmap1bitFeatures
public void Bitmap1bitFeatures ()
{
string sInFile = getInFile ("bitmaps/almogaver1bit.bmp");
using (Bitmap bmp = new Bitmap (sInFile)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
// ??? why is it a 4bbp ?
Assert.AreEqual (PixelFormat.Format4bppIndexed, bmp.PixelFormat);
Assert.AreEqual (173, bmp.Width, "bmp.Width");
Assert.AreEqual (183, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (173, rect.Width, "rect.Width");
Assert.AreEqual (183, rect.Height, "rect.Height");
Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
}
}
示例11: Bitmap8bbpIndexedGreyscaleFeatures
public void Bitmap8bbpIndexedGreyscaleFeatures ()
{
string sInFile = getInFile ("bitmaps/nature-greyscale.jpg");
using (Bitmap bmp = new Bitmap (sInFile)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
Assert.AreEqual (PixelFormat.Format8bppIndexed, bmp.PixelFormat, "PixelFormat");
Assert.AreEqual (110, bmp.Width, "bmp.Width");
Assert.AreEqual (100, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (110, rect.Width, "rect.Width");
Assert.AreEqual (100, rect.Height, "rect.Height");
Assert.AreEqual (110, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (100, bmp.Size.Height, "bmp.Size.Height");
Assert.AreEqual (110, bmp.PhysicalDimension.Width, "bmp.PhysicalDimension.Width");
Assert.AreEqual (100, bmp.PhysicalDimension.Height, "bmp.PhysicalDimension.Height");
Assert.AreEqual (72, bmp.HorizontalResolution, "HorizontalResolution");
Assert.AreEqual (72, bmp.VerticalResolution, "VerticalResolution");
Assert.AreEqual (77896, bmp.Flags, "Flags");
ColorPalette cp = bmp.Palette;
Assert.AreEqual (256, cp.Entries.Length, "Palette.Entries");
Assert.AreEqual (0, cp.Flags, "Palette.Flags");
for (int i = 0; i < 256; i++) {
Color c = cp.Entries [i];
Assert.AreEqual (0xFF, c.A, "A" + i.ToString ());
Assert.AreEqual (i, c.R, "R" + i.ToString ());
Assert.AreEqual (i, c.G, "G" + i.ToString ());
Assert.AreEqual (i, c.B, "B" + i.ToString ());
}
}
}
示例12: RenderEQ
private void RenderEQ(byte[] EqDataArray)
{
if (this.info.SupportGfxLCD)
{
object obj2;
Monitor.Enter(obj2 = this.DWriteMutex);
try
{
Bitmap image = new Bitmap(this.LCD_CONFIG.ColumnsGraphics, this.LCD_CONFIG.RowsGraphics);
GraphicsUnit pixel = GraphicsUnit.Pixel;
RectangleF bounds = image.GetBounds(ref pixel);
Graphics graphics = Graphics.FromImage(image);
graphics.FillRectangle(Brushes.White, bounds);
for (int i = 0; i < this.EQSettings.Render_BANDS; i++)
{
RectangleF ef2;
if (this.DoDebug)
{
Log.Info("LCDHypeWrapper.RenderEQ(): Rendering {0} band {1} = {2}",
new object[]
{
this.EQSettings.UseNormalEq
? "Normal EQ"
: (this.EQSettings.UseStereoEq
? "Stereo EQ"
: (this.EQSettings.UseVUmeter ? "VU Meter" : "VU Meter 2")), i,
this.EQSettings.UseNormalEq
? this.EQSettings.EqArray[1 + i].ToString()
: (this.EQSettings.UseStereoEq
? (this.EQSettings.EqArray[1 + i].ToString() + " : " +
this.EQSettings.EqArray[9 + i].ToString())
: (this.EQSettings.EqArray[1 + i].ToString() + " : " +
this.EQSettings.EqArray[2 + i].ToString()))
});
}
if (this.EQSettings.UseNormalEq)
{
ef2 = new RectangleF((bounds.X + (i * (((int)bounds.Width) / this.EQSettings.Render_BANDS))) + 1f,
bounds.Y + (((int)bounds.Height) - this.EQSettings.EqArray[1 + i]),
(float)((((int)bounds.Width) / this.EQSettings.Render_BANDS) - 2),
(float)this.EQSettings.EqArray[1 + i]);
graphics.FillRectangle(Brushes.Black, ef2);
}
else
{
int num2;
RectangleF ef3;
if (this.EQSettings.UseStereoEq)
{
int num4 = (((int)bounds.Width) / 2) / this.EQSettings.Render_BANDS;
num2 = i * num4;
int num3 = (i + this.EQSettings.Render_BANDS) * num4;
ef2 = new RectangleF((bounds.X + num2) + 1f,
bounds.Y + (((int)bounds.Height) - this.EQSettings.EqArray[1 + i]),
(float)(num4 - 2), (float)this.EQSettings.EqArray[1 + i]);
ef3 = new RectangleF((bounds.X + num3) + 1f,
bounds.Y + (((int)bounds.Height) - this.EQSettings.EqArray[9 + i]),
(float)(num4 - 2), (float)this.EQSettings.EqArray[9 + i]);
graphics.FillRectangle(Brushes.Black, ef2);
graphics.FillRectangle(Brushes.Black, ef3);
}
else if (this.EQSettings.UseVUmeter | this.EQSettings.UseVUmeter2)
{
ef2 = new RectangleF(bounds.X + 1f, bounds.Y + 1f, (float)this.EQSettings.EqArray[1 + i],
(float)(((int)(bounds.Height / 2f)) - 2));
num2 = this.EQSettings.UseVUmeter ? 0 : (((int)bounds.Width) - this.EQSettings.EqArray[2 + i]);
ef3 = new RectangleF((bounds.X + num2) + 1f, (bounds.Y + (bounds.Height / 2f)) + 1f,
(float)this.EQSettings.EqArray[2 + i], (float)(((int)(bounds.Height / 2f)) - 2));
graphics.FillRectangle(Brushes.Black, ef2);
graphics.FillRectangle(Brushes.Black, ef3);
}
}
}
this.DrawImage(image);
return;
}
catch (Exception exception)
{
Log.Info("LCDHypeWrapper.DisplayEQ(): CAUGHT EXCEPTION {0}", new object[] {exception});
if (exception.Message.Contains("ThreadAbortException")) {}
return;
}
finally
{
Monitor.Exit(obj2);
}
}
lock (this.DWriteMutex)
{
if (this.EQSettings.UseVUmeter || this.EQSettings.UseVUmeter2)
{
if (this.DoDebug)
{
Log.Info("LCDHypeWrapper.RenderEQ(): Drawing VU meter");
}
string strLeft = "";
string strRight = "";
int segmentCount = this.LCD_CONFIG.ColumnsText;
if (this.EQSettings._useVUindicators)
{
//.........这里部分代码省略.........
示例13: CreateRegion
public static unsafe GraphicsPath CreateRegion(Bitmap bitmap)
{
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = bitmap.GetBounds(ref unit);
Rectangle bounds = new Rectangle((int)boundsF.Left, (int)boundsF.Top,
(int)boundsF.Width, (int)boundsF.Height);
Color transparencyKey;
if (UseTransparencyColorTopLeft)
{ transparencyKey = bitmap.GetPixel(0, 0); }
else
{ transparencyKey = Color.FromArgb(255, 255, 0, 255); }
uint key = (uint)((transparencyKey.A << 24) |
(transparencyKey.R << 16) |
(transparencyKey.G << 8) |
(transparencyKey.B << 0));
// Access raw bits of the image
BitmapData bitmapData = bitmap.LockBits(bounds, ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
uint* pixelPtr = (uint*)bitmapData.Scan0.ToPointer();
// Get it only once
int yMax = (int)boundsF.Height;
int xMax = (int)boundsF.Width;
// To store the rectangles
GraphicsPath path = new GraphicsPath();
for (int y = 0; y < yMax; y++)
{
// Store pointer to get next line from it
byte* basePos = (byte*)pixelPtr;
for (int x = 0; x < xMax; x++, pixelPtr++)
{ // Is it transparent?
if (*pixelPtr == key) continue; // Yes, go on with the loop
// Store where scan starts
int x0 = x;
//not transparent - scan until we find the next transparent byte
while (x < xMax && (*pixelPtr != key))
{
++x; pixelPtr++;
}
//add rectangle found to path
path.AddRectangle(new Rectangle(x0, y, x - x0, 1));
}
// Goto next line
pixelPtr = (uint*)(basePos + bitmapData.Stride);
}
bitmap.UnlockBits(bitmapData);
return path;
}
示例14: Bitmap32bitsFeatures
public void Bitmap32bitsFeatures ()
{
string sInFile = getInFile ("bitmaps/almogaver32bits.tif");
using (Bitmap bmp = new Bitmap (sInFile)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
// MS reports 24 bpp while we report 32 bpp
// Assert.AreEqual (PixelFormat.Format24bppRgb, bmp.PixelFormat);
Assert.AreEqual (173, bmp.Width, "bmp.Width");
Assert.AreEqual (183, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (173, rect.Width, "rect.Width");
Assert.AreEqual (183, rect.Height, "rect.Height");
Assert.AreEqual (173, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (183, bmp.Size.Height, "bmp.Size.Height");
}
}
示例15: NonInvertedBitmap
public void NonInvertedBitmap ()
{
// regression check against http://bugzilla.ximian.com/show_bug.cgi?id=80751
string sInFile = getInFile ("bitmaps/non-inverted.bmp");
using (Bitmap bmp = new Bitmap (sInFile)) {
GraphicsUnit unit = GraphicsUnit.World;
RectangleF rect = bmp.GetBounds (ref unit);
Assert.AreEqual (90, bmp.Width, "bmp.Width");
Assert.AreEqual (60, bmp.Height, "bmp.Height");
Assert.AreEqual (0, rect.X, "rect.X");
Assert.AreEqual (0, rect.Y, "rect.Y");
Assert.AreEqual (90, rect.Width, "rect.Width");
Assert.AreEqual (60, rect.Height, "rect.Height");
Assert.AreEqual (90, bmp.Size.Width, "bmp.Size.Width");
Assert.AreEqual (60, bmp.Size.Height, "bmp.Size.Height");
// sampling values from a well known bitmap
Assert.AreEqual (-16777216, bmp.GetPixel (12, 21).ToArgb (), "12,21");
Assert.AreEqual (-1, bmp.GetPixel (21, 37).ToArgb (), "21,37");
}
}