Here are the examples of the csharp api System.Drawing.Graphics.FromImage(System.Drawing.Image) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1819 Examples
19
Source : Display.cs
with GNU General Public License v3.0
from boonkerz
with GNU General Public License v3.0
from boonkerz
protected override byte[] createScreenShot()
{
img = screenWork.createScreenshot(true);
this.width = img.Dimensions.Width;
this.height = img.Dimensions.Height;
var msout = new MemoryStream();
var bmpScreenshot = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y,
0,
0,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
bmpScreenshot.Save(msout, ImageFormat.Jpeg);
return msout.ToArray();
}
19
Source : FontPicker.cs
with MIT License
from botman99
with MIT License
from botman99
public void InitializeFontList()
{
SelectedFont = null;
FontTextBox.Text = "";
FontListBox.Items.Clear();
using (Bitmap bmp = new Bitmap(1, 1))
{
using (Graphics g = Graphics.FromImage(bmp))
{
foreach (FontFamily f in FontFamily.Families)
{
try
{
if( (f.Name != null) || (f.Name != "") )
{
Font newfont = new Font(f, 10);
if( !IsSymbolFont(newfont) )
{
if( !bFixedWidthOnly || IsMonospaced(g, newfont) )
{
FontListBox.Items.Add(newfont);
}
}
}
}
catch {}
}
}
}
}
19
Source : MainWindow.xaml.cs
with GNU General Public License v3.0
from bp2008
with GNU General Public License v3.0
from bp2008
private static BitmapSource CopyScreen(Rect bounds)
{
using (var screenBmp = new System.Drawing.Bitmap(
(int)bounds.Width,
(int)bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (var bmpGraphics = System.Drawing.Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen((int)bounds.Left, (int)bounds.Top, 0, 0, screenBmp.Size);
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
screenBmp.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
}
}
19
Source : WebP.cs
with GNU General Public License v3.0
from bp2008
with GNU General Public License v3.0
from bp2008
public static byte[] ToWebP(Bitmap input, int quality = 80)
{
bool inputGotReplaced = false;
if (quality < -1)
quality = -1;
if (quality > 100)
quality = 100;
try
{
if (input.PixelFormat != PixelFormat.Format24bppRgb)
{
Bitmap bmp = new Bitmap(input.Width, input.Height, PixelFormat.Format16bppRgb555);
using (var gr = Graphics.FromImage(bmp))
gr.DrawImage(input, new Rectangle(0, 0, input.Width, input.Height));
input = bmp;
inputGotReplaced = true;
}
BitmapData data = input.LockBits(
new Rectangle(0, 0, input.Width, input.Height),
ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb);
IntPtr unmanagedData = IntPtr.Zero;
int size;
try
{
size = WebPEncodeBGR(data.Scan0, input.Width, input.Height, data.Stride, quality, out unmanagedData);
}
catch (Exception ex)
{
Logger.Debug(ex);
if (unmanagedData != IntPtr.Zero)
WebPFree(unmanagedData);
return new byte[0];
}
input.UnlockBits(data);
try
{
byte[] managedData = new byte[size];
Marshal.Copy(unmanagedData, managedData, 0, size);
return managedData;
}
catch (Exception)
{
return new byte[0];
}
finally
{
WebPFree(unmanagedData);
}
}
catch (Exception)
{
return new byte[0];
}
finally
{
if(inputGotReplaced && input != null)
input.Dispose();
}
}
19
Source : WrappedImage.cs
with GNU General Public License v3.0
from bp2008
with GNU General Public License v3.0
from bp2008
public void TurnRed()
{
//if (bmp != null)
//{
if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
return;
// Based on: http://www.codeproject.com/Articles/16403/Fast-Pointerless-Image-Processing-in-NET
int BitsPerPixel = Image.GetPixelFormatSize(bmp.PixelFormat);
int BytesPerPixel = BitsPerPixel / 8;
int stride = 4 * ((bmp.Width * BitsPerPixel + 31) / 32);
byte[] bits = new byte[stride * bmp.Height];
GCHandle handle = GCHandle.Alloc(bits, GCHandleType.Pinned);
try
{
IntPtr pointer = Marshal.UnsafeAddrOfPinnedArrayElement(bits, 0);
Bitmap bitmap = new Bitmap(bmp.Width, bmp.Height, stride, bmp.PixelFormat, pointer);
Graphics g = Graphics.FromImage(bitmap);
g.DrawImageUnscaledAndClipped(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
g.Dispose();
for (int y = 0; y < bmp.Height; y++)
{
int start = stride * y;
int end = start + (bmp.Width * BytesPerPixel);
for (int i = start; i < end; i += 3)
{
bits[i + 2] = (byte)((bits[i] + bits[i + 1] + bits[i + 2]) / 3);
bits[i] = bits[i + 1] = 0;
}
}
bmp = new Bitmap(bitmap);
}
finally
{
handle.Free();
}
//}
//else
//{
// if (mi.ColorSpace == ColorSpace.sRGB && mi.ColorType == ColorType.TrueColor)
// {
// WritablePixelCollection data = mi.GetWritablePixels();
// byte[] vals = data.GetValues();
// int stride = data.Width * 4;
// for (int y = 0; y < data.Height; y++)
// {
// int start = stride * y;
// int end = start + stride;
// for (int i = start; i < end; i += 4)
// {
// vals[i] = ByteAverage(vals[i], vals[i + 1], vals[i + 2]);
// vals[i + 1] = vals[i + 2] = 0;
// }
// }
// data.Set(vals);
// data.Write();
// }
// else
// {
// Console.WriteLine(mi.ColorSpace + " " + mi.ColorType);
// }
//}
}
19
Source : ImageUtils.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap CaptureScreen(int x1, int y1, int x2, int y2)
{
var screenBmp = new Bitmap(x2 - x1, y2 - y1, PixelFormat.Format32bppRgb);
using (var bmpGraphics = Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen(x1, y1, 0, 0, screenBmp.Size);
return screenBmp;
}
}
19
Source : ImageUtils.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap CaptureArea(Bitmap bmp, Rectangle rect, Point[] clipPoints, bool textInWhite = false)
{
Bitmap bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppRgb);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.FillRectangle(textInWhite ? Brushes.Black : Brushes.White, 0, 0, rect.Width, rect.Height);
using (GraphicsPath graphicsPath = new GraphicsPath())
{
if (clipPoints.Length != 0)
{
graphicsPath.AddPolygon(clipPoints);
graphics.SetClip(graphicsPath);
}
}
graphics.DrawImage(bmp, 0, 0, rect, GraphicsUnit.Pixel);
}
return bitmap;
}
19
Source : ImageUtils.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap CaptureBanArea(Rectangle rect)
{
var screenBmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppRgb);
using (var bmpGraphics = Graphics.FromImage(screenBmp))
{
bmpGraphics.CopyFromScreen(rect.X, rect.Y, 0, 0, new Size(rect.Width, rect.Height));
return screenBmp;
}
}
19
Source : ImageUtils.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap RotateImage(Bitmap bmp, float angle)
{
int maxside = (int)(Math.Sqrt(bmp.Width * bmp.Width + bmp.Height * bmp.Height));
//create a new empty bmp to hold rotated image
Bitmap returnBitmap = new Bitmap(maxside, maxside);
//make a graphics object from the empty bmp
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
//rotate
g.RotateTransform(angle);
//move image back
g.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
//draw preplaceded in image onto graphics object
g.DrawImage(bmp, 10, 10);
return returnBitmap;
}
19
Source : ImageUtils.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap CaptureScreen()
{
Bitmap bitmap = new Bitmap(App.MyPosition.Width, App.MyPosition.Height, PixelFormat.Format32bppRgb);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
}
return bitmap;
}
19
Source : BitmapExtension.cs
with MIT License
from Bphots
with MIT License
from Bphots
public static Bitmap CropAtRect(this Bitmap b, Rectangle r)
{
var nb = new Bitmap(r.Width, r.Height);
using (var g = Graphics.FromImage(nb))
g.DrawImage(b, -r.X, -r.Y);
return nb;
}
19
Source : BitmapExtension.cs
with MIT License
from Bphots
with MIT License
from Bphots
public static Bitmap RotateImage(this Bitmap rotateMe, float angle, bool textInWhite = false)
{
angle = -angle;
var normalizedRotationAngle = NormalizeAngle(angle);
double widthD = rotateMe.Width, heightD = rotateMe.Height;
var newWidthD = Math.Cos(normalizedRotationAngle)*widthD + Math.Sin(normalizedRotationAngle)*heightD;
var newHeightD = Math.Cos(normalizedRotationAngle)*heightD + Math.Sin(normalizedRotationAngle)*widthD;
var newWidth = (int) Math.Ceiling(newWidthD);
var newHeight = (int) Math.Ceiling(newHeightD);
if (newWidth < newHeight)
{
var temp = newWidth;
newWidth = newHeight;
newHeight = temp;
}
using (var bmp = new Bitmap(newWidth, newHeight))
{
using (var g = Graphics.FromImage(bmp))
g.DrawImageUnscaled(rotateMe, (newWidth - rotateMe.Width) / 2, (newHeight - rotateMe.Height) / 2,
bmp.Width, bmp.Height);
//Now, actually rotate the image
var rotatedImage = new Bitmap(bmp.Width, bmp.Height);
using (var g = Graphics.FromImage(rotatedImage))
{
g.FillRectangle(textInWhite ? Brushes.Black : Brushes.White, 0, 0, rotatedImage.Width, rotatedImage.Height);
g.TranslateTransform(bmp.Width / 2, bmp.Height / 2);
//set the rotation point as the center into the matrix
g.RotateTransform(angle); //rotate
g.TranslateTransform(-bmp.Width / 2, -bmp.Height / 2); //restore rotation point into the matrix
g.DrawImage(bmp, new Point(0, 0)); //draw the image on the new bitmap
}
return rotatedImage;
}
}
19
Source : OcrEngine.cs
with MIT License
from Bphots
with MIT License
from Bphots
public Bitmap ExtendImage(Bitmap bmp)
{
var bitmap = new Bitmap((int)(bmp.Width * 1.1), bmp.Height, PixelFormat.Format32bppRgb);
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
graphics.DrawImage(bmp, (float)(0.05 * bitmap.Width), 0, new Rectangle(0, 0, bitmap.Width, bitmap.Height),
GraphicsUnit.Pixel);
}
return bitmap;
}
19
Source : Form1.cs
with MIT License
from BrandonHilde
with MIT License
from BrandonHilde
private void button3_Click(object sender, EventArgs e)
{
clrs = new Color[richTextBox1.Lines.Length];
for (int v = 0; v < richTextBox1.Lines.Length; v++)
{
try
{
clrs[v] = ColorTranslator.FromHtml(richTextBox1.Lines[v]);
}
catch
{
clrs[v] = Color.Transparent;
}
}
int num = (int)numericUpDown1.Value;
btm = (Bitmap)pictureBox1.Image;
bBt = new Bitmap(btm.Width, btm.Height);
using (g = Graphics.FromImage(bBt))
{
List<Color> block = new List<Color>();
Rectangle rec = new Rectangle();
SolidBrush sb = new SolidBrush(Color.Black);
Color final = Color.Black;
for (int x = 0; x < btm.Width; x += num)
{
for (int y = 0; y < btm.Height; y += num)
{
block = new List<Color>();
for (int v = 0; v < num; v++)
{
for (int c = 0; c < num; c++)
{
if (x + v < btm.Width && y + c < btm.Height)
{
block.Add(btm.GetPixel(x + v, y + c));
}
}
}
if (block.Count > 0)
{
final = Clr(block.ToArray());
sb.Color = final;
rec.X = x;
rec.Y = y;
rec.Width = num;
rec.Height = num;
g.FillRectangle(sb, rec);
}
}
}
pictureBox2.Image = bBt;
}
}
19
Source : Pixelation.cs
with GNU General Public License v3.0
from BRH-Media
with GNU General Public License v3.0
from BRH-Media
public static Bitmap Pixelate(Bitmap image, Rectangle rectangle, int blurSize)
{
var pixelated = new Bitmap(image.Width, image.Height);
// make an exact copy of the bitmap provided
using (var graphics = Graphics.FromImage(pixelated))
{
graphics.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height),
new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
}
// look at every pixel in the rectangle while making sure we're within the image bounds
for (var xx = rectangle.X; xx < rectangle.X + rectangle.Width && xx < image.Width; xx += blurSize)
for (var yy = rectangle.Y; yy < rectangle.Y + rectangle.Height && yy < image.Height; yy += blurSize)
{
var offsetX = blurSize / 2;
var offsetY = blurSize / 2;
// make sure that the offset is within the boundary of the image
while (xx + offsetX >= image.Width) offsetX--;
while (yy + offsetY >= image.Height) offsetY--;
// get the pixel color in the center of the soon to be pixelated area
var pixel = pixelated.GetPixel(xx + offsetX, yy + offsetY);
// for each pixel in the pixelate size, set it to the center color
for (var x = xx; x < xx + blurSize && x < image.Width; x++)
for (var y = yy; y < yy + blurSize && y < image.Height; y++)
pixelated.SetPixel(x, y, pixel);
}
return pixelated;
}
19
Source : NativeMethods.cs
with GNU General Public License v3.0
from brhinescot
with GNU General Public License v3.0
from brhinescot
internal static Image GetDesktopBitmap(int x, int y, int width, int height)
{
//Create the image and graphics to capture the portion of the desktop.
Image destinationImage = new Bitmap(width, height);
Graphics destinationGraphics = Graphics.FromImage(destinationImage);
IntPtr destinationGraphicsHandle = IntPtr.Zero;
try
{
//Pointers for window handles
destinationGraphicsHandle = destinationGraphics.GetHdc();
IntPtr windowDC = GetDC(IntPtr.Zero);
//Get the screencapture
int dwRop = SRCCOPY | CAPTUREBLT;
BitBlt(destinationGraphicsHandle, 0, 0, width, height, windowDC, x, y, dwRop);
}
finally
{
destinationGraphics.ReleaseHdc(destinationGraphicsHandle);
}
if (Configuration.Current.IncludeMouseCursorInCapture)
{
CURSORINFO cursorInfo;
cursorInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out cursorInfo);
ICONINFO iconInfo;
GetIconInfo(cursorInfo.hCursor, out iconInfo);
Icon mouseCursor = Icon.FromHandle(CopyIcon(cursorInfo.hCursor));
destinationGraphics.DrawIcon(mouseCursor, cursorInfo.ptScreenPos.X - x - iconInfo.xHotspot, cursorInfo.ptScreenPos.Y - y - iconInfo.yHotspot);
DeleteObject(iconInfo.hbmColor);
DeleteObject(iconInfo.hbmMask);
DestroyIcon(cursorInfo.hCursor);
}
// Don't forget to dispose this image
return destinationImage;
}
19
Source : NativeMethods.cs
with GNU General Public License v3.0
from brhinescot
with GNU General Public License v3.0
from brhinescot
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;
}
19
Source : Player.cs
with GNU General Public License v3.0
from BRH-Media
with GNU General Public License v3.0
from BRH-Media
private static Bitmap TextToBitmap(string text)
{
try
{
//create a dummy Bitmap just to get the Graphics object
var img = new Bitmap(1, 1);
var g = Graphics.FromImage(img);
//the font for our text
var f = new Font("Lucida Console", 32);
//work out how big the text will be when drawn as an image
var size = g.MeasureString(text, f);
//create a new Bitmap of the required size
img = new Bitmap((int)Math.Ceiling(size.Width), (int)Math.Ceiling(size.Height));
g = Graphics.FromImage(img);
//give it a black background
g.Clear(Color.Black);
//new outline path for string
var p = new GraphicsPath();
//apply string
p.AddString(text, f.FontFamily, (int)f.Style, f.Size, new Point(0, 0), new StringFormat());
//new pen
var pen = new Pen(Color.Yellow, 1);
//draw the text in yellow with white outline
g.DrawPath(pen, p);
//return processed image
return img;
}
catch
{
//nothing
}
//default
return null;
}
19
Source : CircularProgressBar.cs
with GNU General Public License v3.0
from BRH-Media
with GNU General Public License v3.0
from BRH-Media
protected virtual void RecreateBackgroundBrush()
{
lock (this)
{
_backBrush?.Dispose();
_backBrush = new SolidBrush(BackColor);
if (BackColor.A == 255)
return;
if (Parent != null && Parent.Width > 0 && Parent.Height > 0)
using (var parentImage = new Bitmap(Parent.Width, Parent.Height))
{
using (var parentGraphic = Graphics.FromImage(parentImage))
{
var pe = new PaintEventArgs(parentGraphic,
new Rectangle(new Point(0, 0), parentImage.Size));
InvokePaintBackground(Parent, pe);
InvokePaint(Parent, pe);
if (BackColor.A > 0) // Translucent
parentGraphic.FillRectangle(_backBrush, Bounds);
}
_backBrush = new TextureBrush(parentImage);
((TextureBrush)_backBrush).TranslateTransform(-Bounds.X, -Bounds.Y);
}
else
_backBrush = new SolidBrush(Color.FromArgb(255, BackColor));
}
}
19
Source : Copy.cs
with GNU General Public License v3.0
from BRH-Media
with GNU General Public License v3.0
from BRH-Media
public Image ToImage()
{
if (_cloneCopy && (_base._copyMode == CopyMode.Display || _base._copyMode == CopyMode.Video))
{
return _base.AV_DisplayCopy(_base._copyMode == CopyMode.Video, true);
}
Bitmap memoryImage = null;
if (_base._hasDisplay && (_base._hasVideo || _base._hasOverlayShown))
{
Rectangle r;
switch (_base._copyMode)
{
case CopyMode.Display:
r = _base._display.RectangleToScreen(_base._display.DisplayRectangle);
break;
case CopyMode.Form:
r = _base._display.FindForm().RectangleToScreen(_base._display.FindForm().DisplayRectangle);
break;
case CopyMode.Parent:
r = _base._display.Parent.RectangleToScreen(_base._display.Parent.DisplayRectangle);
break;
case CopyMode.Screen:
r = Screen.GetBounds(_base._display);
break;
default: // CopyMode.Video
if (_base._hasVideo) r = _base._display.RectangleToScreen(_base._videoBoundsClip);
else r = _base._display.RectangleToScreen(_base._display.DisplayRectangle);
break;
}
try
{
memoryImage = new Bitmap(r.Width, r.Height);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(r.Location.X, r.Location.Y, 0, 0, r.Size);
memoryGraphics.Dispose();
_base._lastError = Player.NO_ERROR;
}
catch (Exception e)
{
if (memoryImage != null) { memoryImage.Dispose(); memoryImage = null; }
_base._lastError = (HResult)Marshal.GetHRForException(e);
}
}
else
{
_base._lastError = HResult.MF_E_NOT_AVAILABLE;
}
return memoryImage;
}
19
Source : Form1.cs
with MIT License
from bulentsiyah
with MIT License
from bulentsiyah
public void ResimCizdir(int x, int y, int Normal)
{
int eskix = x;
int eskiy = 450;
bitmap = (Bitmap)GrafikSol.Image;
Graphics g = Graphics.FromImage(bitmap);
if (GenSayisi > SabitGenSayisi)
{
bitmap = (Bitmap)GrafikSag.Image;
g = Graphics.FromImage(bitmap);
}
if (Normal == 1)
{
g.DrawString((450 - y).ToString(), new Font("Microsoft Sans Serif", 12), new SolidBrush(Color.Black), x - 20, y - 25);
g.FillEllipse(new SolidBrush(Color.DarkRed), x - 5, y - 5, 10, 10);
g.DrawLine(new Pen(Color.DarkRed, 5), (float)eskix, (float)eskiy, (float)x, (float)y);
}
else
{
g.DrawString((450 - y).ToString(), new Font("Microsoft Sans Serif", 12), new SolidBrush(Color.Black), x - 20, y - 25);
g.FillEllipse(new SolidBrush(Color.DarkBlue), x - 5, y - 5, 10, 10);
g.DrawLine(new Pen(Color.DarkBlue, 5), (float)eskix, (float)eskiy, (float)x, (float)y);
}
if (GenSayisi > SabitGenSayisi)
{
GrafikSag.Image = bitmap;
}
else
{
GrafikSol.Image = bitmap;
}
}
19
Source : Form1.cs
with MIT License
from bulentsiyah
with MIT License
from bulentsiyah
public void ResimCizdir(int x, int y)
{
bitmap = (Bitmap)KrokiKampus.Image;
Graphics g = Graphics.FromImage(bitmap);
g.FillEllipse(new SolidBrush(Color.DarkRed), x - 5, y - 5, 10, 10);
//g.DrawString(">>", new Font("Arial", 7), new SolidBrush(Color.White), x - 10, y - 10);
if (eskix != -1)
{
g.DrawLine(new Pen(Color.Red), (float)eskix, (float)eskiy, (float)x, (float)y);
}
eskix = x;
eskiy = y;
KrokiKampus.Image = bitmap;
}
19
Source : GachaManager.cs
with GNU Affero General Public License v3.0
from cc004
with GNU Affero General Public License v3.0
from cc004
public Image GenerateCard(short cardId, bool transformed)
{
var img = new Bitmap(180, 180);
var cardInfo = CardMap[cardId.ToString()];
var resource = cardInfo.cardRes;
var attribute = cardInfo.attr;
var rarity = cardInfo.rarity;
var band = (byte)((cardInfo.characterId - 1) / 5);
var tex = LoadTexture(GetCard(resource + (transformed ? "_after_training" : "_normal")) ??
GetCard(resource + "_normal"));
var frame = LoadTexture(GetFrame(attribute, rarity));
var star = LoadTexture(GetMisc(transformed ? 1 : 0));
var bandtex = LoadTexture(GetBands(band));
var attr = LoadTexture(GetAttribute(attribute));
var canvas = Graphics.FromImage(img);
canvas.Clear(Color.Transparent);
canvas.DrawImage(tex, 0, 0);
canvas.DrawImage(frame, 0, 0);
canvas.DrawImage(bandtex, new RectangleF(2, 2, bandtex.Width * 1f, bandtex.Height * 1f));
canvas.DrawImage(attr, new RectangleF(132, 2, 46, 46));
for (int i = 0; i < rarity; ++i)
canvas.DrawImage(star, new Rectangle(0, 170 - 28 * (i + 1), 35, 35));
img.MakeTransparent();
tex.Dispose(); frame.Dispose(); star.Dispose(); bandtex.Dispose(); attr.Dispose();
return img;
}
19
Source : GachaManager.cs
with GNU Affero General Public License v3.0
from cc004
with GNU Affero General Public License v3.0
from cc004
public async Task<Tuple<string, Image>> Gacha(short gachaId, Random rand = null)
{
await Task.Yield();
var gachaInfo = GachaMap[gachaId.ToString()];
var detail = gachaInfo.details;
rand ??= new Random();
var method = gachaInfo.paymentMethods.OrderByDescending((obj) => (int)obj.count).First();
var behavior = method.behavior;
var count = method.count;
short[] cardIds = new short[count];
for (int i = 0; i < count; ++i)
{
var rate = rand.NextDouble() * 100f;
Rate rarityIndex = null, rarity3 = null, rarity4 = null;
foreach (var obj in gachaInfo.rates)
{
if (obj.rarityIndex == 3)
rarity3 = obj;
if (obj.rarityIndex == 4)
rarity4 = obj;
rate -= obj.rate;
if (rate < 0f && rarityIndex == null)
{
rarityIndex = obj;
}
}
if (i == count - 1)
{
switch (behavior)
{
case "fixed_4_star_once":
rarityIndex = rarity4;
break;
case "over_the_3_star_once":
if (rarityIndex.rarityIndex == 2)
rarityIndex = rarity3;
break;
}
}
byte index = rarityIndex.rarityIndex;
var rweight = rand.Next(rarityIndex.weightTotal);
foreach (var card in detail)
{
if (card.rarityIndex != index)
continue;
rweight -= card.weight;
if (rweight < 0)
{
cardIds[i] = card.situationId;
break;
}
}
}
var result = new Bitmap(GetMisc(2));
var canvas = Graphics.FromImage(result);
for (int i = 0; i < count; ++i)
{
using var card = GenerateCard(cardIds[i], false);
canvas.DrawImage(card, new Rectangle(292 + 324 * (i % 5), 496 + 326 * (i / 5), 290, 290));
}
return new Tuple<string, Image>(gachaInfo.gachaName, result);
}
19
Source : JJCManager.cs
with GNU Affero General Public License v3.0
from cc004
with GNU Affero General Public License v3.0
from cc004
private Image GetImage(Result[] teams)
{
var n = teams.Length;
var result = new Bitmap(1130 + 590, 120 * n + 20);
var canvas = Graphics.FromImage(result);
canvas.Clear(Color.White);
for (int i = 0; i < n; ++i) DrawToGraphics(canvas, teams[i], 0, i * 120);
canvas.DrawString($"powered by www.pcrdfans.com", font, Brushes.Black, 0, 120 * n);
canvas.Dispose();
return result;
}
19
Source : Utils.cs
with GNU Affero General Public License v3.0
from cc004
with GNU Affero General Public License v3.0
from cc004
public static string ToImageText(this string str)
{
using var bitmap = new Bitmap(1, 1);
using var g = Graphics.FromImage(bitmap);
var lines = str.Split('\n', StringSplitOptions.RemoveEmptyEntries);
var sizes = lines.Select(l => g.MeasureString(l, font)).ToArray();
var img = new Bitmap((int)sizes.Max(s => s.Width) + 6, (int)sizes.Sum(s => s.Height) + 6);
using (var g2 = Graphics.FromImage(img))
{
g2.Clear(Color.White);
var h = 3f;
for (int i = 0; i < lines.Length; ++i)
{
g2.DrawString(lines[i], font, brush, 3, h);
h += sizes[i].Height;
}
}
return GetImageCode(img);
}
19
Source : Utils.cs
with GNU Affero General Public License v3.0
from cc004
with GNU Affero General Public License v3.0
from cc004
public static string ToImageText(this string str)
{
using var bitmap = new Bitmap(1, 1);
using var g = Graphics.FromImage(bitmap);
var lines = str.Split('\n', StringSplitOptions.RemoveEmptyEntries);
var sizes = lines.Select(l => g.MeasureString(l, font)).ToArray();
var img = new Bitmap((int)sizes.Max(s => s.Width) + 6, (int)sizes.Sum(s => s.Height) + 6);
using (var g2 = Graphics.FromImage(img))
{
g2.Clear(Color.White);
var h = 3f;
for (int i = 0; i < lines.Length; ++i)
{
g2.DrawString(lines[i], font, brush, 3, h);
h += sizes[i].Height;
}
}
return GetImageCode(img);
}
19
Source : CodeFile1.cs
with GNU Lesser General Public License v3.0
from ccbpm
with GNU Lesser General Public License v3.0
from ccbpm
public void Render(string replacedle, string subreplacedle, int width, int height, DataTable dt)
{
const int SIDE_LENGTH = 400;
const int PIE_DIAMETER = 200;
//通过输入参数,取得饼图中的总基数
float sumData = 0;
foreach (DataRow dr in dt.Rows)
{
sumData += Convert.ToSingle(dr[1]);
}
//产生一个image对象,并由此产生一个Graphics对象
Bitmap bm = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bm);
//设置对象g的属性
g.ScaleTransform((Convert.ToSingle(width)) / SIDE_LENGTH, (Convert.ToSingle(height)) / SIDE_LENGTH);
g.SmoothingMode = SmoothingMode.Default;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
//画布和边的设定
g.Clear(Color.White);
g.DrawRectangle(Pens.Black, 0, 0, SIDE_LENGTH - 1, SIDE_LENGTH - 1);
//画饼图标题
g.DrawString(replacedle, new Font("Tahoma", 24), Brushes.Black, new PointF(5, 5));
//画饼图的图例
g.DrawString(subreplacedle, new Font("Tahoma", 14), Brushes.Black, new PointF(7, 35));
//画饼图
float curAngle = 0;
float totalAngle = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
curAngle = Convert.ToSingle(dt.Rows[i][1]) / sumData * 360;
g.FillPie(new SolidBrush(ChartUtil.GetCharreplacedemColor(i)), 100, 65, PIE_DIAMETER, PIE_DIAMETER, totalAngle, curAngle);
g.DrawPie(Pens.Black, 100, 65, PIE_DIAMETER, PIE_DIAMETER, totalAngle, curAngle);
totalAngle += curAngle;
}
//画图例框及其文字
g.DrawRectangle(Pens.Black, 200, 300, 199, 99);
g.DrawString("Legend", new Font("Tahoma", 12, FontStyle.Bold), Brushes.Black, new PointF(200, 300));
//画图例各项
PointF boxOrigin = new PointF(210, 330);
PointF textOrigin = new PointF(235, 326);
float percent = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
g.FillRectangle(new SolidBrush(ChartUtil.GetCharreplacedemColor(i)), boxOrigin.X, boxOrigin.Y, 20, 10);
g.DrawRectangle(Pens.Black, boxOrigin.X, boxOrigin.Y, 20, 10);
percent = Convert.ToSingle(dt.Rows[i][1]) / sumData * 100;
g.DrawString(dt.Rows[i][0].ToString() + " - " + dt.Rows[i][1].ToString() + " (" + percent.ToString("0") + "%)", new Font("Tahoma", 10), Brushes.Black, textOrigin);
boxOrigin.Y += 15;
textOrigin.Y += 15;
}
//通过Response.OutputStream,将图形的内容发送到浏览器
string file = SystemConfig.PathOfTemp + "Pie" + Web.WebUser.No + ".gif";
bm.Save(file, ImageFormat.Gif);
//回收资源
bm.Dispose();
g.Dispose();
}
19
Source : CodeFile1.cs
with GNU Lesser General Public License v3.0
from ccbpm
with GNU Lesser General Public License v3.0
from ccbpm
public void Render(string replacedle, string subreplacedle, int width, int height, DataTable dt, Stream target)
{
const int SIDE_LENGTH = 400;
const int CHART_TOP = 75;
const int CHART_HEIGHT = 200;
const int CHART_LEFT = 50;
const int CHART_WIDTH = 300;
// DataTable dt = chartData.Tables[0];
//计算最高的点
float highPoint = 0;
foreach (DataRow dr in dt.Rows)
{
if (highPoint < Convert.ToSingle(dr[1]))
{
highPoint = Convert.ToSingle(dr[1]);
}
}
//建立一个Graphics对象实例
Bitmap bm = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bm);
//设置条图图形和文字属性
g.ScaleTransform((Convert.ToSingle(width)) / SIDE_LENGTH, (Convert.ToSingle(height)) / SIDE_LENGTH);
g.SmoothingMode = SmoothingMode.Default;
g.TextRenderingHint = TextRenderingHint.AntiAlias;
//设定画布和边
g.Clear(Color.White);
g.DrawRectangle(Pens.Black, 0, 0, SIDE_LENGTH - 1, SIDE_LENGTH - 1);
//画大标题
g.DrawString(replacedle, new Font("Tahoma", 24), Brushes.Black, new PointF(5, 5));
//画小标题
g.DrawString(subreplacedle, new Font("Tahoma", 14), Brushes.Black, new PointF(7, 35));
//画条形图
float barWidth = CHART_WIDTH / (dt.Rows.Count * 2);
PointF barOrigin = new PointF(CHART_LEFT + (barWidth / 2), 0);
float barHeight = dt.Rows.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
barHeight = Convert.ToSingle(dt.Rows[i][1]) * 200 / highPoint;
barOrigin.Y = CHART_TOP + CHART_HEIGHT - barHeight;
g.FillRectangle(new SolidBrush(ChartUtil.GetCharreplacedemColor(i)), barOrigin.X, barOrigin.Y, barWidth, barHeight);
barOrigin.X = barOrigin.X + (barWidth * 2);
}
//设置边
g.DrawLine(new Pen(Color.Black, 2), new Point(CHART_LEFT, CHART_TOP), new Point(CHART_LEFT, CHART_TOP + CHART_HEIGHT));
g.DrawLine(new Pen(Color.Black, 2), new Point(CHART_LEFT, CHART_TOP + CHART_HEIGHT), new Point(CHART_LEFT + CHART_WIDTH, CHART_TOP + CHART_HEIGHT));
//画图例框和文字
g.DrawRectangle(new Pen(Color.Black, 1), 200, 300, 199, 99);
g.DrawString("Legend", new Font("Tahoma", 12, FontStyle.Bold), Brushes.Black, new PointF(200, 300));
//画图例
PointF boxOrigin = new PointF(210, 330);
PointF textOrigin = new PointF(235, 326);
for (int i = 0; i < dt.Rows.Count; i++)
{
g.FillRectangle(new SolidBrush(ChartUtil.GetCharreplacedemColor(i)), boxOrigin.X, boxOrigin.Y, 20, 10);
g.DrawRectangle(Pens.Black, boxOrigin.X, boxOrigin.Y, 20, 10);
g.DrawString(dt.Rows[i][0].ToString() + " - " + dt.Rows[i][1].ToString(), new Font("Tahoma", 10), Brushes.Black, textOrigin);
boxOrigin.Y += 15;
textOrigin.Y += 15;
}
//输出图形
bm.Save(BP.Sys.SystemConfig.PathOfTemp+"Bar"+BP.Web.WebUser.No+".gif", ImageFormat.Gif);
//资源回收
bm.Dispose();
g.Dispose();
}
19
Source : GenerSiganture.cs
with GNU Lesser General Public License v3.0
from ccbpm
with GNU Lesser General Public License v3.0
from ccbpm
public override object Do()
{
try
{
BP.Port.Emps emps = new Emps();
emps.RetrieveAllFromDBSource();
string path = BP.Sys.SystemConfig.PathOfDataUser + "\\Siganture\\T.JPG";
string fontName = "宋体";
string empOKs = "";
string empErrs = "";
foreach (Emp emp in emps)
{
string pathMe = BP.Sys.SystemConfig.PathOfDataUser + "\\Siganture\\" + emp.No + ".JPG";
if (System.IO.File.Exists(pathMe))
continue;
File.Copy(BP.Sys.SystemConfig.PathOfDataUser + "\\Siganture\\Templete.JPG",
path, true);
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
Font font = new Font(fontName, 15);
Graphics g = Graphics.FromImage(img);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);//文本
g.DrawString(emp.Name, font, drawBrush, 3, 3);
img.Save(pathMe);
img.Dispose();
g.Dispose();
File.Copy(pathMe,
BP.Sys.SystemConfig.PathOfDataUser + "\\Siganture\\" + emp.Name + ".JPG", true);
}
return "执行成功...";
}
catch(Exception ex)
{
return "执行失败,请确认对 " + BP.Sys.SystemConfig.PathOfDataUser + "\\Siganture\\ 目录有访问权限?异常信息:"+ex.Message;
}
}
19
Source : WaterImage.cs
with GNU Lesser General Public License v3.0
from ccbpm
with GNU Lesser General Public License v3.0
from ccbpm
public string DrawImage(string sourcePicture,
string waterImage,
float alpha,
ImagePosition position,
string PicturePath)
{
//
// 判断参数是否有效
//
if (sourcePicture == string.Empty || waterImage == string.Empty || alpha == 0.0 || PicturePath == string.Empty)
{
return sourcePicture;
}
//
// 源图片,水印图片全路径
//
string sourcePictureName = PicturePath + sourcePicture;
string waterPictureName = PicturePath + waterImage;
string fileSourceExtension = System.IO.Path.GetExtension(sourcePictureName).ToLower();
string fileWaterExtension = System.IO.Path.GetExtension(waterPictureName).ToLower();
//
// 判断文件是否存在,以及类型是否正确
//
if (System.IO.File.Exists(sourcePictureName) == false ||
System.IO.File.Exists(waterPictureName) == false || (
fileSourceExtension != ".gif" &&
fileSourceExtension != ".jpg" &&
fileSourceExtension != ".png") || (
fileWaterExtension != ".gif" &&
fileWaterExtension != ".jpg" &&
fileWaterExtension != ".png")
)
{
return sourcePicture;
}
//
// 目标图片名称及全路径
//
string targetImage = sourcePictureName.Replace(System.IO.Path.GetExtension(sourcePictureName), "") + "_1101.jpg";
//
// 将需要加上水印的图片装载到Image对象中
//
Image imgPhoto = Image.FromFile(sourcePictureName);
//
// 确定其长宽
//
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
//
// 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。
//
Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
//
// 设定分辨率
//
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//
// 定义一个绘图画面用来装载位图
//
Graphics grPhoto = Graphics.FromImage(bmPhoto);
//
//同样,由于水印是图片,我们也需要定义一个Image来装载它
//
Image imgWatermark = new Bitmap(waterPictureName);
//
// 获取水印图片的高度和宽度
//
int wmWidth = imgWatermark.Width;
int wmHeight = imgWatermark.Height;
//SmoothingMode:指定是否将平滑处理(消除锯齿)应用于直线、曲线和已填充区域的边缘。
// 成员名称 说明
// AntiAlias 指定消除锯齿的呈现。
// Default 指定不消除锯齿。
// HighQuality 指定高质量、低速度呈现。
// HighSpeed 指定高速度、低质量呈现。
// Invalid 指定一个无效模式。
// None 指定不消除锯齿。
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
//
// 第一次描绘,将我们的底图描绘在绘图画面上
//
grPhoto.DrawImage(imgPhoto,
new Rectangle(0, 0, phWidth, phHeight),
0,
0,
phWidth,
phHeight,
GraphicsUnit.Pixel);
//
// 与底图一样,我们需要一个位图来装载水印图片。并设定其分辨率
//
Bitmap bmWatermark = new Bitmap(bmPhoto);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//
// 继续,将水印图片装载到一个绘图画面grWatermark
//
Graphics grWatermark = Graphics.FromImage(bmWatermark);
//
//ImageAttributes 对象包含有关在呈现时如何操作位图和图元文件颜色的信息。
//
ImageAttributes imageAttributes = new ImageAttributes();
//
//Colormap: 定义转换颜色的映射
//
ColorMap colorMap = new ColorMap();
//
//我的水印图被定义成拥有绿色背景色的图片被替换成透明
//
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, // red红色
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, //green绿色
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, //blue蓝色
new float[] {0.0f, 0.0f, 0.0f, alpha, 0.0f}, //透明度
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};//
// ColorMatrix:定义包含 RGBA 空间坐标的 5 x 5 矩阵。
// ImageAttributes 类的若干方法通过使用颜色矩阵调整图像颜色。
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
//
//上面设置完颜色,下面开始设置位置
//
int xPosOfWm;
int yPosOfWm;
switch (position)
{
case ImagePosition.BottomMiddle:
xPosOfWm = (phWidth - wmWidth) / 2;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.Center:
xPosOfWm = (phWidth - wmWidth) / 2;
yPosOfWm = (phHeight - wmHeight) / 2;
break;
case ImagePosition.LeftBottom:
xPosOfWm = 10;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.LeftTop:
xPosOfWm = 10;
yPosOfWm = 10;
break;
case ImagePosition.RightTop:
xPosOfWm = phWidth - wmWidth - 10;
yPosOfWm = 10;
break;
case ImagePosition.RigthBottom:
xPosOfWm = phWidth - wmWidth - 10;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.TopMiddle:
xPosOfWm = (phWidth - wmWidth) / 2;
yPosOfWm = 10;
break;
default:
xPosOfWm = 10;
yPosOfWm = phHeight - wmHeight - 10;
break;
}
// 第二次绘图,把水印印上去
//
grWatermark.DrawImage(imgWatermark,
new Rectangle(xPosOfWm,
yPosOfWm,
wmWidth,
wmHeight),
0,
0,
wmWidth,
wmHeight,
GraphicsUnit.Pixel,
imageAttributes);
imgPhoto = bmWatermark;
grPhoto.Dispose();
grWatermark.Dispose();
//
// 保存文件到服务器的文件夹里面
//
imgPhoto.Save(targetImage, ImageFormat.Jpeg);
imgPhoto.Dispose();
imgWatermark.Dispose();
return targetImage.Replace(PicturePath, "");
}
19
Source : WaterImage.cs
with GNU Lesser General Public License v3.0
from ccbpm
with GNU Lesser General Public License v3.0
from ccbpm
public string DrawWords(string sourcePictureName,
string waterWords,
float alpha,
ImagePosition position,
string targetImage)
{
//
// 判断参数是否有效
//
if (sourcePictureName == string.Empty || waterWords == string.Empty || alpha == 0.0 || sourcePictureName == string.Empty)
throw new Exception("@参数错误");
//
// 源图片全路径
//
string fileExtension = System.IO.Path.GetExtension(sourcePictureName).ToLower();
//
// 判断文件是否存在,以及文件名是否正确
//
if (System.IO.File.Exists(sourcePictureName) == false || (
fileExtension != ".gif" &&
fileExtension != ".jpg" &&
fileExtension != ".png"))
{
throw new Exception("@源文件格式错误" + sourcePictureName);
}
//创建一个图片对象用来装载要被添加水印的图片
Image imgPhoto = Image.FromFile(sourcePictureName);
//获取图片的宽和高
int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height;
//
//建立一个bitmap,和我们需要加水印的图片一样大小
Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
//SetResolution:设置此 Bitmap 的分辨率
//这里直接将我们需要添加水印的图片的分辨率赋给了bitmap
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//Graphics:封装一个 GDI+ 绘图图面。
Graphics grPhoto = Graphics.FromImage(bmPhoto);
//设置图形的品质
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
//将我们要添加水印的图片按照原始大小描绘(复制)到图形中
grPhoto.DrawImage(
imgPhoto, // 要添加水印的图片
new Rectangle(0, 0, phWidth, phHeight), // 根据要添加的水印图片的宽和高
0, // X方向从0点开始描绘
0, // Y方向
phWidth, // X方向描绘长度
phHeight, // Y方向描绘长度
GraphicsUnit.Pixel); // 描绘的单位,这里用的是像素
//根据图片的大小我们来确定添加上去的文字的大小
//在这里我们定义一个数组来确定
int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
//字体
Font crFont = null;
//矩形的宽度和高度,SizeF有三个属性,分别为Height高,width宽,IsEmpty是否为空
SizeF crSize = new SizeF();
//利用一个循环语句来选择我们要添加文字的型号
//直到它的长度比图片的宽度小
for (int i = 0; i < 7; i++)
{
crFont = new Font("arial", sizes[i], FontStyle.Italic);
//测量用指定的 Font 对象绘制并用指定的 StringFormat 对象格式化的指定字符串。
crSize = grPhoto.MeasureString(waterWords, crFont);
// ushort 关键字表示一种整数数据类型
if ((ushort)crSize.Width < (ushort)phWidth)
break;
}
//截边5%的距离,定义文字显示(由于不同的图片显示的高和宽不同,所以按百分比截取)
int yPixlesFromBottom = (int)(phHeight * .05);
//定义在图片上文字的位置
float wmHeight = crSize.Height;
float wmWidth = crSize.Width;
float xPosOfWm;
float yPosOfWm;
switch (position)
{
case ImagePosition.BottomMiddle:
xPosOfWm = phWidth / 2;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.Center:
xPosOfWm = phWidth / 2;
yPosOfWm = phHeight / 2;
break;
case ImagePosition.LeftBottom:
xPosOfWm = wmWidth;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.LeftTop:
xPosOfWm = wmWidth / 2;
yPosOfWm = wmHeight / 2;
break;
case ImagePosition.RightTop:
xPosOfWm = phWidth - wmWidth - 10;
yPosOfWm = wmHeight;
break;
case ImagePosition.RigthBottom:
xPosOfWm = phWidth - wmWidth - 10;
yPosOfWm = phHeight - wmHeight - 10;
break;
case ImagePosition.TopMiddle:
xPosOfWm = phWidth / 2;
yPosOfWm = wmWidth;
break;
default:
xPosOfWm = wmWidth;
yPosOfWm = phHeight - wmHeight - 10;
break;
}
//封装文本布局信息(如对齐、文字方向和 Tab 停靠位),显示操作(如省略号插入和国家标准 (National) 数字替换)和 OpenType 功能。
StringFormat StrFormat = new StringFormat();
//定义需要印的文字居中对齐
StrFormat.Alignment = StringAlignment.Center;
//SolidBrush:定义单色画笔。画笔用于填充图形形状,如矩形、椭圆、扇形、多边形和封闭路径。
//这个画笔为描绘阴影的画笔,呈灰色
int m_alpha = Convert.ToInt32(256 * alpha);
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));
//描绘文字信息,这个图层向右和向下偏移一个像素,表示阴影效果
//DrawString 在指定矩形并且用指定的 Brush 和 Font 对象绘制指定的文本字符串。
grPhoto.DrawString(waterWords, //string of text
crFont, //font
semiTransBrush2, //Brush
new PointF(xPosOfWm + 1, yPosOfWm + 1), //Position
StrFormat);
//从四个 ARGB 分量(alpha、红色、绿色和蓝色)值创建 Color 结构,这里设置透明度为153
//这个画笔为描绘正式文字的笔刷,呈白色
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
//第二次绘制这个图形,建立在第一次描绘的基础上
grPhoto.DrawString(waterWords, //string of text
crFont, //font
semiTransBrush, //Brush
new PointF(xPosOfWm, yPosOfWm), //Position
StrFormat);
//imgPhoto是我们建立的用来装载最终图形的Image对象
//bmPhoto是我们用来制作图形的容器,为Bitmap对象
imgPhoto = bmPhoto;
//释放资源,将定义的Graphics实例grPhoto释放,grPhoto功德圆满
grPhoto.Dispose();
//将grPhoto保存
imgPhoto.Save(targetImage, ImageFormat.Jpeg);
imgPhoto.Dispose();
return targetImage;
//return targetImage.Replace(PicturePath, "");
}
19
Source : FrmScreenShot.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
private Bitmap CopyScreen()
{
// 创建一个和屏幕一样大的空白图片
Bitmap bmp = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
using (Graphics g = Graphics.FromImage(bmp)) // 把屏幕图片拷贝到创建的空白图片中
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
return bmp;
}
19
Source : FrmScreenShot.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
private Bitmap CopyScreen(int x, int y, int w, int h)
{
// 创建一个和屏幕一样大的空白图片
Bitmap bmp = new Bitmap(w, h);
using (Graphics g = Graphics.FromImage(bmp))
g.CopyFromScreen(x, y, 0, 0, new Size(w, h));
return bmp;
}
19
Source : SpecifyScreenshot.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
public static Bitmap Screenshot(int x, int y, int width, int height)
{
Bitmap bit = new Bitmap(width, height);
try
{
using (Graphics g = Graphics.FromImage(bit))
{
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.CopyFromScreen(x, y, 0, 0, new Size(width, height));
return bit;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
19
Source : ImageSelectWeapon.cs
with GNU General Public License v3.0
from cdians
with GNU General Public License v3.0
from cdians
public void ValiLogic()
{
// 识别颜色
DateTime startTime = DateTime.Now;
if (!ValiOpenBag())
{
return;
}
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data/");
if (System.IO.Directory.Exists(path) == false)//如果不存在就创建file文件夹
{
System.IO.Directory.CreateDirectory(path);
}
string name = "";
string name1 = "";
Bitmap image = new Bitmap(globalParam.weapon0Location["basicSize"].X, globalParam.weapon0Location["basicSize"].Y);
Bitmap image1 = new Bitmap(globalParam.weapon1Location["basicSize"].X, globalParam.weapon1Location["basicSize"].Y);
Graphics imgGraphics = Graphics.FromImage(image);
imgGraphics.CopyFromScreen(globalParam.weapon0Location["basic"], new Point(0, 0), new Size(image.Width, image.Height)); //第一个参数是截图开始坐标,第二个参数是要拷贝到的Bitmap的开始位置,保持不变,最后是图片大小
if (BaseConfig.DEBUG)
{
image.Save(path + Guid.NewGuid().ToString() + ".png");
}
name = path + GetRandomString(9, true, true, false, false, null);
CutImage(image, name + ".png");
Graphics imgGraphics1 = Graphics.FromImage(image1);
imgGraphics1.CopyFromScreen(globalParam.weapon1Location["basic"], new Point(0, 0), new Size(image1.Width, image1.Height)); //第一个参数是截图开始坐标,第二个参数是要拷贝到的Bitmap的开始位置,保持不变,最后是图片大小
if (BaseConfig.DEBUG)
{
image1.Save(path + Guid.NewGuid().ToString() + ".png");
}
name1 = path + GetRandomString(10, true, true, false, false, null);
CutImage(image1, name1 + ".png");
try
{
string lastWeaponName0 = player.weapon0.weapon;
string lastWeaponName1 = player.weapon1.weapon;
string useWeaponName = player.useWeapon.weapon;
string weaponName = GetOCRWeapon(name + ".png");
if (!String.IsNullOrEmpty(weaponName))
{
// 配件信息
Dictionary<string, string> other = QueryAccessories(globalParam.weapon0Location, image);
player.weapon0.weapon = weaponName;
if (null != other)
{
player.weapon0.qiangkou = other["qiangkou"];
player.weapon0.woBa = other["woBa"];
player.weapon0.magazine = other["magazine"];
player.weapon0.qiangTuo = other["qiangTuo"];
player.weapon0.scope = other["scope"];
GetWeaponData(player.weapon0);
if (player.useWeapon.weapon.Equals("空"))
{
player.useWeapon = player.weapon0;
}
}
} else
{
player.weapon0.ClearAttr();
}
string weaponName1 = GetOCRWeapon(name1 + ".png");
if (!String.IsNullOrEmpty(weaponName1))
{
// 配件信息
Dictionary<string, string> other = QueryAccessories(globalParam.weapon1Location, image1);
player.weapon1.weapon = weaponName1;
if (null != other)
{
player.weapon1.qiangkou = other["qiangkou"];
player.weapon1.woBa = other["woBa"];
player.weapon1.magazine = other["magazine"];
player.weapon1.qiangTuo = other["qiangTuo"];
player.weapon1.scope = other["scope"];
GetWeaponData(player.weapon1);
if (player.useWeapon.weapon.Equals("空"))
{
player.useWeapon = player.weapon1;
}
}
} else
{
player.weapon1.ClearAttr();
}
if (!String.IsNullOrEmpty(weaponName) || !String.IsNullOrEmpty(weaponName1))
{
// 交换武器位置识别
if (useWeaponName.Equals(weaponName) && lastWeaponName0.Equals(weaponName1) && lastWeaponName1.Equals(weaponName))
{
player.useWeapon = player.weapon0;
} else if (useWeaponName.Equals(weaponName1) && lastWeaponName0.Equals(weaponName1) && lastWeaponName1.Equals(weaponName))
{
player.useWeapon = player.weapon1;
}
if (String.IsNullOrEmpty(weaponName) && !String.IsNullOrEmpty(weaponName1))
{
player.useWeapon = player.weapon1;
} else if (!String.IsNullOrEmpty(weaponName) && String.IsNullOrEmpty(weaponName1))
{
player.useWeapon = player.weapon0;
}
if (jichuViewModel.Speaker && !_speakerStatus)
{
_speakerStatus = true;
Task.Run(() =>
{
SpeechSynthesizer synthes = new SpeechSynthesizer();
synthes.Speak("识别成功");//异步
_speakerStatus = false;
});
}
}
playerViewModel.Refresh();
gunsViewModel.Refresh();
}
catch (Exception ex)
{
LogHelper.ShowLog("识别枪械报错 错误信息: {0}", ex.Message);
}
LogHelper.ShowLog("枪械识别耗时: {0}", (DateTime.Now - startTime).ToString());
}
19
Source : FrmScreenShot.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
public Image CopyScreen()
{
// 创建一个和屏幕一样大的空白图片
using (Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
// 把屏幕图片拷贝到创建的空白图片中
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height));
return (Bitmap)bmp.Clone();
}
}
}
19
Source : FireLogic.cs
with GNU General Public License v3.0
from cdians
with GNU General Public License v3.0
from cdians
private static void XueWu()
{
AppInfo appInfo = AppInfo.GetAppInfo();
GlobalParam globalParam = GlobalParam.GetGlobalParam();
Bitmap image = new Bitmap(140, 60);
Point cutPoint = new Point(((int)appInfo.screenWidth / 2 - (image.Width / 2)), ((int)appInfo.screenHeight / 2) - (image.Height / 2));
Graphics imgGraphics = Graphics.FromImage(image);
imgGraphics.CopyFromScreen(cutPoint, new Point(0,0) ,new Size(image.Width, image.Height)); //第一个参数是截图开始坐标,第二个参数是要拷贝到的Bitmap的开始位置,保持不变,最后是图片大小
if (BaseConfig.DEBUG)
{
image.Save("cut.png");
}
int interval = 8;
int x = 0;
int y = 0;
Color pixel;//颜色匹对
Color color = ColorTranslator.FromHtml("#B50D6B");
for (int i =0;i<image.Width;i++)
{
for (int j=0;j<image.Height;j++)
{
pixel = image.GetPixel(i, j);
if (Math.Abs(pixel.R - color.R) < interval &&
Math.Abs(pixel.G - color.G) < interval &&
Math.Abs(pixel.B - color.B) < interval)
{
x = (cutPoint.X + i) - ((int)appInfo.screenWidth / 2);
//y = ((int)appInfo.screenHeight / 2) - (cutPoint.Y + j);
LogHelper.ShowLog("get Xuewu X: {0} Y: {1}", x, y);
YouyiSdk.M_MoveR2(globalParam.m_Handle, x, 0);
return;
}
}
}
}
19
Source : Screenshot.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
public static Bitmap ScreenCapture(int x, int y, int width, int height)
{
Bitmap bit = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bit))
{
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.CopyFromScreen(x, y, 0, 0, new Size(width, height));
return bit;
}
}
19
Source : MainForm.cs
with MIT License
from cdmxz
with MIT License
from cdmxz
private static Bitmap ResizeImage(Bitmap oldBmp, Size newSize)
{
if (oldBmp == null)
throw new Exception("函数名:ResizeImage\n原因:参数oldBmp为空!");
Bitmap newBmp = new Bitmap(newSize.Width, newSize.Height);
using (Graphics g = Graphics.FromImage(newBmp))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;// 高质量
g.DrawImage(oldBmp, new Rectangle(0, 0, newSize.Width, newSize.Height), new Rectangle(0, 0, oldBmp.Width, oldBmp.Height), GraphicsUnit.Pixel);
oldBmp.Dispose();
return newBmp;
}
}
19
Source : Form1.cs
with GNU General Public License v3.0
from Charltsing
with GNU General Public License v3.0
from Charltsing
private void CaptureAndriod()
{
//截屏获取图片
ADB.RunADBShellCommand("shell screencap -p");
if (ADB.bytesOutputfixed != null)
{
using (MemoryStream pngStream = new MemoryStream(ADB.bytesOutputfixed))
{
HiPerfTimer timer = new HiPerfTimer();
timer.Start();
Bitmap bmpfix = null;
try
{
bmpfix = DetectStartPoint(pngStream);
//为什么有的手机截屏画面上下颠倒呢???
if (cbxRotate180.Checked) bmpfix.RotateFlip(RotateFlipType.Rotate180FlipNone);
using (Graphics g = Graphics.FromImage(bmpfix))
{
using (Font font = new Font("Times New Roman", 36))
{
string xyText = "(" + StartX.ToString() + "," + StartY.ToString() + ")";
g.DrawString(xyText, font, Brushes.Red, new PointF(10, 30));
}
}
}
catch (Exception ex)
{
Invoke(new MethodInvoker(delegate ()
{
{
if (rtbCmd != null)
{
rtbCmd.AppendText(ex.ToString());
rtbCmd.ScrollToCaret();
}
}
}));
}
timer.Stop();
if (bmpfix != null)
{
string tmp = "Detect:" + timer.Duration.ToString() + "\r\n";
Invoke(new MethodInvoker(delegate ()
{
{
if (rtbCmd != null)
{
rtbCmd.AppendText(tmp);
rtbCmd.ScrollToCaret();
}
}
}));
pictureBox1.Invoke(new Action(() =>
{
pictureBox1.Image = bmpfix;
pictureBox1.Refresh();
}));
}
else
{
Invoke(new MethodInvoker(delegate ()
{
{
if (rtbCmd != null)
{
rtbCmd.AppendText("bmpfix is null!");
rtbCmd.ScrollToCaret();
}
}
}));
}
}
}
else
{
Invoke(new MethodInvoker(delegate ()
{
{
if (rtbCmd != null)
{
rtbCmd.AppendText("bytesOutputfixed is null!");
rtbCmd.ScrollToCaret();
}
}
}));
}
}
19
Source : FrmInfo.cs
with MIT License
from ChDC
with MIT License
from ChDC
private void drawMemoryUsage(float value)
{
Control control = lblMemory;
Bitmap b = new Bitmap(control.Width, control.Height);
Graphics g = Graphics.FromImage(b);
//draw background
g.FillRectangle(new SolidBrush(Color.FromArgb(28, 28, 29)), 0, 0, control.Width, control.Height);
// draw usage rect
int width = (int)(control.Width * value);
Rectangle rect = new Rectangle(0, 0, width, control.Height);
//LinearGradientBrush brush = new LinearGradientBrush(control.ClientRectangle, Color.FromArgb(17, 160, 255), Color.FromArgb(23,174,254), LinearGradientMode.Vertical);
//brush.SetSigmaBellShape(0.5f);
//g.FillRectangle(brush, rect);
g.FillRectangle(new SolidBrush(Color.FromArgb(0, 186, 255)), rect);
// border
g.DrawRectangle(new Pen(Color.FromArgb(28, 28, 29), 3), 0, 0, control.Width-2, control.Height-2);
g.Dispose();
control.BackgroundImage = b;
}
19
Source : components.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
private Image resize_icon(Image image)
{
Bitmap bitmap = new Bitmap(40, 40);
Graphics graphics = Graphics.FromImage(bitmap);
int left = (40 < image.Width) ? (image.Width - 40) / 2 : 0;
int top = (40 < image.Height) ? (image.Height - 40) / 2 : 0;
int width = (40 < image.Width) ? 40 : image.Width;
int height = (40 < image.Height) ? 40 : image.Height;
graphics.DrawImage(image, new Rectangle((40 - width) / 2, (40 - height) / 2, width, height), new Rectangle(left, top, width, height), GraphicsUnit.Pixel);
graphics.Dispose();
image.Dispose();
return bitmap;
}
19
Source : momiji_base.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
protected static Image generate_pattern(int size)
{
Image image = new Bitmap(size * 2, size * 2);
Graphics graphics = Graphics.FromImage(image);
graphics.FillRectangles(Brushes.LightGray, new Rectangle[]
{
new Rectangle(0, 0, size, size),
new Rectangle(size, size, size, size),
});
graphics.FillRectangles(Brushes.White, new Rectangle[]
{
new Rectangle(0, size, size, size),
new Rectangle(size, 0, size, size),
});
graphics.Dispose();
return image;
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
private void generate_gradient_wheel()
{
Color[] colors;
Region region;
PathGradientBrush brush;
GraphicsPath path = new GraphicsPath();
GraphicsPath ellipse = new GraphicsPath();
Graphics graphics = Graphics.FromImage(wheel);
int diameter = wheel.Width;
int inscribe = diameter / 10;
--diameter;
path.AddEllipse(0, 0, diameter, diameter);
ellipse.AddEllipse(inscribe, inscribe, diameter - inscribe * 2, diameter - inscribe * 2);
path.Flatten();
region = new Region(ellipse);
brush = new PathGradientBrush(path);
colors = new Color[path.PointCount];
for (int index = 0; index < path.PointCount; ++index)
{
double angle = (double)index / path.PointCount + 0.375/*135.0 / 180.0*/;
if (.0 > angle)
angle = angle + 1.0;
else if (1.0 <= angle)
angle = angle - 1.0;
colors[index] = hsv.hsv_2_rgb(angle, 1.0, 1.0);
}
brush.SurroundColors = colors;
graphics.SetClip(region, CombineMode.Exclude);
graphics.FillEllipse(brush, 0, 0, diameter, diameter);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.DrawEllipse(SystemPens.Control, 0, 0, diameter, diameter);
graphics.DrawPath(SystemPens.Control, ellipse);
graphics.Dispose();
region.Dispose();
brush.Dispose();
ellipse.Dispose();
path.Dispose();
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
unsafe private void generate_gradient_triangle()
{
double vsh;
Graphics graphics;
PointF hue, saturation, value;
BitmapData data = triangle.LockBits(new Rectangle(Point.Empty, triangle.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
int* pixels = (int*)data.Scan0;
compute_triangle(out hue, out saturation, out value);
vsh = vector_cross(value, saturation, hue);
for (int y = 0; y < triangle.Height; ++y)
for (int x = 0; x < triangle.Width; ++x)
{
Point point = new Point(x, y);
*pixels++ = compute_color(vsh,
vector_cross(value, saturation, point),
vector_cross(hue, value, point),
vector_cross(saturation, hue, point), false);
}
triangle.UnlockBits(data);
graphics = Graphics.FromImage(triangle);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.DrawPolygon(SystemPens.Control, new PointF[] { hue, saturation, value, });
graphics.Dispose();
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
private void paint(object o, PaintEventArgs e)
{
IntPtr hdc;
Bitmap bitmap = new Bitmap(Width, Height);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.DrawImage(wheel, PointF.Empty);
graphics.DrawImage(triangle, (float)(wheel.Width / 10.0), (float)(wheel.Width / 10.0));
graphics.Dispose();
e.Graphics.DrawImage(bitmap, Point.Empty);
hdc = e.Graphics.GetHdc();
draw_ellipse(rotate_point((wheel.Width - 1.0) / 2.0 - wheel.Width / 20.0, .0, wheel.Width / 2.0, 0), hdc);
draw_ellipse(compute_point(), hdc);
e.Graphics.ReleaseHdc();
bitmap.Dispose();
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
private void update_gradient_front(Color[] colors)
{
float[] positions = new float[colors.Length];
Graphics graphics = Graphics.FromImage(image);
Rectangle rectangle = new Rectangle(Point.Empty, image.Size);
LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Transparent, Color.Transparent, .0f);
ColorBlend blend = new ColorBlend();
for (int index = 0; index < positions.Length; ++index)
positions[index] = index / (positions.Length - 1.0f);
blend.Colors = colors;
blend.Positions = positions;
brush.InterpolationColors = blend;
graphics.FillRectangle(brush, rectangle);
graphics.Dispose();
brush.Dispose();
Refresh();
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
internal void update_gradient(Color[] colors)
{
TextureBrush texture = generate_pattern_brush((Height - 9) / 2);
Graphics graphics = Graphics.FromImage(image);
graphics.FillRectangle(texture, new Rectangle(Point.Empty, image.Size));
graphics.Dispose();
texture.Dispose();
update_gradient_front(colors);
}
19
Source : palette.cs
with BSD 2-Clause "Simplified" License
from chengse66
with BSD 2-Clause "Simplified" License
from chengse66
private void paint(object o, PaintEventArgs e)
{
Pen triangle;
Bitmap bitmap = new Bitmap(Width, Height);
Graphics graphics = Graphics.FromImage(bitmap);
int position = (int)(value * (Width - 41.0) / maximum);
graphics.Clear(BackColor);
draw_border(hovered, new Rectangle(1, 0, Width - 36, Height - 5), graphics);
if (hovered)
triangle = new Pen(Color.FromArgb(0xc3, 0x76, 0x3d));
else
triangle = new Pen(Color.FromArgb(0x73, 0x73, 0x73));
graphics.DrawPolygon(triangle, new Point[] { new Point(position + 3, Height - 5), new Point(position + 6, Height - 2), new Point(position + 6, Height - 1), new Point(position, Height - 1), new Point(position, Height - 2), });
graphics.DrawString(text, Font, SystemBrushes.ControlText, Width - 35, 0);
if (null != image)
graphics.DrawImage(image, 3, 2, Width - 40, Height - 9);
graphics.Dispose();
triangle.Dispose();
e.Graphics.DrawImage(bitmap, 0, 0);
bitmap.Dispose();
}
See More Examples