Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a custom image adorner add-in for numerical arrays in Visual Studio 2010?

I work with a lot of floating-point images, and would find it extremely useful to have an image-based representation of my arrays. I'd like to create a WPF UserControl that renders the data array (as shown below) as an image, instead of a scrollable list of text values.

Is this possible? I have looked at the MDSN documentation on VS 2010 extensibility, at SO's list of VS 2010 extensions, and at this topic on creating a custom editor, but I'm a bit lost on where to start.

alt text

Update 1:

Thanks to Brian and Basarat Ali for the leads on DebuggerVisualizer. Looks like the correct strategy, EXCEPT that unfortunately a visualizer for any type of arrays is disallowed.

A work-around (of limited utility) is to visualize a wrapper object.

At Brian's suggestion, I have posted a solution on CodePlex:

VS2010 Debugger Visualizers Contrib (http://debuggervisualizers.codeplex.com/).

The project's source code demonstrates a working wrapper visualizer and a non-functional "raw" data visualizer for a 1D double[] array. Here's a screenshot of the test console running:

alt text

If anyone has any suggestions on how to work-around this problem, please let me know!

Also, any explanation of why System.Array cannot be visualized is welcome!

Update 2:

I just re-searched SO with the word DebuggerVisualizer, and find this to be previously asked. Looks like user Will Dean suggests implementing Project Mole's work-around using a WeakReference. Don't see how this would work in a DebuggerVisualizer, though.

Update 3:

Josh Smith of Project Mole just suggested a very helpful work around (thanks Josh!):

Note, you can use your ArrayWrapper approach without needing to modify your source code to open a visualizer. You can type this into the Watch window in VS:

new YourNamespace.ArrayWrapper(myArray);

Hit the Enter key, then you should see a magnifying glass icon in the Watch window next to that line of code. Click it to open your custom visualizer.

like image 979
lightw8 Avatar asked Nov 09 '10 22:11

lightw8


1 Answers

You should create a debugger visualizer. Here's a walkthrough : http://msdn.microsoft.com/en-us/library/ms164759.aspx . I believe that what you want is to be able to view all the results in an external program. For this you can just add an export option to you list to export as a csv file. However if you still feel you want a bitmap you can convert the list to an image using RenderTargetBitmap : http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx

like image 171
basarat Avatar answered Nov 09 '22 11:11

basarat