现在创建视频流:
k#ñ/.Ôforum.entlib.net.cnBoùXeüRk#ñ/.Ôforum.entlib.net.cnBoùXeüR//Create a new video stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRprivate void CreateStream() {
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//describe the stream to create
k#ñ/.Ôforum.entlib.net.cnBoùXeüRAVISTREAMINFO strhdr = new AVISTREAMINFO();
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.fccType = this.fccType; //mmioStringToFOURCC("vids", 0)
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.fccHandler = this.fccHandler; //"Microsoft Video 1"
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.dwScale = 1;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.dwRate = frameRate;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.dwSuggestedBufferSize = (UInt32)(height * stride);
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//use highest quality! Compression destroys the hidden message.
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.dwQuality = 10000;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.rcFrame.bottom = (UInt32)height;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.rcFrame.right = (UInt32)width;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRstrhdr.szName = new UInt16[64];
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//create the stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRint result = AVIFileCreateStream(aviFile, out aviStream, ref strhdr);
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//define the image format
k#ñ/.Ôforum.entlib.net.cnBoùXeüRBITMAPINFOHEADER bi = new BITMAPINFOHEADER();
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biSize = (UInt32)Marshal.SizeOf(bi);
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biWidth = (Int32)width;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biHeight = (Int32)height;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biPlanes = 1;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biBitCount = 24;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbi.biSizeImage = (UInt32)(this.stride * this.height);
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//format the stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRresult = Avi.AVIStreamSetFormat(aviStream, 0, ref bi, Marshal.SizeOf(bi));
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüRk#ñ/.Ôforum.entlib.net.cnBoùXeüR 写入帧:
k#ñ/.Ôforum.entlib.net.cnBoùXeüRk#ñ/.Ôforum.entlib.net.cnBoùXeüR//Create an empty AVI file
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic void Open(string fileName, UInt32 frameRate) {
k#ñ/.Ôforum.entlib.net.cnBoùXeüRthis.frameRate = frameRate;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRAvi.AVIFileInit();
k#ñ/.Ôforum.entlib.net.cnBoùXeüRint hr = Avi.AVIFileOpen(
k#ñ/.Ôforum.entlib.net.cnBoùXeüRref aviFile, fileName,
k#ñ/.Ôforum.entlib.net.cnBoùXeüROF_WRITE | OF_CREATE, 0);
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//Add a sample to the stream - for first sample: create the stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic void AddFrame(Bitmap bmp) {
k#ñ/.Ôforum.entlib.net.cnBoùXeüRBitmapData bmpDat = bmp.LockBits(
k#ñ/.Ôforum.entlib.net.cnBoùXeüRnew Rectangle(0, 0, bmp.Width, bmp.Height),
k#ñ/.Ôforum.entlib.net.cnBoùXeüRImageLockMode.ReadOnly,PixelFormat.Format24bppRgb);
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//this is the first frame - get size and create a new stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRif (this.countFrames == 0) {
k#ñ/.Ôforum.entlib.net.cnBoùXeüRthis.stride = (UInt32)bmpDat.Stride;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRthis.width = bmp.Width;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRthis.height = bmp.Height;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRCreateStream(); //a method to create a new video stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//add the bitmap to the stream
k#ñ/.Ôforum.entlib.net.cnBoùXeüRint result = AVIStreamWrite(aviStream,
k#ñ/.Ôforum.entlib.net.cnBoùXeüRcountFrames, 1,
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbmpDat.Scan0, //pointer to the beginning of the image data
k#ñ/.Ôforum.entlib.net.cnBoùXeüR(Int32) (stride * height),
k#ñ/.Ôforum.entlib.net.cnBoùXeüR0, 0, 0);
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbmp.UnlockBits(bmpDat);
k#ñ/.Ôforum.entlib.net.cnBoùXeüRthis.countFrames ++;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüR[代码中CryptUtility类的改变]
k#ñ/.Ôforum.entlib.net.cnBoùXeüRHideOrExtract() 在前面的版本中一次读入所有载体位图,但现在必须改进了,每次加在一个位图,在加载下一个位图前先释放本位图.当前使用的位图(一个简单的位图或者AVI的一帧)保存在BitmapInfo结构中,通过by ref方式传递
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic struct BitmapInfo{
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//uncompressed image
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic Bitmap bitmap;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//position of the frame in the AVI stream, -1 for non-avi bitmaps
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic int aviPosition;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//count of frames in the AVI stream, or 0 for non-avi bitmaps
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic int aviCountFrames;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//path and name of the bitmap file
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//this file will be deleted later, if aviPosition is 0 or greater
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic String sourceFileName;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR//how many bytes will be hidden in this image
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic long messageBytesToHide;
k#ñ/.Ôforum.entlib.net.cnBoùXeüRpublic void LoadBitmap(String fileName){
k#ñ/.Ôforum.entlib.net.cnBoùXeüRbitmap = new Bitmap(fileName);
k#ñ/.Ôforum.entlib.net.cnBoùXeüRsourceFileName = fileName;
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüR}
k#ñ/.Ôforum.entlib.net.cnBoùXeüR