Change Image Resolution

mcoscasmcoscas Member Posts: 34
edited 2021-03-09 in NAV Three Tier
Hi everybody,
I try to change the resolution of the images imported in the field Picture of the table Item.(NAV 2017 CU 30)
The different steps are:
1. Import the file into a folder located in a server (I know that the standard NAV already do this my problem is not here but in the next point)
2. Change the resolution of the image (1280*720)
3. Upload the new image to a FTP server

I wrote this code:

Path := 'C:\\draw\Tchoupi_2.gif';
DrawBitmap := DrawBitmap.Bitmap(Path);
DrawBitmap.SetResolution(1280,720);


It compiles without error but when I run it I get the following error:
A call to System.Drawing.Bitmap failed with this message: Parameter is not valid.

I try differents syntaxes for the path with \ and / but it did not help.

Is someone has an idea ?

Thanks in advance.
Michael

Best Answer

  • mcoscasmcoscas Member Posts: 34
    Answer ✓
    Hi Alexey,
    Thanks for your help but it did not help, I tried both RunOnClient = Yes and No, no difference.
    But fortunately I found the solution of my problem this morning at this link:
    https://www.delftstack.com/howto/csharp/resize-an-image-in-csharp/
    It seems to be that a Microsoft issue exists when you tried to save a file after changed the resolution with the function SetResolution like this:
    DrawBitmap := DrawBitmap.Bitmap(Path);
    DrawBitmap.SetResolution(1280,720);
    DrawNewBitmap.Save(NewPath);

    So I changed my code like this:

    DrawImage := DrawImage.FromFile(Path);
    DrawBitmap := DrawBitmap.Bitmap(DrawImage);
    DrawSize := DrawSize.Size(1280,720);
    DrawNewBitmap := DrawNewBitmap.Bitmap(DrawImage, DrawSize);
    DrawNewBitmap.Save(NewPath);

    And it works fine ! :smile:

Answers

  • AlexeyShaminAlexeyShamin Member Posts: 80
    Hello!
    Your problem in line DrawBitmap := DrawBitmap.Bitmap(Path);
    system cannot find file.

    Can you check property RunOnClient in DrawBitmap variablre? is it set to "No"?
  • mcoscasmcoscas Member Posts: 34
    Answer ✓
    Hi Alexey,
    Thanks for your help but it did not help, I tried both RunOnClient = Yes and No, no difference.
    But fortunately I found the solution of my problem this morning at this link:
    https://www.delftstack.com/howto/csharp/resize-an-image-in-csharp/
    It seems to be that a Microsoft issue exists when you tried to save a file after changed the resolution with the function SetResolution like this:
    DrawBitmap := DrawBitmap.Bitmap(Path);
    DrawBitmap.SetResolution(1280,720);
    DrawNewBitmap.Save(NewPath);

    So I changed my code like this:

    DrawImage := DrawImage.FromFile(Path);
    DrawBitmap := DrawBitmap.Bitmap(DrawImage);
    DrawSize := DrawSize.Size(1280,720);
    DrawNewBitmap := DrawNewBitmap.Bitmap(DrawImage, DrawSize);
    DrawNewBitmap.Save(NewPath);

    And it works fine ! :smile:
  • JJMcJJMc Member Posts: 60
    What variable did you create to use DrawImage?
  • mcoscasmcoscas Member Posts: 34
    Hi,
    Here the variables:
    DrawBitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawNewBitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawImage DotNet System.Drawing.Image.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawSize DotNet System.Drawing.Size.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Regards,
    Michael
  • JJMcJJMc Member Posts: 60
    edited 2021-03-20
    mcoscas wrote: »
    Hi,
    Here the variables:
    DrawBitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawNewBitmap DotNet System.Drawing.Bitmap.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawImage DotNet System.Drawing.Image.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    DrawSize DotNet System.Drawing.Size.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Regards,
    Michael

    Thank you ever so much.
    And do you know if there is a way to convert from jpg to bmp?
Sign In or Register to comment.