Reputation: 11
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??
Upvotes: 1
Views: 801
Reputation: 2321
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.
Upvotes: 1
Reputation: 398
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.
Upvotes: 0