Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TImage.LoadFromFile is not working


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Oct 22, 2015 12:47 PM Last Post By: Remy Lebeau (Te...
Adriano Macome

Posts: 56
Registered: 9/26/11
TImage.LoadFromFile is not working  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2015 1:01 PM
Hi;

Under XE5 I developed a form with lots of graphics; before opening the form, I load each graphic from a file, then I show the form for editing. Now I see the same form is not working under XE7; it seems the problem is when loading from file.

Img.Picture.LoadFromFile('source1.jpg');

If after that command, I do:

Img.Picture.SaveToFile('target1.jpg');

An exception error happen. By debugging VCL code, I see it fails under TGraphic.SaveToStream method, in where I can see that the value of FPicture is nil.

What is missed?

Best regards,

Adriano.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TImage.LoadFromFile is not working  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2015 5:19 PM   in response to: Adriano Macome in response to: Adriano Macome
Adriano wrote:

it seems the problem is when loading from file.

Do you have the Vcl.Imaging.Jpeg unit in your uses clause?

By debugging VCL code, I see it fails under TGraphic.SaveToStream
method, in where I can see that the value of FPicture is nil.

The only way that can happen is if you are accessing the Picture property
from an invalid Img object pointer. TImage creates its FPicture object in
its constructor, and it stays alive in memory until the TImage object is
destroyed. FPicture should never be nil if your Img variable is pointing
at a valid TImage object.

--
Remy Lebeau (TeamB)
Adriano Macome

Posts: 56
Registered: 9/26/11
Re: TImage.LoadFromFile is not working  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 8:34 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Sorry, I did´t see the second part of your answer. So now I will edit my last answer:

To your first question: Yes, I have JPEG unit exactly as you say.

To the second part: The TImages components are all set on the form at design time, so I think that each of them may have the FPicture created when I try to do LoadFromFile; take in mind that the TImage component is not nil when I do LoadFromFile.

And as I said, exactly the same unit works very well under XE5.

Thank you for your help!

Edited by: Adriano Macome on Oct 22, 2015 10:15 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TImage.LoadFromFile is not working [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 10:57 AM   in response to: Adriano Macome in response to: Adriano Macome
Adriano wrote:

To the second part: The TImages components are all set on the form
at design time, so I think that each of them may have the FPicture
created when I try to do LoadFromFile; take in mind that the TImage
component is not nil when I do LoadFromFile.

Then what you describe is not possible, unless you are doing something to
corrupt memory. Please provide a complete compilable example that demonstrates
the prolem.

--
Remy Lebeau (TeamB)
Adriano Macome

Posts: 56
Registered: 9/26/11
Re: TImage.LoadFromFile is not working [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 11:58 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I found out the problem!, there was an error in how I built the file name, adding a wrong file extension!
Thank you and sorry.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TImage.LoadFromFile is not working [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2015 12:47 PM   in response to: Adriano Macome in response to: Adriano Macome
Adriano wrote:

I found out the problem!, there was an error in how I built
the file name, adding a wrong file extension!

That should have caused LoadFromFile() to raise an exception when it cold
not open the file.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02