using System;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;using Server.Public;namespace Server.Multimedia.Video
{
/// <summary>
/// Compress 的摘要说明。
/// </summary>
public class ICBase
{
protected int hic;
protected ICMODE mode;
protected BITMAPINFO _in;
protected BITMAPINFO _out;
protected COMPVARS pp;
protected int fourcc;
protected COMPVARS Compvars
{
get{return this.pp;}
}
public ICBase(COMPVARS cp,BITMAPINFO biIn,ICMODE mode,int fourcc)
{
this.pp=cp;
this._in=biIn;
this.mode=mode;
this.fourcc=fourcc;
_out=new BITMAPINFO();
} #region
public int HIC
{
get{return this.hic;}
}
public BITMAPINFO InFormat
{
get{return this._in;}
}
public BITMAPINFO OutFormat
{
get{return this._out;}
}
public ICMODE Mode
{
get{return this.mode;}
}
public int Fourcc
{
get{return this.fourcc;}
}
#endregion public virtual void Open()//(System.IntPtr p)
{
this.hic=ICOpen(FOURCC.ICTYPE_VIDEO,this.fourcc,this.mode);
this.Compvars.hic=this.hic;
}
public virtual byte[] Process(byte[] data)
{
return null;
} public virtual void Close()
{
ICClose(hic);
}
#region
[DllImport("MSVFW32.dll")]
public static extern void ICSeqCompressFrameEnd(ref COMPVARS pc);
/* [DllImport("MSVFW32.dll")]
public static extern IntPtr ICSeqCompressFrame(
COMPVARS pc,
int uiFlags,
IntPtr lpBits,
ref bool pfKey,
ref int plSize
);*/
[DllImport("MSVFW32.dll")]
public static extern int ICCompressGetFormatSize(
int hic,
ref BITMAPINFO lpbiInput
);
[DllImport("MSVFW32.dll")]
public static extern bool ICSeqCompressFrameStart(
COMPVARS pc,
ref BITMAPINFO lpbiIn
);
[DllImport("MSVFW32.dll")]
public static extern int ICSeqCompressFrame(
COMPVARS pc,
int uiFlags,
byte[] lpBits,
ref bool pfKey,
ref long plSize
);
[DllImport("MSVFW32.dll",CharSet=CharSet.Ansi)]
public static extern int ICGetInfo(
int hic,
ICINFO lpicinfo,
int cb
);
[DllImport("MSVFW32.dll")]
public static extern bool ICCompressorChoose(
IntPtr hwnd,
int uiFlags,
//ref BITMAPINFO pvIn,
int pvIn,
int lpData,
COMPVARS pc,
string lpszTitle
);
[DllImport("MSVFW32.dll")]
public static extern int ICLocate(
int fccType,
int fccHandler,
ref BITMAPINFOHEADER lpbiIn,
ref BITMAPINFOHEADER lpbiOut,
short wFlags
);
[DllImport("MSVFW32.dll"),PreserveSig]
public static extern int ICOpen(int fccType,int fccHandler,ICMODE wMode);
[DllImport("MSVFW32.dll")]
public static extern int ICClose(int hic);
[DllImport("MSVFW32.dll")]
public static extern int ICCompress(
int hic,
int dwFlags, // flags
ref BITMAPINFOHEADER lpbiOutput, // output format
IntPtr lpData, // output data
ref BITMAPINFOHEADER lpbiInput, // format of frame to compress
IntPtr lpBits, // frame data to compress
int lpckid, // ckid for data in AVI file
int lpdwFlags, // flags in the AVI index.
int lFrameNum, // frame number of seq.
int dwFrameSize, // reqested size in bytes. (if non zero)
int dwQuality, // quality within one frame
// BITMAPINFOHEADER lpbiPrev, // format of previous frame
int lpbiPrev, // format of previous frame
int lpPrev // previous frame
);
[DllImport("MSVFW32.dll")]
public static extern int ICDecompress(
int hic,
int dwFlags,
ref BITMAPINFOHEADER lpbiFormat,
byte[] lpData,
ref BITMAPINFOHEADER lpbi ,
byte[] lpBits
);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,ref BITMAPINFO dw1,ref BITMAPINFO dw2);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,int dw1,int dw2);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,ICINFO dw1,int dw2);
public static readonly int DRV_USER =0x4000;
public static readonly int ICM_USER =(DRV_USER+0x0000);
public static readonly int ICM_COMPRESS_BEGIN =(ICM_USER+7); // begin a series of compress calls.
public static readonly int ICM_COMPRESS =(ICM_USER+8) ; // compress a frame
public static readonly int ICM_COMPRESS_END =(ICM_USER+9) ; // end of a series of compress calls.
public static readonly int ICM_COMPRESS_GET_FORMAT =(ICM_USER+4);
public static readonly int ICM_DECOMPRESS_BEGIN =(ICM_USER+12); // start a series of decompress calls
public static readonly int ICM_DECOMPRESS =(ICM_USER+13); // decompress a frame
public static readonly int ICM_DECOMPRESS_END =(ICM_USER+14);
#endregion
}
public class ICCompressor:ICBase//视频压缩
{
public ICCompressor(COMPVARS cp,BITMAPINFO biIn,int fourcc):base(cp,biIn,ICMODE.ICMODE_COMPRESS,fourcc)
{
}
public override void Open()
{
base.Open ();
int r=ICSendMessage(hic,ICM_COMPRESS_GET_FORMAT,ref this._in,ref this._out);
bool s=ICSeqCompressFrameStart(this.Compvars,ref this._in);
}
public override byte[] Process(byte[] data)
{
if(this.hic==0)return null;
bool key=false;long size=0;
try
{
lock(data)
{ IntPtr r=(IntPtr)ICSeqCompressFrame(this.pp,0,data,ref key,ref size);
byte[] b=new byte[size];
Marshal.Copy(r,b,0,(int)size);
return b;
}
}
catch(System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
return null;
}
public override void Close()
{
if(this.hic!=0)
{
try
{
ICSeqCompressFrameEnd(ref this.pp);
}
catch
{
}
}
base.Close ();
}
}
public class ICDecompressor:ICBase//视频解压缩
{
public ICDecompressor(COMPVARS cp,BITMAPINFO biIn,int fourcc):base(cp,biIn,ICMODE.ICMODE_DECOMPRESS,fourcc)
{
}
public override void Open()
{
base.Open ();
int r=ICSendMessage(hic,ICM_USER+10,ref this._in,ref this._out);//get the output bitmapinfo
r=ICSendMessage(hic,ICM_DECOMPRESS_BEGIN,ref this._in,ref this._out);
}
public override byte[] Process(byte[] data)
{
return data;// if(this.hic==0)return null;
// byte[] b=new byte[this._out.bmiHeader.biSizeImage];;
// try
// {
// int i=ICDecompress(this.hic,0,ref this._in.bmiHeader,data,ref this._out.bmiHeader,b);
// }
// catch
// {
// }
// return b;
}
public override void Close()
{
if(this.hic!=0)
{
ICSendMessage(hic,ICM_USER+14,0,0);//get the output bitmapinfo
}
base.Close ();
}
}
}
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;using Server.Public;namespace Server.Multimedia.Video
{
/// <summary>
/// Compress 的摘要说明。
/// </summary>
public class ICBase
{
protected int hic;
protected ICMODE mode;
protected BITMAPINFO _in;
protected BITMAPINFO _out;
protected COMPVARS pp;
protected int fourcc;
protected COMPVARS Compvars
{
get{return this.pp;}
}
public ICBase(COMPVARS cp,BITMAPINFO biIn,ICMODE mode,int fourcc)
{
this.pp=cp;
this._in=biIn;
this.mode=mode;
this.fourcc=fourcc;
_out=new BITMAPINFO();
} #region
public int HIC
{
get{return this.hic;}
}
public BITMAPINFO InFormat
{
get{return this._in;}
}
public BITMAPINFO OutFormat
{
get{return this._out;}
}
public ICMODE Mode
{
get{return this.mode;}
}
public int Fourcc
{
get{return this.fourcc;}
}
#endregion public virtual void Open()//(System.IntPtr p)
{
this.hic=ICOpen(FOURCC.ICTYPE_VIDEO,this.fourcc,this.mode);
this.Compvars.hic=this.hic;
}
public virtual byte[] Process(byte[] data)
{
return null;
} public virtual void Close()
{
ICClose(hic);
}
#region
[DllImport("MSVFW32.dll")]
public static extern void ICSeqCompressFrameEnd(ref COMPVARS pc);
/* [DllImport("MSVFW32.dll")]
public static extern IntPtr ICSeqCompressFrame(
COMPVARS pc,
int uiFlags,
IntPtr lpBits,
ref bool pfKey,
ref int plSize
);*/
[DllImport("MSVFW32.dll")]
public static extern int ICCompressGetFormatSize(
int hic,
ref BITMAPINFO lpbiInput
);
[DllImport("MSVFW32.dll")]
public static extern bool ICSeqCompressFrameStart(
COMPVARS pc,
ref BITMAPINFO lpbiIn
);
[DllImport("MSVFW32.dll")]
public static extern int ICSeqCompressFrame(
COMPVARS pc,
int uiFlags,
byte[] lpBits,
ref bool pfKey,
ref long plSize
);
[DllImport("MSVFW32.dll",CharSet=CharSet.Ansi)]
public static extern int ICGetInfo(
int hic,
ICINFO lpicinfo,
int cb
);
[DllImport("MSVFW32.dll")]
public static extern bool ICCompressorChoose(
IntPtr hwnd,
int uiFlags,
//ref BITMAPINFO pvIn,
int pvIn,
int lpData,
COMPVARS pc,
string lpszTitle
);
[DllImport("MSVFW32.dll")]
public static extern int ICLocate(
int fccType,
int fccHandler,
ref BITMAPINFOHEADER lpbiIn,
ref BITMAPINFOHEADER lpbiOut,
short wFlags
);
[DllImport("MSVFW32.dll"),PreserveSig]
public static extern int ICOpen(int fccType,int fccHandler,ICMODE wMode);
[DllImport("MSVFW32.dll")]
public static extern int ICClose(int hic);
[DllImport("MSVFW32.dll")]
public static extern int ICCompress(
int hic,
int dwFlags, // flags
ref BITMAPINFOHEADER lpbiOutput, // output format
IntPtr lpData, // output data
ref BITMAPINFOHEADER lpbiInput, // format of frame to compress
IntPtr lpBits, // frame data to compress
int lpckid, // ckid for data in AVI file
int lpdwFlags, // flags in the AVI index.
int lFrameNum, // frame number of seq.
int dwFrameSize, // reqested size in bytes. (if non zero)
int dwQuality, // quality within one frame
// BITMAPINFOHEADER lpbiPrev, // format of previous frame
int lpbiPrev, // format of previous frame
int lpPrev // previous frame
);
[DllImport("MSVFW32.dll")]
public static extern int ICDecompress(
int hic,
int dwFlags,
ref BITMAPINFOHEADER lpbiFormat,
byte[] lpData,
ref BITMAPINFOHEADER lpbi ,
byte[] lpBits
);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,ref BITMAPINFO dw1,ref BITMAPINFO dw2);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,int dw1,int dw2);
[DllImport("MSVFW32.dll")]
public static extern int ICSendMessage(int hic,int msg,ICINFO dw1,int dw2);
public static readonly int DRV_USER =0x4000;
public static readonly int ICM_USER =(DRV_USER+0x0000);
public static readonly int ICM_COMPRESS_BEGIN =(ICM_USER+7); // begin a series of compress calls.
public static readonly int ICM_COMPRESS =(ICM_USER+8) ; // compress a frame
public static readonly int ICM_COMPRESS_END =(ICM_USER+9) ; // end of a series of compress calls.
public static readonly int ICM_COMPRESS_GET_FORMAT =(ICM_USER+4);
public static readonly int ICM_DECOMPRESS_BEGIN =(ICM_USER+12); // start a series of decompress calls
public static readonly int ICM_DECOMPRESS =(ICM_USER+13); // decompress a frame
public static readonly int ICM_DECOMPRESS_END =(ICM_USER+14);
#endregion
}
public class ICCompressor:ICBase//视频压缩
{
public ICCompressor(COMPVARS cp,BITMAPINFO biIn,int fourcc):base(cp,biIn,ICMODE.ICMODE_COMPRESS,fourcc)
{
}
public override void Open()
{
base.Open ();
int r=ICSendMessage(hic,ICM_COMPRESS_GET_FORMAT,ref this._in,ref this._out);
bool s=ICSeqCompressFrameStart(this.Compvars,ref this._in);
}
public override byte[] Process(byte[] data)
{
if(this.hic==0)return null;
bool key=false;long size=0;
try
{
lock(data)
{ IntPtr r=(IntPtr)ICSeqCompressFrame(this.pp,0,data,ref key,ref size);
byte[] b=new byte[size];
Marshal.Copy(r,b,0,(int)size);
return b;
}
}
catch(System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
return null;
}
public override void Close()
{
if(this.hic!=0)
{
try
{
ICSeqCompressFrameEnd(ref this.pp);
}
catch
{
}
}
base.Close ();
}
}
public class ICDecompressor:ICBase//视频解压缩
{
public ICDecompressor(COMPVARS cp,BITMAPINFO biIn,int fourcc):base(cp,biIn,ICMODE.ICMODE_DECOMPRESS,fourcc)
{
}
public override void Open()
{
base.Open ();
int r=ICSendMessage(hic,ICM_USER+10,ref this._in,ref this._out);//get the output bitmapinfo
r=ICSendMessage(hic,ICM_DECOMPRESS_BEGIN,ref this._in,ref this._out);
}
public override byte[] Process(byte[] data)
{
return data;// if(this.hic==0)return null;
// byte[] b=new byte[this._out.bmiHeader.biSizeImage];;
// try
// {
// int i=ICDecompress(this.hic,0,ref this._in.bmiHeader,data,ref this._out.bmiHeader,b);
// }
// catch
// {
// }
// return b;
}
public override void Close()
{
if(this.hic!=0)
{
ICSendMessage(hic,ICM_USER+14,0,0);//get the output bitmapinfo
}
base.Close ();
}
}
}
解决方案 »
- wpf后台代码移动控件的位置
- VS2008 VC#环境下如何调用外部的EXE程序
- 求一个算法
- 用C#怎么实现广告创建时,可以绑定用户,广告到期后,系统发送到会员的站内短信和E-mail
- C# 实现 SMTP POP3 相关操作源代码
- [提問]利用WMI,可以結束遠程機器中指定的進程嗎?
- 怎么将xml文件里的内容读出来,并且给用户显示成树型结构的样式啊?
- ......
- 如何实现自动导入数据到sharepoint 网站的List中?
- Web间数据传送问题!
- WFP TabItem设置trigger无效
- ________________电脑怎么玩比较爽???.......................................
{
if (this.hic == 0) return null;
bool key = false; long size = 0;
try
{
lock (data)
{ IntPtr r = (IntPtr)ICSeqCompressFrame(this.pp, 0, data, ref key, ref size);
byte[] b = new byte[size];
Marshal.Copy(r, b, 0, (int)size);
return b;
}
}
catch (System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
return null;
}问题肯定在这里!
你跟代码了么?
{
this.hic=ICOpen(FOURCC.ICTYPE_VIDEO,this.fourcc,this.mode);
this.Compvars.hic=this.hic;
}这个地方是获取hic,这个要调用系统函数
IntPtr r=(IntPtr)ICSeqCompressFrame(this.pp,0,data,ref key,ref size);
[email protected]
{
this.hic=ICOpen(FOURCC.ICTYPE_VIDEO,this.fourcc,this.mode);
this.Compvars.hic=this.hic;
}
这个地方的hic的值老是0,
把if (this.hic == 0) return null;
这行给注释掉
IntPtr r = (IntPtr)ICSeqCompressFrame(this.pp, 0, data, ref key, ref size); 其中r的值为0,则返回为空
是呀,解决没有呀,兄弟们都等信呢!!!都是这个问题!郁闷中!还忘楼主给贴出答案,,谢啦!
能不能给我一份关键代码研究一下啊?
谢谢
邮箱:[email protected]
public virtual void Open()//(System.IntPtr p)
{
this.hic=ICOpen(FOURCC.ICTYPE_VIDEO,this.fourcc,this.mode);
this.Compvars.hic=this.hic;
} 因为你系统没装有对应的解码器,所以这个icopen一直返回零。
微软的文档是这样说明这个返回值的:"Returns a handle to a compressor or decompressor if successful or zero otherwise"解决的办法是下载你程序编码所用的解码器,我估计你程序里是用MPEG codec。
到这个连接去下载解码器:http://www.movavi.com/codec/mp42.html
希望可以帮助大家