最近在使用python 处理一些图形的东西。python
实现:对一些512 的图进行像素遍历RGBA 变量, 查询通道不是 255 255 255 颜色 的矩阵,进行切图到空白c++
以前使用c#进行 确实快10 倍左右, python 要等很长时间, c#
c++ 我本身不上手,因此想用python 调用c#dll 。程序使用cpython 写的,后来查询 能够使用ironpython 和dotnet进行交换,测试
这些不过,家里测试没有问题,能够到公司 老是不能建立工程, 我也是醉了。spa
https://social.msdn.microsoft.com/Forums/zh-CN/80e5d654-caf4-48c8-9c19-a6e2ae5f22bb/vs.net
安装这个 我也找不出来什么问题。debug
搞了半天, 想这样 c++ 使用CLR 封装 c# dll python 在调用c++的dll 这样一来下路不知道效率如何?code
就开始了blog
using System; using System.Collections.Generic; using System.Text; namespace sen { public class Class1 { public string each () { return "ceshi"; } } }
而后c++ 进行封装 utf-8
#pragma once using namespace System; #using "..\debug\sen.dll" using namespace sen ; using namespace std ; namespace lr { public ref class Clname { // TODO: 在此处添加此类的方法。 public: char* send () { Class1 ^ci= gcnew Class1(); System::String ^c = gcnew System::String(ci->each()); char* ss = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(c); //printf (ss); return ss ; } }; }
编译是经过了。
麻烦出如今下一步, c++ 给python 调用还要绑定 看了看很麻烦
http://blog.csdn.net/fxjtoday/article/details/6059874
最后感受有时间在研究吧, 感受这样一部下路 在没有纯python快 那真实费力不讨好
、由于就是一个调用关系 ,后来想一想 干脆使用 c#控制台
给python调用
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication6 { class Program { static int Main(string[] args) { if(args.Length>0){ foreach (string i in args) { Console.WriteLine(i); } } if (args[1]=="11") { Console.WriteLine(50); return 50; }else { return 20; } } } }
编译成exe 给python 调用
#coding:utf-8 print "ss" #from ctypes import* #filename = r"N:\E\egret\Labs\projects\lr\Debug\lr.dll" #func = cdll.LoadLibrary(filename) #print (func.send) import os cmd = r"F:\c#\c#2005\ConsoleApplication6\ConsoleApplication6\bin\Debug\ConsoleApplication6.exe" v = os.system("%s %s %s" % (cmd ,"dd" , "11dd")) print "*************" print type(v)
结果仍是比较满意的,
ss
dd
11dd
*************
<type 'int'>
同时写好的 给max 脚本调用
cc = "F:\\c#\\c#2005\\ConsoleApplication6\\ConsoleApplication6\bin\\Debug\\ConsoleApplication6.exe" c = DOSCommand (cc+ " sdf"+ " 11") "F:\c#\c#2005\ConsoleApplication6\ConsoleApplication6\bin\Debug\ConsoleApplication6.exe" 50