Load image from resources

You can always use System.Resources.ResourceManager which returns the cached ResourceManager used by this class. Since chan1 and chan2 represent two different images, you may use System.Resources.ResourceManager.GetObject(string name) which returns an object matching your input with the project resources Example object O = Resources.ResourceManager.GetObject(“chan1”); //Return an object from the image chan1.png in the project channelPic.Image = … Read more

Translate Rectangle Position in Zoom Mode Picturebox

You can translate selected rectangle on the picture box to the rectangle on image this way: public RectangleF GetRectangeOnImage(PictureBox p, Rectangle selectionRect) { var method = typeof(PictureBox).GetMethod(“ImageRectangleFromSizeMode”, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var imageRect = (Rectangle)method.Invoke(p, new object[] { p.SizeMode }); if (p.Image == null) return selectionRect; var cx = (float)p.Image.Width / (float)imageRect.Width; var cy = (float)p.Image.Height … Read more

Transparent images with C# WinForms

I was in a similar situation a couple of days ago. You can create a transparent control to host your image. using System; using System.Windows.Forms; using System.Drawing; public class TransparentControl : Control { private readonly Timer refresher; private Image _image; public TransparentControl() { SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; refresher = new Timer(); refresher.Tick += TimerOnTick; … Read more

Free file locked by new Bitmap(filePath)

Here is my approach to opening an image without locking the file… public static Image FromFile(string path) { var bytes = File.ReadAllBytes(path); var ms = new MemoryStream(bytes); var img = Image.FromStream(ms); return img; } UPDATE: I did some perf tests to see which method was the fastest. I compared it to @net_progs “copy from bitmap” … Read more

PictureBox PaintEvent with other method

You need to decide what you want to do: Draw into the Image or draw onto the Control? Your code is a mix of both, which is why it doesn’t work. Here is how to draw onto the Control: private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44)); .. } Here … Read more