#region YUV 转 RGB
private static int R = 0;
private static int G = 1;
private static int B = 2;
public static Bitmap GetImagByYuvToRGB(string path, int width, int height)
{
//int width = 1280;
//int height = 720;
// string path = “D:\1.yuv”;
// Bitmap bmp = Helper.GetImagByYuvToRGB(path, width, height);
// bmp.Save(“D:\yuv2bmp_1.bmp”)
int imgSize = width * height;
int frameSize = imgSize + (imgSize >> 1);
Bitmap bm = null;
byte[] yuv = new byte[frameSize];
byte[] rgb = new byte[3 * imgSize];
using (FileStream fs = File.OpenRead(path))
{
int frame = (int)fs.Length / frameSize;
using (BinaryReader br = new BinaryReader(fs))
{
while (br.PeekChar() != -1)
{
// 循环读取每一桢
br.Read(yuv, 0, frameSize);
}
}
bm = Helper.Yuv420_RGB24(yuv, width, height);
// bm.Save("D:\\yuv2bmp_1.bmp");
}
return bm;
}
/// <summary>
/// YUV420转RGB24
/// </summary>
/// <param name="yuvFrame">YUV 格式图像数据。</param>
/// <param name="rgbFrame">RGB 格式图像数据。</param>