We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Graphics.FillRectangle and Graphics.DrawLine producing incorrect output

    Bitmap bitmap = new Bitmap(250, 110);
    Graphics graphics = Graphics.FromImage(bitmap);

    SolidBrush b = new SolidBrush(System.Drawing.Color.Red);

    graphics.FillRectangle(b, 0f, 0f, 100, 100);
    graphics.DrawLine(new Pen(new SolidBrush(System.Drawing.Color.Blue)), 0,0,160,80);
    bitmap.Save("demo.png");

The above snippet produces the following output on a Windows machine in a WinForms application, not using Aspose.Drawing but using the native Windows libraries:
image.png (342 Bytes)

Actual output on MacOS using Aspose.Drawing:
actual.png (265 Bytes)

Environment:
macOS Monterey, m1 chipset.

Library version:
Aspose.Drawing.22.11.0\lib\net20\Aspose.Drawing.dll

@andy2,

Thanks for the screenshots and details.

I tested your exact code using latest version of Aspose.Drawing for .NET APIs and it works fine. Please find attached the output image which is ok. I tested in a project with .NET Framework 4.0 on Windows8.
e.g.
Sample code:

var drawingLicense = new Aspose.Drawing.License();
drawingLicense.SetLicense("Aspose.Drawing.NET.lic");
Bitmap bitmap = new Bitmap(250, 110);
Graphics graphics = Graphics.FromImage(bitmap);

SolidBrush b = new SolidBrush(System.Drawing.Color.Red);

graphics.FillRectangle(b, 0f, 0f, 100, 100);
graphics.DrawLine(new Pen(new SolidBrush(System.Drawing.Color.Blue)), 0, 0, 160, 80);
bitmap.Save("e:\\test2\\demo1.png"); 

Please find attached the output image for your reference.
demo1.png (337 Bytes)

Do you see any issue with the output image? Did you try it on Windows machine? Also, did you use license with the APIs? If not, you may apply for a temporary license and get it (to be set in code at the start of your application) which is valid for 30 days, see the page for your reference.

Hi Amjad,

I did wonder if the output was wrong because the library wasn’t licensed, but didn’t see mention of that anywhere - I just read that there might be a watermark.

After applying the temporary license, the output is correct.

Thanks

@andy2,

Yes, in evaluation mode (without a valid license to be set in code), an evaluation watermark would be always there in the output image(s). Anyways, good to know that your issue is sorted out in licensing mode. Feel free to write us back if you have further queries or issue.