I have a simple c# console application that builds a fractal. I use Visual Studio Community on macOS. I create a bitmap of a certain size (wxh). For every pixel a color is assigned with .SetPixel
, based on the calculated mandelbrotnumber.
class Form1 : Form
{
//..
public Form1()
{
//..
AutoScaleMode = AutoScaleMode.Dpi;
}
//..
private void DrawMandelbrot(object o, PaintEventArgs ea)
{
Bitmap bm = new Bitmap(w, h);
mandelb = CreateMandelbrot(bm);
ea.Graphics.DrawImage(mandelb, xMandelb, yMandelb, w, h);
}
}
This works fine, except I have a high dpi retina screen and the bitmaps look very pixelated.
I tried things like:
Graphics graphics = this.CreateGraphics();
dpiX = graphics.DpiX;
to get a dpi, but this just gives me 96, which is the resolution of the Form
, not of the screen.
I tried bm.SetResolution(144.0F, 144.0F);
directly after creating the bitmap, with no succes.
I tried more complex approaches like found here but that just crashes the program. Probably (?) because I'm on macos, all solutions that are promoted that suggest loading .dll's like [DllImport("user32.dll")]
dont work : System.DllNotFoundException: user32.dll
.
I tried adding this.AutoScaleDimensions = new System.Drawing.SizeF(200F, 200F);
to the method that initializes the Form
.
Even switching to WPF seems to be problematic, if it's even possible at all on macOS. Wondering if it is even possible at all using C#?
I don't need the whole program to render for the retina dpi, but creating a bitmap pixel by pixel probably needs another approach to get high resolution images? It would be acceptable to simply make the bitmap smaller, but at a higher resolution. Of course the nicest solution would be to create the complete Form
application with a few line of code on a high dpi-resolution, based on the available dpi of the screen, without rewriting the whole application as
The .NET documentation is really useless, so I hope someone here has a solution.
PS: instead of just downvoting my post, i'd rather hear what the critique on my post is. Is it a duplicate? I'm glad to hear where I can find the answer, have been searching for hours. You need more code? Happy to provide...