1

I have a problem with converting *.fig files (from Matlab) into bitmaps (or any type which I could use in pictureBox) using C#.

I need to read this file somehow and then show it in pictureBox.

I tried several ways, for example:

Image img = Image.FromFile(fileName);
Bitmap bmp1 = new Bitmap(img.Width, img.Height);

But I got an "Out of memory" exception thrown in the first step.

Do you have any ideas how to do it??

3
  • 5
    It would seem that such a task is non-trivial: undocumentedmatlab.com/blog/fig-files-format The file itself is not a bitmap or any other image format, it contains the actual MATLAB commands inside of it. Commented Oct 19, 2012 at 19:45
  • 1
    You may want to see if there is some way of integrating with MATLAB itself to have it render you an image of the file. Commented Oct 19, 2012 at 19:47
  • I got this fig files from somebody else, so I have no control to change some settings in matlab. Commented Oct 19, 2012 at 20:00

2 Answers 2

1

I have a proposal:

Instead of a picturebox, put a panel on your windows form. Then, use System.Diagnostics.Process to start the matlab viewer (required dependency for this, sorry). Now, you can use the instructions here to get the windows handle for the main window of the viewer:

How to get main window handle from process id?

Next, change its parent to the panel in your windows form.

http://support.microsoft.com/kb/89563

I've used this trick before and it takes some tweaking, but you can capture another process's main window and make it a child control on your form. If you can find a less messy way of doing this, that would be great.

Sign up to request clarification or add additional context in comments.

1 Comment

Your proposal looks very reasonably, but unfortunately I didn't mention about one other functionality that I have in my application... I mean, I have to insert this picture from pictureBox to sql database as a bite[]... I've just noticed strange situation, some of the fig files from internet works using my first idea...
0

The out of memory exception also occurs when the image file is not in the correct format. http://msdn.microsoft.com/en-us/library/stf701f5.aspx

It's likely you'll need to use some tool to change the .fig file into an image format. I'm not sure how Matlab saves .fig files, so you'll need to do some research as to how the file is actually stored, or find some third party software to update your file to a viable format.

2 Comments

Hmm..I would like to avoid some other tools to change the format.. but thanks for your suggestion
The issue you're going to keep running into is you don't have a picture. You have a figure from Matlab, which may store data in some different way. According to a bit of research, it's a vector file format. You need it as a picture, somehow you're going to have to render it into an image, whether through Matlab, or through some process to turn it into a picture format. Check out: mathworks.com/matlabcentral/fileexchange/… homepage.usask.ca/~ijm451/fig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.