yuv420 轉bmp的方法:
我找到了一個c寫的exe ,但是c的水準我實在是不敢去修改那個源碼,是以我幹脆就調用這個dll,在c#裡建立了下面這個類, 然後調用 y2b.exe 來轉換, 而且不會顯示出來那個黑屏.要知道怎麼回事,就看代碼吧!呵呵.
using system;
using system.collections.generic;
using system.text;
using system.diagnostics;
using system.drawing;
using system.io;
namespace jximage
{
public class yuv2bmp
{
/// <summary>
/// 檢查程式配置是否正常, 比如exe路徑,圖檔檔案夾等. 一般情況下設定了路徑和圖檔檔案路徑以及圖檔後,應該使用屬性取得是否可以執行指令.
/// </summary>
public bool canuse
{
get
{
if (system.io.file.exists(system.windows.forms.application.startuppath + "//y2b.exe") )
{
return true;
}
return false;
}
}
private string bmpfile = null;
/// bmp檔案名, 在成功執行轉換後可以用此獲得檔案路徑..
/// <returns>傳回檔案名</returns>
public string getbmpfilename()
return bmpfile;
/// bmp資料流,成功轉換後可以從此獲得流 .
/// <returns>資料流形式的bmp </returns>
public memorystream getbmpfilestream()
try
return new memorystream(system.io.file.readallbytes(bmpfile));
catch (exception)
return null;
/// image 成功轉換後可以用此來獲得檔案.
/// <returns>傳回一個圖檔</returns>
public image getbmp()
return image.fromfile(bmpfile);
/// yuv轉bmp
/// <param name="yuvfilename">yuv檔案名</param>
/// <returns>傳回是否成功</returns>
public bool yuvtobmp(string yuvfilename)
{
if (canuse)
string ret = execute(yuvfilename);
if (ret.indexof("ok")>=0)//從0字元開始會有個ok
if (system.io.file.exists(yuvfilename.replace(".yuv", ".bmp")))
{
bmpfile = yuvfilename.replace(".yuv", ".bmp");
}
return false;
/// 執行dos指令.
/// <param name="canmand">指令</param>
/// <returns>傳回執行結果 </returns>
public static string execute(string yuvfilename)
int milliseconds = 2 * 1000;//兩秒
string output = ""; //輸出字元串
if (yuvfilename != null && yuvfilename != "")
process process = new process(); //建立程序對象
processstartinfo startinfo = new processstartinfo();
startinfo.filename =system.windows.forms.application.startuppath +"//y2b.exe" ; //設定需要執行的指令
startinfo.arguments = "/h352 /v288 /""+yuvfilename+"/" /"" +yuvfilename.replace(".yuv",".bmp"); //設定參數,其中的“/c”表示執行完指令後馬上退出
startinfo.useshellexecute = false; //不使用系統外殼程式啟動
startinfo.redirectstandardinput = false; //不重定向輸入
startinfo.redirectstandardoutput = true; //重定向輸出
startinfo.createnowindow = true; //不建立視窗
process.startinfo = startinfo;
try
if (process.start()) //開始程序
if (milliseconds == 0)
process.waitforexit(); //這裡無限等待程序結束
else
process.waitforexit(milliseconds); //這裡等待程序結束,等待時間為指定的毫秒
output = process.standardoutput.readtoend();//讀取程序的輸出
catch
finally
if (process != null)
process.close();
return output;
return null;
}
}

<a href="http://www.mysticboy.cn/attachments/month_0709/7200792711542.rar" target="_blank">點選下載下傳此檔案</a>
如果你要實作更多yuv到bmp的轉換,請使用
dirac-0.7.0 sf上可以搜到哦 . google裡也可以的. 我就不上傳了.
基本支援所有yuv方面的轉換.
不過全部是exe方式的, 如果你打開win32目錄的話,支援vs2003和vs2005 ,也支援其他c++編輯器
如果不會c,那就用我上面的方法弄就行了. 呵呵 .