[Insight-users] Access violation when reading images with itk

Luis Ibanez luis.ibanez at kitware.com
Sun Apr 6 16:58:50 EDT 2008


Hi Peter,

The ImageFileRead is designed to throw exception when it
encounters any problems reading a file.


Please read the ITK Software Guide:

     http://www.itk.org/ItkSoftwareGuide.pdf

in particular the chapter: "Reading and Writing Images".


If the filename is empty, or invalid, the Reader will throw
and exception.


You should handle better this condition in the "catch" block,
by displaying an error to the user informing her/him about
the fact that the filename is invalid.


    Regards,


       Luis



-------------------------------
Boettcher, Dr. Peter wrote:
> I have problems reading images into my itk-MFC-application.
>  
> I have two images I use for testing. Both are grey-scale images stored 
> as tif and as bmp respectively. Both images can be loaded nicely with 
> the ImageViewer-Application.
> I get an access violation error when I execute reader->Update(). when I 
> give a invalide filename to the reader it executes the update command, 
> and gives me an ExceptionObject error.
>  
>  
> Regards, Peter.
>  
>  
>  
>  
> Here is my code
>  
> CString FileName;
> HRESULT hResult;
>  
>  CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, NULL, this);
>  
>  hResult = (int)dlg.DoModal();
>  if(FAILED(hResult)) {
>   return;
>  }
>  FileName = dlg.GetFileName();
> 
>   typedef itk::Image< unsigned short, 2 > ImageType;
>   typedef itk::ImageFileReader< ImageType > ReaderType;
>   ReaderType::Pointer reader = ReaderType::New();
>  reader->SetFileName(FileName);
>  
>  
>  try {
>       std::cout << "Writing image: " << "daga" << std::endl;
>       reader->Update();
>     }
>     catch( itk::ExceptionObject & err ) {
>      
>       std::cerr << "ERROR: ExceptionObject caught !" << std::endl;
>       std::cerr << err << std::endl;
>     }
>  
> ------------------------------------
> Peter Böttcher, Dr med vet, DipECVS
> European Veterinary Specialist in Surgery
> Fachtierarzt für Kleintierchirurgie
> Klinik für Kleintiere
> Universität Leipzig
> An den Tierkliniken 23
> D-04103 Leipzig (Germany)
> Tel: +49-341-9738700
> Fax: +49-341-9738799
> email: boettcher at kleintierklinik.uni-leipzig.de 
> <mailto:boettcher at kleintierklinik.uni-leipzig.de>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list