2

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...

raoul
  • 197
  • 3
  • 14

1 Answers1

0

Visual Studio 2017 for Mac Support for macOS/OS X Development

Visual Studio 2017 for Mac enables you to build console applications and Cocoa (desktop) applications for macOS. visualstudio.com

That is, NO .NET Winforms and WPF.

You could start here: macOS development with Visual Studio for Mac.

(Hint: It's Xamarin.Mac guides)

9dan
  • 4,222
  • 2
  • 29
  • 44
  • thanks for the reaction. Do I understand you correctly that it is impossible to create a console application that will render properly for a retinascreen? And, the application aside, wouldn't it be possible to create a bitmap with a higher resolution? When I use `SetResolution(144.0F, 144.0F)` it doesnt seem to have any impact on size, but I think I'm missing something... – raoul Dec 01 '17 at 17:44