本文整理汇总了C#中System.Drawing.Image.GetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Image.GetBounds方法的具体用法?C# Image.GetBounds怎么用?C# Image.GetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Image
的用法示例。
在下文中一共展示了Image.GetBounds方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResizeImage
public override void ResizeImage(Graphics graphics, Image original)
{
Rectangle target = RectangleResizing.Center(
Rectangle.Round(graphics.VisibleClipBounds),
Rectangle.Round(original.GetBounds(ref GraphicsUnit)));
graphics.DrawImage(original, target);
}
示例2: BoundingBox
private Rectangle BoundingBox(Image img, Matrix matrix)
{
GraphicsUnit gu = new GraphicsUnit();
Rectangle rImg = Rectangle.Round(img.GetBounds(ref gu));
// Transform the four points of the image, to get the resized bounding box.
Point topLeft = new Point(rImg.Left, rImg.Top);
Point topRight = new Point(rImg.Right, rImg.Top);
Point bottomRight = new Point(rImg.Right, rImg.Bottom);
Point bottomLeft = new Point(rImg.Left, rImg.Bottom);
Point[] points = { topLeft, topRight, bottomRight, bottomLeft };
GraphicsPath gp = new GraphicsPath(points,
new[]
{
(byte) PathPointType.Start, (byte) PathPointType.Line, (byte) PathPointType.Line,
(byte) PathPointType.Line
});
gp.Transform(matrix);
return Rectangle.Round(gp.GetBounds());
}
示例3: ColorNonRegionFormArea
private static Bitmap ColorNonRegionFormArea(IntPtr hWnd, Image capture, Color color)
{
Bitmap finalCapture;
using (Region region = GetRegionByHWnd(hWnd))
using (Graphics drawGraphics = Graphics.FromImage(capture))
using (SolidBrush brush = new SolidBrush(color))
{
RectangleF bounds = region.GetBounds(drawGraphics);
if (bounds == RectangleF.Empty)
{
GraphicsUnit unit = GraphicsUnit.Pixel;
bounds = capture.GetBounds(ref unit);
if ((GetWindowLongA(hWnd, GWL_STYLE) & TARGETWINDOW) == TARGETWINDOW)
{
IntPtr windowRegion = CreateRoundRectRgn(0, 0, (int) bounds.Width + 1, (int) bounds.Height + 1, 9, 9);
Region r = Region.FromHrgn(windowRegion);
r.Complement(bounds);
drawGraphics.FillRegion(brush, r);
}
}
else
{
region.Complement(bounds);
drawGraphics.FillRegion(brush, region);
}
finalCapture = new Bitmap((int) bounds.Width, (int) bounds.Height);
using (Graphics finalGraphics = Graphics.FromImage(finalCapture))
{
finalGraphics.SmoothingMode = SmoothingMode.AntiAlias;
finalGraphics.DrawImage(capture, new RectangleF(new PointF(0, 0), finalCapture.Size), bounds, GraphicsUnit.Pixel);
}
}
return finalCapture;
}
示例4: CreateImage
private void CreateImage()
{
if (image != null) image.Dispose();
try {
// Check if image dimensions are valid
Graphics infoGfx = diagramPresenter.Diagram.DisplayService.InfoGraphics;
int imgWidth = (int)Math.Round((dpi / infoGfx.DpiX) * diagramPresenter.Diagram.Width);
int imgHeight = (int)Math.Round((dpi / infoGfx.DpiY) * diagramPresenter.Diagram.Height);
if (Math.Min(imgWidth, imgHeight) <= 0 || Math.Max(imgWidth, imgHeight) > 16000) {
string msgTxt = string.Format("The selected resolution would result in a {0}x{1} pixels bitmap which is not supported.", imgWidth, imgHeight);
MessageBox.Show(this, msgTxt, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} else {
Cursor = Cursors.WaitCursor;
try {
image = diagramPresenter.Diagram.CreateImage(imageFormat,
shapes,
margin,
withBackgroundCheckBox.Checked,
backgroundColor,
dpi);
if (image != null) {
GraphicsUnit unit = GraphicsUnit.Display;
imageBounds = Rectangle.Round(image.GetBounds(ref unit));
}
} catch (Exception exc) {
MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} finally {
Cursor = Cursors.Default;
}
}
} catch (Exception exc) {
MessageBox.Show(this, string.Format("Error while creating image: {0}", exc.Message), "Error while creating image", MessageBoxButtons.OK, MessageBoxIcon.Error);
image = new Bitmap(1, 1);
}
}
示例5: BoundingBox
private static Rectangle BoundingBox(Image img, Matrix matrix)
{
GraphicsUnit graphicsUnit = new GraphicsUnit();
Rectangle rectangle = Rectangle.Round(img.GetBounds(ref graphicsUnit));
// Transform the four points of the image to get the resized bounding box.
Point topLeft = new Point(rectangle.Left, rectangle.Top);
Point topRight = new Point(rectangle.Right, rectangle.Top);
Point bottomRight = new Point(rectangle.Right, rectangle.Bottom);
Point bottomLeft = new Point(rectangle.Left, rectangle.Bottom);
Point[] points = new[] { topLeft, topRight, bottomRight, bottomLeft };
var types = new[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line };
using (GraphicsPath graphicsPath = new GraphicsPath(points, types))
{
graphicsPath.Transform(matrix);
return Rectangle.Round(graphicsPath.GetBounds());
}
}
示例6: BoundingBox
private static Rectangle BoundingBox(Image img, Matrix matrix)
{
GraphicsUnit gu = new GraphicsUnit();
Rectangle rImg = Rectangle.Round(img.GetBounds(ref gu));
Point topLeft = new Point(rImg.Left, rImg.Top);
Point topRight = new Point(rImg.Right, rImg.Top);
Point bottomRight = new Point(rImg.Right, rImg.Bottom);
Point bottomLeft = new Point(rImg.Left, rImg.Bottom);
Point[] points = new Point[] { topLeft, topRight, bottomRight, bottomLeft };
GraphicsPath gp = new GraphicsPath(points,
new byte[] { (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line });
gp.Transform(matrix);
return Rectangle.Round(gp.GetBounds());
}
示例7: Load
public bool Load(Image image)
{
PixelFormat pxFormat = image.PixelFormat;
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF boundsF = image.GetBounds(ref unit);
Rectangle bounds = new Rectangle(
(int)boundsF.X, (int)boundsF.Y, (int)boundsF.Width, (int)boundsF.Height);
BitmapData bitmapData =
(image as Bitmap).LockBits(bounds, ImageLockMode.ReadWrite, pxFormat);
try
{
int width = image.Width;
int height = image.Height;
int length = width * height;
InitializeAndAllocateMemory(width, height);
byte[] dst = (byte[])_data;
int realWidth = (int)Math.Abs(bitmapData.Stride);
int bytenum = realWidth / width;
int reserved = realWidth - bytenum * width;
byte* src = (byte*)bitmapData.Scan0.ToPointer();
{
int index = 0;
switch (bytenum)
{
case 1:
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, index++, src++)
{
dst[index] = (byte)(*(src));
}
src += reserved;
}
break;
case 3:
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, index++, src += 3)
{
dst[index] = (byte)((*(src) * 29 + *(src + 1) * 150 + *(src + 2) * 77 + 128) / 256);
}
src += reserved;
}
break;
case 4:
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, index++, src += 4)
{
dst[index] = (byte)((*(src) * 29 + *(src + 1) * 150 + *(src + 2) * 77 + 128) / 256);
}
src += reserved;
}
break;
}
}
}
catch
{
}
finally
{
if (image != null && bitmapData != null)
{
(image as Bitmap).UnlockBits(bitmapData);
}
}
return true;
}
示例8: OverlayImage
public static Image OverlayImage(Image baseImage, Image overlay)
{
Bitmap i = new Bitmap (baseImage.Width, baseImage.Height);
using (Graphics g = Graphics.FromImage (i)) {
g.DrawImage (baseImage, Point.Empty);
GraphicsUnit gu = GraphicsUnit.Pixel;
g.DrawImage (overlay, new RectangleF (i.Width - overlay.Width, i.Height - overlay.Height, overlay.Width, overlay.Height), overlay.GetBounds (ref gu), GraphicsUnit.Pixel);
}
return i;
}
示例9: refreshImageSelection
private void refreshImageSelection()
{
var s = (string)listImages.SelectedItem;
if (s == null)
{
previewImage = null;
picPreview.Invalidate();
return;
}
previewImage = images[s];
var units = GraphicsUnit.Pixel;
imageBounds = previewImage.GetBounds(ref units);
updatePreviewSize();
picPreview.Invalidate();
}
示例10: DrawImageDisabled
internal static void DrawImageDisabled(Graphics graphics, Image image, Rectangle imageBounds, Color background, bool unscaledImage) {
if (graphics == null) {
throw new ArgumentNullException("graphics");
}
if (image == null) {
throw new ArgumentNullException("image");
}
#if GRAYSCALE_DISABLED
Size imageSize = image.Size;
if (disabledImageAttr == null) {
// This is how I came up with this somewhat random ColorMatrix.
// Its set to resemble Office10 commandbars, but still be able to
// deal with hi-color (256+) icons and images.
//
// The idea is to scale everything down (more than just a grayscale does,
// therefore the small numbers in the scaling part of matrix)
// White -> some shade of gray &
// Black -> Black
//
// Second part of the matrix is to translate everything, so all colors are
// a bit brigher.
// Grays become lighter and washed out looking
// Black becomes a shade of gray as well.
//
// btw, if you do come up with something better let me know - [....]
float[][] array = new float[5][];
array[0] = new float[5] {0.2125f, 0.2125f, 0.2125f, 0, 0};
array[1] = new float[5] {0.2577f, 0.2577f, 0.2577f, 0, 0};
array[2] = new float[5] {0.0361f, 0.0361f, 0.0361f, 0, 0};
array[3] = new float[5] {0, 0, 0, 1, 0};
array[4] = new float[5] {0.38f, 0.38f, 0.38f, 0, 1};
ColorMatrix grayMatrix = new ColorMatrix(array);
disabledImageAttr = new ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(grayMatrix);
}
if (unscaledImage) {
using (Bitmap bmp = new Bitmap(image.Width, image.Height)) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.DrawImage(image,
new Rectangle(0, 0, imageSize.Width, imageSize.Height),
0, 0, imageSize.Width, imageSize.Height,
GraphicsUnit.Pixel,
disabledImageAttr);
}
graphics.DrawImageUnscaled(bmp, imageBounds);
}
}
else {
graphics.DrawImage(image,
imageBounds,
0, 0, imageSize.Width, imageSize.Height,
GraphicsUnit.Pixel,
disabledImageAttr);
}
#else
// This is remarkably simple -- make a monochrome version of the image, draw once
// with the button highlight color, then a second time offset by one pixel
// and in the button shadow color.
// Technique borrowed from comctl Toolbar.
Bitmap bitmap;
bool disposeBitmap = false;
if (image is Bitmap)
bitmap = (Bitmap) image;
else {
// #37659 -- metafiles can have extremely high resolutions,
// so if we naively turn them into bitmaps, the performance will be very poor.
// bitmap = new Bitmap(image);
GraphicsUnit units = GraphicsUnit.Display;
RectangleF bounds = image.GetBounds(ref units);
bitmap = new Bitmap((int) (bounds.Width * graphics.DpiX / image.HorizontalResolution),
(int) (bounds.Height * graphics.DpiY / image.VerticalResolution));
Graphics bitmapGraphics = Graphics.FromImage(bitmap);
bitmapGraphics.Clear(Color.Transparent);
bitmapGraphics.DrawImage(image, 0, 0, image.Size.Width, image.Size.Height);
bitmapGraphics.Dispose();
disposeBitmap = true;
}
Color highlight = ControlPaint.LightLight(background);
Bitmap monochrome = MakeMonochrome(bitmap, highlight);
graphics.DrawImage(monochrome, new Rectangle(imageBounds.X + 1, imageBounds.Y + 1, imageBounds.Width, imageBounds.Height));
monochrome.Dispose();
Color shadow = ControlPaint.Dark(background);
monochrome = MakeMonochrome(bitmap, shadow);
graphics.DrawImage(monochrome, imageBounds);
monochrome.Dispose();
//.........这里部分代码省略.........