[Insight-users] Error on buffer deletion

Frank Schmitt frank.schmitt at igd.fraunhofer.de
Fri Dec 16 05:57:40 EST 2005


Hi,

if i want to delete the buffer of an rgb/rgba image an exception occurs
(this does not happen with scalar images).

Here is example code, which shows what i mean.
Is there something wrong with my code?

#include "itkRGBAPixel.h"
#include "itkRGBPixel.h"
#include "itkImage.h"
#include "itkImageFileReader.h"

int main(int argc, char ** argv)
{
  typedef itk::RGBAPixel< unsigned char >    PixelType;
// If you use the following PixelType no exception
//typedef unsigned char    PixelType;
  typedef itk::Image< PixelType, 2 >   ImageType;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( "someRGBImage.bmp" );
  reader->Update();
  ImageType::Pointer itkimage = reader->GetOutput();
  itkimage->GetPixelContainer()->SetContainerManageMemory(false);
  itkimage->SetGlobalReleaseDataFlag(false);
  PixelType* pixelbuffer = itkimage->GetBufferPointer();
  delete pixelbuffer;

  return 0;
}

Another thing I noticed is that after reading an rgb-image imageio says it
is scalar with 3 components, but reading an png-image everthing is as
expected: imageio says rgb image with 1 component?

Thanks for any help,
Frank






More information about the Insight-users mailing list