Shinobu [Kitchen burner]
Shinobu [Kitchen burner]
CC#
Created by Shinobu [Kitchen burner] on 5/8/2025 in #help
Is there an issue with C# Winforms image resizing function?
I was using this snippet of code to resize the image and display to a picture box: Bitmap resizedImage = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(resizedImage)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawImage(currentImageOriginalSize, 0, 0, newWidth, newHeight); } currentImage = resizedImage; and the image I got was more blurry than the one displayed online using HTML (we pulled from the same image source and the web doesn't use an external library. The picture box and the picture element has the same size). Is this a known issue or did I do something wrong?
5 replies
CC#
Created by Shinobu [Kitchen burner] on 12/19/2024 in #help
✅ Help to display a label on top of a picture box
I have been struggling to make a label show up on top of the corresponding picture box with the setup below: private FlowLayoutPanel CreateImagePanel() { //setup panel inside flow layout panel ... PictureBox pictureBox = new PictureBox { SizeMode = PictureBoxSizeMode.StretchImage, Size = new Size(maxImageWidth, maxImageHeight), Cursor = Cursors.Hand, Dock = DockStyle.Fill }; //the label that should appear on the top left of the picture Label selectionIndicator = new Label { Size = new Size(16, 16), TextAlign = ContentAlignment.MiddleCenter, Font = new Font("Arial", 6, FontStyle.Bold), ForeColor = Color.White, BackColor = Color.Blue, Visible = false, AutoSize = false }; //make the label a circle instead of a square selectionIndicator.Paint += (s, e) => { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; using (var path = new System.Drawing.Drawing2D.GraphicsPath()) { path.AddEllipse(0, 0, selectionIndicator.Width - 1, selectionIndicator.Height - 1); selectionIndicator.Region = new Region(path); e.Graphics.DrawEllipse(new Pen(Color.White, 2), 0, 0, selectionIndicator.Width - 1, selectionIndicator.Height - 1); } }; // Position the selection indicator in the top-right corner selectionIndicator.Location = new Point(containerPanel.Width - 16, 0); selectionIndicator.BringToFront(); containerPanel.Controls.Clear(); containerPanel.Controls.Add(pictureBox); containerPanel.Controls.Add(selectionIndicator); imagePanel.Controls.Add(containerPanel); imagePanel.Tag = "empty"; imagePanel.Visible = false; return imagePanel; } and to display it, I just use: selectionIndicator.Visible = false; I used a panel inside flow panel to bypass it's no collision rule, but the label doesn't appear Thanks for reading
12 replies