
Hi there, you're passing an Image into your and override the view member with a view to the a local gil::image. After the crop function is done this local image is destroyed the the view to that image now points to garbage. Also it's unclear to me how you initialize the view member in your Image class. This works on my machine: #include <boost/gil/gil_all.hpp> using namespace boost::gil; rgb8_image_t s( 100, 100 ); class Image { public: Image( rgb8_view_t v ) : _view( v ) {} void crop( int x, int y, int width, int height, Image& out ) { copy_pixels( subimage_view( _view , 0 , 0 , 100 , 100 ) , view( s ) ); out._view = view( s ); } public: rgb8_view_t _view; }; int main ( int argc , char **argv) { rgb8_image_t img( 100, 100 ); Image i( view( img ) ); Image out( view( img ) ); i.crop( 100, 100, 50, 50, out ); return 0; } Cheers, Christian