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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 SetImageFromStream does not get image sometimes

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Aug 11 2017 : 11:47:27
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?
10   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Aug 17 2017 : 04:12:33
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
PeterPanino Posted - Aug 16 2017 : 18:09:05
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.
xequte Posted - Aug 14 2017 : 20:05:02
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
PeterPanino Posted - Aug 14 2017 : 04:40:22
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!
PeterPanino Posted - Aug 14 2017 : 02:52:26
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!
xequte Posted - Aug 13 2017 : 20:18:28
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
PeterPanino Posted - Aug 12 2017 : 07:54:54
BTW, the IO.ExecuteOpenDialog preview identifies the dump0.dat file as:

PeterPanino Posted - Aug 12 2017 : 07:31:12
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?
PeterPanino Posted - Aug 11 2017 : 20:12:38
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.
xequte Posted - Aug 11 2017 : 18:15:40
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