I need to draw multiline text on the bitmap.
if graphics has Pixel unit it works fine.
but i need to prepare bitmap for the exporting/printing, so i need to use the "Document" units.
unfortunately the text is cropped.
```C#
static void Main() {
const string outputFile = "output.png";
const float PxDpi = 96f;
const float DocumentDpi = 300f;
using(var bitmap = new Bitmap(300, 300))
using(var graphics = Graphics.FromImage(bitmap))
using(var font = new Font("DejaVu Sans", 18f))
using(var stringFormat = new StringFormat()) {
bitmap.SetResolution(PxDpi, PxDpi);
graphics.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
graphics.PageUnit = GraphicsUnit.Document;
var pixelBounds = new RectangleF(50, 50, 150, 250);
var bounds = new RectangleF(
Convert(pixelBounds.X, PxDpi, DocumentDpi),
Convert(pixelBounds.Y, PxDpi, DocumentDpi),
Convert(pixelBounds.Width, PxDpi, DocumentDpi),
Convert(pixelBounds.Height, PxDpi, DocumentDpi));
graphics.DrawString("HELLO WORLD", font, Brushes.Black, bounds, stringFormat);
bitmap.Save(outputFile, ImageFormat.Png);
}
}
static float Convert(float value, float fromDpi, float toDpi) {
double scale = (double)toDpi / fromDpi;
double result = value * scale;
return (float)result;
}
on the windows platform I see the
Hello
World
on the png.
But on the linux I see the cropped text
H
W
```
on the output png.
The good side is a location of text start is right.
but the bound's size is too small.
@safern, @maryamariyan as this seems to be a bug I'll mark it as 3.0.
@safern my suggestion here is move to Future as there's only one report. Also it is likely in libgdiplus not us?
Yes this is likely libgdiplus and not us. I'll move it over to libgdiplus and close this one to be investigated on their side. We just call GdipDrawString which is native code in order to produce the bitmap.
Most helpful comment
@safern, @maryamariyan as this seems to be a bug I'll mark it as 3.0.