图像显示中出现白线,请教这是什么原因.(100分)

  • 主题发起人 主题发起人 mage76
  • 开始时间 开始时间
M

mage76

Unregistered / Unconfirmed
GUEST, unregistred user!
从客户端接受数据,解码后用Timage显示.但是显示出来的图像上会出现白色横线,出现位置也上下变化,但是将image.Picture.Bitmap保存为图片后确没有这种白线.请问这是什么原因.相关代码如下.


procedure ShowYuvImage(pBmp, pY, pU, pV:pByteArray; dwWidth, dwHeight, dwDCWidth,dwDCHeight:Longword);
var
hbm: HBitmap;
bmpInfoHeader: TBITMAPINFOHEADER;
bits:Pchar;
begin
yuv2rgb420(pBmp, pY, pU, pV, dwWidth, dwHeight, 1);
bmpInfoHeader.biSize:=SizeOf(BITMAPINFOHEADER);
bmpInfoHeader.biWidth := dwWidth;
bmpInfoHeader.biHeight := -dwHeight;
bmpInfoHeader.biCompression := BI_RGB;
bmpInfoHeader.biPlanes := 1;
bmpInfoHeader.biBitCount := 24;
bmpInfoHeader.biSizeImage := dwHeight*dwWidth*3;
bits:=pchar(pBmp);
hbm := CreateDIBitmap(GetDC(0) ,bmpInfoHeader,
LongInt(CBM_INIT),
bits,
PBITMAPINFO(@bmpInfoHeader)^,
DIB_RGB_COLORS);
Form1.movie.Picture.Bitmap.ReleaseHandle;
Form1.movie.Picture.Bitmap.Handle:=hbm;
//Form1.movie.Picture.Bitmap.SaveToFile('c:/'+inttostr(a)+'.bmp');
end;
这种白线的情况并不是每帧图像都出现,有时隔几帧出现一次,有时连续几帧都出现
 
bmpInfoHeader.biHeight := -dwHeight; ???

bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0;

yuv2rgb420(pBmp, pY, pU, pV, dwWidth, dwHeight, 1);这个函数有没有问题?

一般解码器都可以直接解出RGB格式的。用YUV再转太慢。另外给你一段参考代码

int CXvidDecTestDlg::ini_bitmapinfo(int width, int height, int nBitCounts)
{
//p_dib = new CFG_DIB( 352, 288, 24) ;
int m_nColorEntries = 0 ;
m_lpBMPHdr = (LPBITMAPINFOHEADER)new
char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * m_nColorEntries];
m_lpBMPHdr->biSize = sizeof(BITMAPINFOHEADER); //以下是为BITMAPINFOHEADER结构赋值
m_lpBMPHdr->biWidth = width;
m_lpBMPHdr->biHeight = height;
m_lpBMPHdr->biPlanes = 1;
m_lpBMPHdr->biBitCount = nBitCounts;
m_lpBMPHdr->biCompression = BI_RGB;
m_lpBMPHdr->biSizeImage = 0;
m_lpBMPHdr->biXPelsPerMeter = 0;
m_lpBMPHdr->biYPelsPerMeter = 0;
m_lpBMPHdr->biClrUsed = m_nColorEntries;
m_lpBMPHdr->biClrImportant = m_nColorEntries;
return 1 ;
// ComputeImage();
// memset(m_lpvColorTable, 0, sizeof(RGBQUAD) * m_nColorEntries);
// m_lpDIBits = NULL;
}

int CXvidDecTestDlg::draw_image(unsigned char * image_buffer)
{
int i, j, k ;
static int dcount = 0 ;
unsigned char r, g, b;
k = 0 ;
DWORD dwStart = GetTickCount();
/*for(i = 0 ; i < YDIM ; i++) {
for(j = 0 ; j < XDIM ; j++) {
mem_dc->SetPixel(j, i, RGB(image_buffer[k+2],image_buffer[k+1],image_buffer[k])) ;
k += 3 ;
}
}
*/


mem_dc->SetBkMode(1);
SetTextColor (mem_dc->m_hDC, RGB(0,255,0) ) ;

OSD.Format(_T("第 %d 帧,耗时 %d ms"),++dcount,GetTickCount()- dwStart) ;

//mem_dc-> setbkmode(TempMap.Canvas.handle,transparent);

mem_dc->TextOut(10,10,(const CString) OSD);



StretchDIBits(cur_dc->m_hDC ,
0, 0, XDIM, YDIM,
0, 0, XDIM, YDIM,
image_buffer,(const BITMAPINFO *) m_lpBMPHdr, 0, SRCCOPY);

/*cur_dc->BitBlt(0,0,
XDIM, YDIM,
mem_dc,
0,0,
SRCCOPY) ; */
return 0 ;
}

做视频一般都是用StretchDIBits的。
 
后退
顶部