Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Responding to the C# code ... Overall, good job on getting the imaging going. I've had to do similar things with some of my apps in the past.</p> <p>One piece of advice, however: All graphics objects in .NET are based on Windows GDI+ primitives. This means these objects require correct disposal to clean up their non-memory resources, much like file handles or database connections. You'll want to tweak the code a bit to support that correctly.</p> <p>All of the GDI+ objects implement the IDisposable interface, making them functional with the using statement. Consider rewriting your code similarly to the following:</p> <pre><code>// Experiment with this value int exposurePercentage = 40; using (Image img = Image.FromFile("rss-icon.jpg")) { using (Graphics g = Graphics.FromImage(img)) { // First Number = Alpha, Experiment with this value. using (Pen p = new Pen(Color.FromArgb(75, 255, 255, 255))) { // Looks jaggy otherwise g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int x, y; // 3 * Height looks best int diameter = img.Height * 3; double imgPercent = (double)img.Height / 100; x = 0 - img.Width; // How many percent of the image to expose y = (0 - diameter) + (int)(imgPercent * exposurePercentage); g.FillEllipse(p.Brush, x, y, diameter, diameter); pictureBox1.Image = img; } } } </code></pre> <p>(Bear in mind, unlike most of my samples, I haven't had a chance to compile and test this ... It's meant more as a sample of structuring the code for ensuring that there are no resource leaks, not as a finished product. There are probably better ways to abstract/structure that anyway. And strongly consider doing so -- toss this in a graphics library DLL that you can just reference in any project which needs these capabilities in the future!)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload