Jump to content
neumimnemecky

Why jpg image is not created?

Recommended Posts

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
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?

  • Like 1

Share this post


Link to post
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 by neumimnemecky

Share this post


Link to post
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.

  • Like 2

Share this post


Link to post
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×