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
 SetImageFromStream does not get image sometimes
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

864 Posts

Posted - Aug 11 2017 :  11:47:27  Show Profile  Reply
Hi! I have here some cases where SetImageFromStream is missing to automatically detect and get an image from a stream:



idx := mvDocImages.AppendImage;
mvDocImages.SetImageFromStream(idx, MyStream);


How can I debug this to send you a binary copy of the stream content so you could look at the stream content and detect why SetImageFromStream does not recognize the stream content?

xequte

38222 Posts

Posted - Aug 11 2017 :  18:15:40  Show Profile  Reply
Hi Peter

You should be able to save the data to file without an extension, and then use IO.LoadFromFile. Do you get the same result?

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

PeterPanino

864 Posts

Posted - Aug 11 2017 :  20:12:38  Show Profile  Reply
I used this code to dump the content of the TStream to a file:

fs := TFileStream.Create('R:\dump' + IntToStr(i) + '.dat', fmCreate);
try
  MyStream.Position := 0;
  fs.CopyFrom(MyStream, MyStream.Size);
finally
  fs.Free;
end;


The dump file resulted as a vertically flipped BMP image!!!



The ORIGINAL image should be:



So why the automatic format detection algorithm could not detect a simple vertically flipped image?

And how can I make the detection algorithm correctly detect this kind of image?

BTW, here is the dump file:

attach/PeterPanino/201781265235_dump0.zip
13.16 KB

Please fix/update your automatic image format detection algorithm!

BTW, both Irfanview and Microsoft Paint were able to correctly detect the image when opening dump0.dat! Paint.net could not. Also XnView was able to automatically detect and load the dump file. But none of these programs flipped the image back to its correct original vertical position.
Go to Top of Page

PeterPanino

864 Posts

Posted - Aug 12 2017 :  07:31:12  Show Profile  Reply
I have now used your demo ImageEn\Demos\Display\ExternalBitmap to open the dump file dump0.dat: It opens and displays the image without problems!

So why does IO.LoadFromFile correctly detect the image format while SetImageFromStream does not?
Go to Top of Page

PeterPanino

864 Posts

Posted - Aug 12 2017 :  07:54:54  Show Profile  Reply
BTW, the IO.ExecuteOpenDialog preview identifies the dump0.dat file as:

Go to Top of Page

xequte

38222 Posts

Posted - Aug 13 2017 :  20:18:28  Show Profile  Reply
Hi Peter

If the dump is upside-down then either the dump is failing, or there is an issue with the source stream.

Try using:

      fs := TIEWideFileStream.Create(FileName, fmCreate);
      IECopyFrom(fs, MyStream, 0);
      FreeAndNil(fs);


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

PeterPanino

864 Posts

Posted - Aug 14 2017 :  02:52:26  Show Profile  Reply
Hi Nigel,

with TIEWideFileStream I get the same upside-down dump as with TFileStream!

Here are the dumps created with TIEWideFileStream:

attach/PeterPanino/201781423932_dumps.zip
21.73 KB

But as I said, the main failure is that SetImageFromStream does not detect the image at all while IO.LoadFromFile does detect the image.

The image being upside-down is not the main problem (maybe I could live with that). The main problem is that SetImageFromStream does not detect the image at all.

This problem is a showstopper in my current project. I would be very happy if it could be solved ASAP.

Thank you!
Go to Top of Page

PeterPanino

864 Posts

Posted - Aug 14 2017 :  04:40:22  Show Profile  Reply
PROBLEM (ALMOST) SOLVED!!!

Before SetImageFromStream insert this line:

MyStream.Position := 0;

Now SetImageFromStream always detects the image!

But why it was failing only in some RANDOM cases without this line?

And how can I make SetImageFromStream detect whether the image is upside-down? (And maybe then set it automatically back to the correct vertical position). That would be the ultimate success!
Go to Top of Page

xequte

38222 Posts

Posted - Aug 14 2017 :  20:05:02  Show Profile  Reply
Hi Peter

SetImageFromStream will not reset the position of the stream. It reads from the current position (as often you are only reading a portion of the stream). So in your case you should reset the position before calling SetImageFromStream.

It cannot detect whether an image is upside-down because it does not understand the content of the image, unless there is something in the image or meta-data that indicates the correct orientation.



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

PeterPanino

864 Posts

Posted - Aug 16 2017 :  18:09:05  Show Profile  Reply
Hi Nigel,

but then why it worked in many cases without MyStream.Position := 0;? (It failed always with the same specific images).

Of course, it's clear that it cannot detect the content of the image.
Go to Top of Page

xequte

38222 Posts

Posted - Aug 17 2017 :  04:12:33  Show Profile  Reply
Hi Peter

It is hard to say without seeing the code that generates the streams, but at any rate, you should always reset the position of the stream before attempting to read it.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: