[Insight-users] Requesting ITK image from C#

Dan Mueller dan.muel at gmail.com
Sat Jun 20 00:44:19 EDT 2009


Hi,

Please post to the list the source code with a minimal example of the
issue you are facing.

Without seeing source code, one thing I can think of is that perhaps
the ITK objects are being release after your first function call. If
there are no references to the object (ie. a global static variable in
your dll) then ITK's SmartPointer functionality will free everything
when leaving the function, so when you call WriteImage the memory
locations are no longer valid. If this is happening, you could "solve"
it by artificially adding a reference count to the objects you want to
keep alive (caution: make sure you remember to decrement the reference
count at the end!). It could be something entirely different though...

If you want to use ITK from C# you might also consider using ManagedITK:
    http://code.google.com/p/manageditk/

Hope this helps.

Cheers, Dan

2009/6/19 wail ba-alawi <ba3lwi at gmail.com>:
> Hi all,
>
> I have a windows form app in C# as my interface and I have some methods
> written in C++ dll using the ITK library
>
> what I did is to create a function(ReadImage) that reads an image and return
> it as:
> itk::ImageSource<itk::Image<unsigned short,2>>::OutputImageType* obj;
> obj = static_cast<itk::Image<unsigned short,2>*>(reader->GetOutput());
> return obj;
>
> and another function(WriteImage) in the same dll will take that output as an
> Input to to an ITK writer
>
> when I call the (WriteImage) function in the (ReadImage) within the dll
> everything goes perfectly
> but when I do the following I get memory violation:
> I call the (ReadImage) from C# and assign the output to Intptr
> then I call the (WriteImage) from C# and insert the Intptr as an Input
> the second call gives always a memory violation error
>
> any idea of what can I do?
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list