Thanks for the help. vil_stream_core cannot be used without deriving it (it has a protected destructor). I've created a simple derived class and I end up with the same problem when using it.

I'll try that debugging tip with vil_stream_core.

Patrick Reynolds
R & D Engineer
Kitware, Inc.

On Wed, Apr 29, 2009 at 11:22 AM, Ian Scott <ian.m.scott@student.manchester.ac.uk> wrote:
Not that this will fix your actual problem, but you are trying to write into a buffer, so why go via a vil_stream_fstream which wraps a real file? Just use the in memory derivative of vil_stream - vil_stream_core.

Have you checked if your tmp file contains a valid png?

One possibility is that the png image resource won't finish (or possibly even start) writing the file until the resource is destroyed.

If it isn't that, I can't see anything obviously wrong. But I start debugging by putting a break point at the vil_stream_whatever::write() method and check that meaningful data is going into the stream.


Patrick Reynolds wrote:
Hi all,

I'm trying to write a simple application that takes a vil_image_view and writes it to a buffer in a given encoding, png for example. The method in which I'm trying to do this seems logical, but doesn't yield the correct data into the buffer (code below):

vil_image_view<vxl_byte> frame = vil_load( "test.png" );
vil_png_file_format png;
vil_stream_fstream* pngStream = new vil_stream_fstream( "tmp", "r" ); // I've tried this with 'w' as well
vil_image_resource_sptr pngImageRes = png.make_output_image(
                                                      frame.ni <http://frame.ni>(),

                                                      VIL_PIXEL_FORMAT_BYTE );

pngImageRes->put_view( frame );
char* buf = new char[ pngStream->file_size() ];
pngStream->read( buf, pngStream->file_size() );

I've also tried this using a simple sub-class of vil_stream_core that simply makes its destructor public, but I get the same or similar results. Hopefully, I'm missing something simple.

Also, sorry if this is a question that's been asked before, sourceforge's mailing list search seems to be broken... Anyone know of another way to search it?

Patrick Reynolds
R & D Engineer
Kitware, Inc.