如何将图像从matlab程序传递到c#程序? [英] How to pass images from a matlab program to a c# program?

查看:91
本文介绍了如何将图像从matlab程序传递到c#程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人帮我将数据和图像从matlab中的程序传递到c#中的程序。这两个程序将在同一系统或网络中同时运行。

我想要远程或内存共享概念。

我搜索了很多,大部分结果我发现类似于在C#中访问整个matlab程序作为DLL,这对我来说是不可行的。我希望这两个程序能够独立运行并且可以进行通信。

Please any one help me to pass data and images from a program in matlab to a program in c# . Both programs will be running simultaneously in same system or in a network.
I want something like remoting or memory share concept.
I searched a lot and most of the result I found is something like accessing whole matlab program as a DLL in C#, which is not feasible for me. I want both the programs to run independently and can communicate.

推荐答案

我没有运行示例,但如果这两个应用程序在同一台机器上运行你可以使用user32.dll程序集中的功能来获取Matlab程序窗口的屏幕截图。这允许您获取图像。获取数据可能涉及在Matlab程序的控制树中挖掘以找到包含数据的正确控件。您可以使用Inspect执行此操作: http:// msdn .microsoft.com / zh-CN / library / windows / desktop / dd318521(v = vs.85).aspx [ ^ ]。



如果您使用的是.NET 4.5,则可以使用UI自动化功能: http://msdn.microsoft.com/en-us/library/ms747327(v=vs.110).aspx [ ^ ]。



下面是获取图像的示例:

I don't have a running example, but if the two applications are running on the same machine you can use functionality from the user32.dll assembly to get a 'screenshot' of the Matlab program window. This allows you to get the images. Getting the data would probably involve 'digging' in the control tree of the Matlab program to find the right controls containing the data. You can use Inspect to do this: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318521(v=vs.85).aspx[^].

If you are on .NET 4.5, you can use the UI Automation functionality: http://msdn.microsoft.com/en-us/library/ms747327(v=vs.110).aspx[^].

Below is an example to get the images:
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);

public static Bitmap PrintWindow(IntPtr hwnd)    
{       
    RECT rc;        
    GetWindowRect(hwnd, out rc);

    Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);        
    Graphics gfxBmp = Graphics.FromImage(bmp);        
    IntPtr hdcBitmap = gfxBmp.GetHdc();        

    PrintWindow(hwnd, hdcBitmap, 0);  

    gfxBmp.ReleaseHdc(hdcBitmap);               
    gfxBmp.Dispose(); 

    return bmp;   
}


这篇关于如何将图像从matlab程序传递到c#程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆