I decided to let my bot run on my new home server. So I moved it there via git and the bot does run etc. However, I get the following error when I am using a command where images are being processed with System.Drawing:
System.ArgumentException: Parameter is not valid.
at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
at System.Drawing.Bitmap..ctor(String filename, Boolean useIcm)
at Aurelia.ImageProcessor.ImageBuilder(String filename, String idolname, String group, String rarity, Int32 rar, String id, String pathDefiner) in /home/aurelia/discordBots/Aurelia/AureliaBot/Aurelia/ImageProcessor.cs:line 21
(Aurelia is my bot's name)
If I debug it in VS on my home pc, I don't get this error, and it works fine. The first few times, the bot actually send a picture, but it was a wrong picture. So now, I have no clue what to do. I checked every parameter, every parameter should be fine.
The code for the bitmap:
Bitmap cardTemp = new Bitmap($"assets\\groups\\{group}\\{idolname}\\{filename}");
Bitmap card = new Bitmap(cardTemp, 800, 1200);
Bitmap rareFrameTemp = new Bitmap($"assets\\frames\\{rarity}Frame.png");
Only the first line throws the error, and yes the file exists. Thank you!
CodePudding user response:
The issue is that your paths, while they work for Windows, will not work for Unix based systems as they use forward slashes - /
- not backward slashes \
as a directory separator character.
Use Path.Combine
for a cross-platform solution.
It will use the Path.DirectorySeparatorChar
which will provide a platform-specific character:
var cardTempPath = Path.Combine("assets", "groups", group, idolname, filename);
var rareFrameTemp = Path.Combine("assets", "frames", $"{rarity}Frame.png");
Bitmap cardTemp = new Bitmap(cardTempPath);
Bitmap card = new Bitmap(cardTemp, 800, 1200);
Bitmap rareFrameTemp = new Bitmap(rareFrameTemp);