Change Image Resolution

mcoscas
Member Posts: 34
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
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
0
Best 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 !0
Answers
-
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"?0 -
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 !0 -
What variable did you create to use DrawImage?0
-
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,
Michael0 -
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?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions