ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Unable to load PNG
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

GregoryW

8 Posts

Posted - Dec 03 2012 :  04:24:57  Show Profile  Reply
Hi,
when i try to compile the code below [i am using Delphi XE, ImageEn 4.1.4]:
try
procedure TForm11.Button4Click(Sender: TObject);
var
  PNG: TIEPNGImage;
  ms: TMemoryStream;
begin
  PNG := TIEPNGImage.Create;
  ms := TMemoryStream.Create;
  try
    ms.LoadFromFile('111.png');
    PNG.LoadFromStream(ms);        <<< 1st error
    PNG.SaveToFile('222.png');     <<< 2nd error
  finally
    PNG.Free;
    ms.Free;
  end;
end;

I get errors like this:





PNG:


I need to load the images (*.png) from a stream. Am I doing something wrong? Please help!

No error messages when using old ImageEn (v3.1.2, for example), the code worked perfectly.

Greg

w2m

USA
1990 Posts

Posted - Dec 03 2012 :  07:22:58  Show Profile  Reply
Your code does not even use ImageEn at all. Why don't you use ImageEn?

Anyway... you need to set the position of the stream to 0 after LoadFromFile.

procedure TForm1.Button1Click(Sender: TObject);
// Load a png file into TMemoryStream and save the png file with a new name
var
  iPNG: TIEPNGImage;
  ims: TMemoryStream;
begin
  iPNG := TIEPNGImage.Create;
  try
    ims := TMemoryStream.Create;
    try
      ims.LoadFromFile('111.png');
      ims.Position := 0; // Add this
      iPNG.LoadFromStream(ms);
      iPNG.SaveToFile('222.png');
    finally
      ims.Free;
    end;
  finally
   iPNG.Free;
  end;
end;

You do not need to use PNGImage.
procedure TForm1.Button2Click(Sender: TObject);
// Load a png file into a TMemoryStream then save the png to a file with a new filename
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    ms.LoadFromFile('111.png');
    ms.Position := 0;
    ms.SaveToFile('222.png');
  finally
    ms.Free;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
// Load a png file into a TMemory stream, then use imageenio to load the stream and save the png file
var
  iImageEnIO: TImageENIO;
  ims: TMemoryStream;
begin
  iImageEnIO := TImageENIO.Create(nil);
  try
    ims := TMemoryStream.Create;
    try
      ims.LoadFromFile('111.png');
      ims.Position := 0;
      iImageEnIO.LoadFromStreamPNG(ims);
      iImageEnIO.SaveToFilePNG('222.png');
    finally
      ims.Free;
    end;
  finally
   iImageEnIO.Free;
  end;
end;

procedure TForm1.Button4Click(Sender: TObject);
// Load a png file into a TMemory stream, then load the stream into ImageEnView, and use ImageEnView.IO to save the png file with a new name
var
  ims: TMemoryStream;
begin
  ims := TMemoryStream.Create;
  try
    ims.LoadFromFile('111.png');
    ims.Position := 0;
    ImageEnView1.IO.LoadFromStreamPNG(ims);
    ImageEnView1.Update;
    ImageEnView1.IO.SaveToFilePNG('222.png');
  finally
     ims.Free;
  end;
end;

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

GregoryW

8 Posts

Posted - Dec 03 2012 :  22:02:31  Show Profile  Reply
Hi w2m,

please try to run your code:
procedure TForm1.Button1Click(Sender: TObject);
// Load a png file into TMemoryStream and save the png file with a new name
var
  iPNG: TIEPNGImage;
  ims: TMemoryStream;
begin
  iPNG := TIEPNGImage.Create;
  try
    ims := TMemoryStream.Create;
    try
      ims.LoadFromFile('111.png');
      ims.Position := 0; // Add this
      iPNG.LoadFromStream(ims);
      iPNG.SaveToFile('222.png');
    finally
      ims.Free;
    end;
  finally
   iPNG.Free;
  end;
end;

you get error message:
---------------------------
Error on creating PNG.
---------------------------

P.S. iPNG.SaveToFile('222.png') - this is just an example of a bug. In fact, I need a PNG (in TIEPNGImage) for further image manipulation.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Dec 04 2012 :  07:08:09  Show Profile  Reply
I did test my code... everything works as expected here.
1. What version of Delphi are you using?
2 What version of ImageEn are you using?
3. What components are in the project?
4. Perhaps you have more than one version of ImageEn installed.
5. Do you get an exception by running the exe outside of Delphi?

Send me your email address and I will send you a demo that we can test.

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

GregoryW

8 Posts

Posted - Dec 04 2012 :  22:41:46  Show Profile  Reply
1) Delphi XE
2) ImageEn 4.1.4
3) only standard delphi units
4) nope
5) yes,
---------------------------
Error on creating PNG.
---------------------------
Go to Top of Page

w2m

USA
1990 Posts

Posted - Dec 05 2012 :  09:56:42  Show Profile  Reply
Discussing via email

William Miller
Go to Top of Page

GregoryW

8 Posts

Posted - Dec 11 2012 :  00:05:29  Show Profile  Reply
Dear xequte,

I sent an e-mail to support a few days ago titled "Unable to load PNG". Did you read it?

Greg
Go to Top of Page

xequte

38615 Posts

Posted - Dec 11 2012 :  01:07:54  Show Profile  Reply
Hi Greg

We cannot reproduce this issue on our machines.

From the video it appears that Delphi's PNG library is being used instead of ImageEn's own one, so it is likely to be a path problem.

Please take a look at:

http://www.imageen.com/ieforum/topic.asp?TOPIC_ID=357


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

GregoryW

8 Posts

Posted - Dec 11 2012 :  02:43:31  Show Profile  Reply
Thank you! Problem solved thanks to post made by 'fabrizio':

"This is my opinion about this problem: because both ImageEn and VCL uses zlib, but in different versions, maybe ImageEn links the VCL-zlib version. Structures of different zlib versions are also different, so they cannot work.
zlib is necessary to load/save PNG.
Putting zlib (and others like png, jpeg, etc..) object files in the same directory of ImageEn source code should fix the problen. Another way could be to put these object files (the libs content) in the first position of Delphi Library Path.

Fortunately this problem is fixed in XE2, because ImageEn can use the VCL-zlib library."
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: