// 获取一帧图像数据
MVSMARTCAMCTRL_API int __stdcall MV_SC_GetOneFrame(IN void* handle,
IN OUT unsigned char *pData ,
IN unsigned int nDataSize,
IN OUT MV_SC_IMAGE_OUT_INFO* pstImageInfo);
// 结果数据缓存的上限
#define MV_SC_MAX_RESULT_SIZE (1024*16)
// 输出帧的信息
typedef struct _MV_SC_IMAGE_OUT_INFO_
{
unsigned short nWidth; // 图像宽
unsigned short nHeight; // 图像高
unsigned int nFrameNum; // 帧号
unsigned int nFrameLen; // 当前帧数据大小
unsigned int nTimeStampHigh; // 时间戳高32位
unsigned int nTimeStampLow; // 时间戳低32位
unsigned int nResultType; // 输出的消息类型
// 根据消息类型对应不同的结构体
unsigned char chResult[MV_SC_MAX_RESULT_SIZE];
unsigned int nReserved[8]; // 保留
}MV_SC_IMAGE_OUT_INFO
C#代码
/// <summary>
/// 获得相机所拍照片
/// </summary>
/// <param name="handle"></param>
/// <returns></returns>
[DllImport("MvSmartCamCtrl.dll")]
public static extern int MV_SC_GetOneFrame(IntPtr handle, Byte[] pData, int nDataSize, out MV_SC_IMAGE_OUT_INFO pstDevInfo);
// 输出帧的信息
[StructLayout(LayoutKind.Sequential)]
public struct MV_SC_IMAGE_OUT_INFO
{
public short nWidth; // 图像宽
public short nHeight; // 图像高
public int nFrameNum; // 帧号
public int nFrameLen; // 当前帧数据大小
public int nTimeStampHigh; // 时间戳高32位
public int nTimeStampLow; // 时间戳低32位
public int nResultType; // 输出的消息类型
// 根据消息类型对应不同的结构体
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024 * 16)]
public MV_SC_RESULT_BCR chResult;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public int[] nReserved;
}
package Demo;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import com.google.gson.Gson;
public class Demo
{
public static String doPostClient(String json, String url)
{
HttpClient httpClient = new HttpClient();
String rval = "";
PostMethod postMethod = new PostMethod(url);
try
{
Gson gson = new Gson();
InputStream in = new ByteArrayInputStream(objectToByte(json));
postMethod.setRequestBody(in);
HttpClientParams params = new HttpClientParams();
httpClient.setParams(params);
httpClient.executeMethod(postMethod);
byte[] b = postMethod.getResponseBody();
String rtnData = (String) byteToObject(b);
rval = gson.toJson(rtnData);
} catch (Exception e)
{
rval="erro:"+e.getMessage();
} finally
{
postMethod.releaseConnection();
}
return rval;
}
public static byte[] objectToByte(java.lang.Object obj)
{
byte[] bytes = null;
ObjectOutputStream oo = null;
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(out);
gzip.write(obj.toString().getBytes("utf-8"));
gzip.close();
bytes = out.toByteArray();
} catch (Exception e)
{
e.printStackTrace();
} finally
{
if (oo != null)
{
try
{
oo.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
return bytes;
}
private static java.lang.Object byteToObject(byte[] bytes)
{
String obj = "";
ObjectInputStream oi = null;
try
{
ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
GZIPInputStream gzipi = new GZIPInputStream(bi);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gzipi, "UTF-8"));
String line;
while ((line = bufferedReader.readLine()) != null)
{
obj+=line;
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{
if (oi != null)
{
try
{
oi.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
return obj;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有