neumimnemecky 0 Posted July 15, 2022 This is my new project, where I try to open bmp file and save it as jpg with NativeJPG by Simdesign. https://sourceforge.net/projects/ahk...t.zip/download I did not uploaded images. Folder img should be created and in it bmp.jpg . Why nothing is created? procedure TForm1.LoadJpegFile(const AFileName: string); var bmp_filename, JpgFileName, dest_path: String; begin BMP_filename := 'F:\bmp.bmp'; JpgFileName := '.\img\bmp.jpg'; dest_path := ExtractFilePath(JpgFileName); if not DirectoryExists(dest_path) then CreateDir(dest_path); if not fileexists(bmp_filename) then begin showmessage('File not found: '+bmp_filename); exit; end; try Bmp.LoadFromFile(bmp_filename); Jpg.CompressionQuality := 100; Jpg.Assign(Bmp); Jpg.SaveToFile(JpgFileName); // nothing happens? finally end; end; Share this post Link to post
PeterBelow 238 Posted July 15, 2022 48 minutes ago, neumimnemecky said: This is my new project, where I try to open bmp file and save it as jpg with NativeJPG by Simdesign. https://sourceforge.net/projects/ahk...t.zip/download I did not uploaded images. Folder img should be created and in it bmp.jpg . Why nothing is created? procedure TForm1.LoadJpegFile(const AFileName: string); var bmp_filename, JpgFileName, dest_path: String; begin BMP_filename := 'F:\bmp.bmp'; JpgFileName := '.\img\bmp.jpg'; dest_path := ExtractFilePath(JpgFileName); if not DirectoryExists(dest_path) then CreateDir(dest_path); if not fileexists(bmp_filename) then begin showmessage('File not found: '+bmp_filename); exit; end; try Bmp.LoadFromFile(bmp_filename); Jpg.CompressionQuality := 100; Jpg.Assign(Bmp); Jpg.SaveToFile(JpgFileName); // nothing happens? finally end; end; Never rely on relative path names! They depend on whatever the application thinks the "current directory" is, and that is frequently not what you think it should be. Have you checked what destPath contains after your assignment? 1 Share this post Link to post
neumimnemecky 0 Posted July 15, 2022 (edited) 9 minutes ago, PeterBelow said: Never rely on relative path names! They depend on whatever the application thinks the "current directory" is, and that is frequently not what you think it should be. Have you checked what destPath contains after your assignment? dest_path = '.\img\' And jpg is type TsdJpegGraphic So it works fine but the folder is not the folder I expected. Edited July 15, 2022 by neumimnemecky Share this post Link to post
Vandrovnik 214 Posted July 15, 2022 59 minutes ago, neumimnemecky said: dest_path = '.\img\' And jpg is type TsdJpegGraphic So it works fine but the folder is not the folder I expected. Use full (absolute) path for JpgFileName and dest_path, such as F:\img etc. 2 Share this post Link to post
Remy Lebeau 1397 Posted July 16, 2022 7 hours ago, neumimnemecky said: dest_path = '.\img\' Check with TDirectory.GetCurrentDirectory() or equivalent to make sure that '.' refers to the folder you think it does. Share this post Link to post
neumimnemecky 0 Posted July 16, 2022 12 hours ago, Remy Lebeau said: Check with TDirectory.GetCurrentDirectory() or equivalent to make sure that '.' refers to the folder you think it does. Thank you. I think it's better to use SetCurrentDirectory(). Once applied I could use dot. Maybe a question. Does Delphi 7 have an option to set command line parameter? Like myprogram.exe workingpath=F:\images ??? I think I have seen this usefull feature in Visual Studio (C/C++). Share this post Link to post
PeterBelow 238 Posted July 16, 2022 3 hours ago, neumimnemecky said: Thank you. I think it's better to use SetCurrentDirectory(). Once applied I could use dot. Maybe a question. Does Delphi 7 have an option to set command line parameter? Like myprogram.exe workingpath=F:\images ??? I think I have seen this usefull feature in Visual Studio (C/C++). In the IDE: Run -> Parameters Share this post Link to post
Remy Lebeau 1397 Posted July 18, 2022 On 7/16/2022 at 6:18 AM, neumimnemecky said: Thank you. I think it's better to use SetCurrentDirectory(). Once applied I could use dot. That is a bad idea in general. It prevents users from being able to set their own working directory when running your app from a command-line window or a shortcut. Share this post Link to post