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; }
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); }
private void Form1_Paint(object sender, PaintEventArgs e) { //g.DrawLine(pen, new Point(1, 1), new Point(300, 100)); //g.DrawLine(pen, new Point(100, 1), new Point(300, 100)); //g.DrawRectangle(pen, new Rectangle(50, 50, 100, 100)); //g.DrawString("Hello! 你好!", font, brush, new PointF(150.0F, 150.0F)); //g.DrawEllipse(pen, g.FillEllipse(brush, 30, 30, 200, 200); g.FillEllipse(brush, 130, 130, 200, 200); g.FillEllipse(new SolidBrush(Color.FromArgb(153, 23, 153, 155)), 220, 230, 150, 150); g.FillEllipse(new SolidBrush(Color.FromArgb(153, 23, 153, 55)), 200, 30, 150, 150); g.FillEllipse(new SolidBrush(Color.FromArgb(153, 93, 53, 55)), 40, 230, 250, 250); //Image image = Image.FromFile("../../MonaLisa.jpg"); //g.DrawImage(image, new Point(200, 200)); // Create a Bitmap object from an image file. Bitmap bitmap = new Bitmap("../../MonaLisa.jpg"); // Get the color of a pixel within myBitmap. Color pixelColor = bitmap.GetPixel(50, 50); // RGB value : pixelColor.R, pixelColor.G, pixelColor.B g.DrawImage(bitmap, new Point(200, 200)); }
public void Setup() { Bitmap bmp = new Bitmap(200, 100); m_graphics = Graphics.FromImage(bmp); m_gm = new GraphicsManager(null, m_graphics); }
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))); } } }
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; }
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); } }
public static Image CopyTextureToBitmap(D3D.Texture2D texture) { int width = texture.Description.Width; if (width % 16 != 0) width = MathExtensions.Round(width, 16) + 16; Bitmap bmp = new Bitmap(texture.Description.Width, texture.Description.Height, PixelFormat.Format32bppArgb); BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat); using (DataStream stream = new DataStream(bData.Scan0, bData.Stride * bData.Height, false, true)) { DataRectangle rect = texture.Map(0, D3D.MapMode.Read, D3D.MapFlags.None); using (DataStream texStream = rect.Data) { for (int y = 0; y < texture.Description.Height; y++) for (int x = 0; x < rect.Pitch; x+=4) { byte[] bytes = texStream.ReadRange<byte>(4); if (x < bmp.Width*4) { stream.Write<byte>(bytes[2]); // DXGI format is BGRA, GDI format is RGBA. stream.Write<byte>(bytes[1]); stream.Write<byte>(bytes[0]); stream.Write<byte>(255); } } } } bmp.UnlockBits(bData); return bmp; }
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; }
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; }
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; }
public void LoadContent() { tiles = new Bitmap[2]; tiles[0] = new Bitmap(@"Assets/Tiles/unpassable.png"); tiles[1] = new Bitmap(@"Assets/Tiles/dirt.png"); player = new Bitmap(@"Assets/avatar.png"); }
// From http://edu.cnzz.cn/show_3281.html public static GraphicsPath CalculateGraphicsPathFromBitmap(Bitmap bitmap, Color colorTransparent) { GraphicsPath graphicsPath = new GraphicsPath(); if (colorTransparent == Color.Empty) colorTransparent = bitmap.GetPixel(0, 0); for(int row = 0; row < bitmap.Height; row ++) { int colOpaquePixel = 0; for(int col = 0; col < bitmap.Width; col ++) { if(bitmap.GetPixel(col, row) != colorTransparent) { colOpaquePixel = col; int colNext = col; for(colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++) if(bitmap.GetPixel(colNext, row) == colorTransparent) break; graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1)); col = colNext; } } } return graphicsPath; }
public Preferences() : base() { InitializeComponent(); Text = String.Concat(Locale.Current.Preferences.WindowTitle, " - ", Program.MainForm.Text); Icon = Program.MainForm.Icon; TopMost = true; _iconApps = Utilities.ResourceHelper.GetImage("gmail-limon.png"); _iconStandard = Utilities.ResourceHelper.GetImage("gmail-bleu.png"); _rendererListLarge = Shellscape.UI.VisualStyles.ControlPanel.GetRenderer(Shellscape.UI.VisualStyles.ControlPanel.ControlPanelPart.MessageText, 0, true); _rendererListSmall = Shellscape.UI.VisualStyles.ControlPanel.GetRenderer(Shellscape.UI.VisualStyles.ControlPanel.ControlPanelPart.BodyText, 0, true); _titleElement = Shellscape.UI.VisualStyles.ControlPanel.GetElement( Shellscape.UI.VisualStyles.ControlPanel.ControlPanelPart.Title, 0, true ); InitNavigation(); InitGeneralPanel(); InitAccountsPanel(); InitAccountPanel(); if (Config.Current.FirstRun) { InitFirstRun(); } HidePanels(); _PanelGeneral.Visible = true; }
public ContextMenuModel(IScreen owner, string name, string displayName, Bitmap image = null) { Owner = owner; Name = name; DisplayName = displayName; Image = image; }
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); }
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; }
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; }
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); } } }
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; }
/// <summary> /// Combine image of WallpaperConfiguration into one big image. /// /// </summary> /// <returns></returns> protected string GenerateWallpaper() { string path = Path.GetTempFileName(); // create an image for virtual screen Image image = new Bitmap(Configuration.VirtualScreenBounds.Width, Configuration.VirtualScreenBounds.Height); Graphics gs = Graphics.FromImage(image); // generate an image based on the described configuration foreach (ScreenConfiguration wallConf in Configuration.Screens) { // draw image IDrawer drawer = Drawers[wallConf.Style]; drawer.Draw(gs, wallConf); gs.Flush(); } image.Save(path, ImageFormat.Jpeg); // clean up image.Dispose(); gs.Dispose(); return path; }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); var myImg = new Bitmap("C:\\Users\\phil.SONOCINE\\Pictures\\MyTest.jpg"); //byte[] bytes = ImageReading.pixels(myImg); this.pictureBox1.Image = ImageReading.pixels(myImg); ; //grayscale //var gsBytes = new List<byte>(); //for (int i = 0; i < bytes.Length; i+=3) //{ // var R = bytes[i]; // var G = bytes[i+1]; // var B = bytes[i+2]; // byte gs = (byte)(0.2989 * R + 0.5870 * G + 0.1140 * B); // gsBytes.Add(gs); //} //using (var ms = new MemoryStream(bytes)) //{ // try // { // ms.Seek(0, SeekOrigin.Begin); // var bmp = Image.FromStream(ms); // e.Graphics.DrawImage(bmp, 0, 0); // } // catch(Exception ex) // { // Console.WriteLine(ex.Message); // } //} }
/// <summary> /// Returns Exif rotation in degrees. Returns 0 if the metadata /// does not exist or could not be read. A negative value means /// the image needs to be mirrored about the vertical axis. /// </summary> /// <param name="img">Image.</param> public static int GetRotation(Bitmap img) { try { foreach (PropertyItem prop in img.PropertyItems) { if (prop.Id == TAG_ORIENTATION) { ushort orientationFlag = BitConverter.ToUInt16(prop.Value, 0); if (orientationFlag == 1) return 0; else if (orientationFlag == 2) return -360; else if (orientationFlag == 3) return 180; else if (orientationFlag == 4) return -180; else if (orientationFlag == 5) return -90; else if (orientationFlag == 6) return 90; else if (orientationFlag == 7) return -270; else if (orientationFlag == 8) return 270; } } } catch { ; } return 0; }
public CusCtlTellPanelChar(Liplis.MainSystem.Liplis lips, ObjSetting os, string url, string title, string discription, int newsEmotion, int newsPoint, Bitmap charBody, EventHandler enter, IContainer components) { this.lips = lips; this.os = os; initCms(components); initDataPanelNonThum(url, title, discription, newsEmotion, newsPoint, charBody, enter); }
public void PasteFromBinaryScaledImageToTile(int zoom, double Lon, double Lat, int xTile, int yTile, double scale, byte[] bytes) { using (Bitmap iconImage = new Bitmap(new MemoryStream(bytes), false)) { PasteScaledBitmapImageToTileByLatLon(zoom, Lon, Lat, xTile, yTile, scale, iconImage); } }
/// <summary>The quantize.</summary> /// <param name="image">The image.</param> /// <param name="pixelFormat">The pixel format.</param> /// <param name="useDither">The use dither.</param> /// <returns>The quantized image with the recalculated color palette.</returns> public static Bitmap Quantize(Image image, PixelFormat pixelFormat, bool useDither) { Bitmap tryBitmap = image as Bitmap; if (tryBitmap != null && tryBitmap.PixelFormat == PixelFormat.Format32bppArgb) { // The image passed to us is ALREADY a bitmap in the right format. No need to create // a copy and work from there. return DoQuantize(tryBitmap, pixelFormat, useDither); } // We use these values a lot int width = image.Width; int height = image.Height; Rectangle sourceRect = Rectangle.FromLTRB(0, 0, width, height); // Create a 24-bit rgb version of the source image using (Bitmap bitmapSource = new Bitmap(width, height, PixelFormat.Format32bppArgb)) { using (Graphics grfx = Graphics.FromImage(bitmapSource)) { grfx.DrawImage(image, sourceRect, 0, 0, width, height, GraphicsUnit.Pixel); } return DoQuantize(bitmapSource, pixelFormat, useDither); } }
/// <summary> /// Размещает иконку на тайле /// </summary> /// <param name="zoom"></param> /// <param name="Lon"></param> /// <param name="Lat"></param> /// <param name="xTile"></param> /// <param name="yTile"></param> /// <param name="iconImage"></param> public void PasteImageToTileByLatLon(int zoom, double Lon, double Lat, int xTile, int yTile, Bitmap iconImage) { int width = iconImage.Width; int height = iconImage.Height; CopyRegionIntoImage(iconImage, new Rectangle(0, 0, width, height), GetTargetBound(zoom, Lon, Lat, xTile, yTile, width, height)); }
public Image<Gray, byte> byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image i = Image.FromStream(ms); Bitmap b = new Bitmap(i); return new Image<Gray, byte>(b); }
public static Bitmap LoadPicture(string url) { System.Net.HttpWebRequest wreq; System.Net.HttpWebResponse wresp; Stream mystream; Bitmap bmp; bmp = null; mystream = null; wresp = null; try { wreq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url); wreq.AllowWriteStreamBuffering = true; wresp = (System.Net.HttpWebResponse)wreq.GetResponse(); if ((mystream = wresp.GetResponseStream()) != null) bmp = new Bitmap(mystream); } catch { // Do nothing... } finally { if (mystream != null) mystream.Close(); if (wresp != null) wresp.Close(); } return (bmp); }
public static string Create(string src, int? width, int? height) { var sourcePath = HttpContext.Current.Server.MapPath(src); if (string.IsNullOrEmpty(sourcePath) || !File.Exists(sourcePath)) { return string.Empty; } using (var srcBitmap = new Bitmap(sourcePath)) { var w = width.HasValue ? width.Value : srcBitmap.Width; var h = height.HasValue ? height.Value : srcBitmap.Height; var imagePath = generatePath(sourcePath, w, h); var mappedImagePath = HttpContext.Current.Server.MapPath(imagePath); if (File.Exists(mappedImagePath)) { return imagePath; } using (var destBitmap = new Bitmap(srcBitmap, new Size(w, h))) { destBitmap.Save(mappedImagePath); return imagePath; } } }