日期:2014-05-16  浏览次数:20565 次

急,急,急。。在LINUX下无何处理BMP图片呢?如果把三副BMP合成一副呢?

急,急,急。。在LINUX下无何处理BMP图片呢?如果把三副BMP合成一副呢?
望高手提供思路或者提供源代码例子,或者提供一些线索。。。
公司要我做,现在遇到麻烦了。。。


------解决方案--------------------
用GIMP不可以么??
------解决方案--------------------
qt下直接QPixmap pic("yours.bmp");就可以读取BMP图片了。

bmp处理的话首先要大致了解一下bmp的编码,然后可以参考一些开源的库或者干脆直接使用。

比如netbmp,ImageMagick,graphicmagic之类~~~
------解决方案--------------------
gimp类似于photoshop,只能处理,不能嵌入程序吧~~~
------解决方案--------------------
贴个源码参考,加载部分

bool LoadBmp(ImgInf * pRetInf, const char * psz)
{
bool bRet;
FILE * fh=NULL;
int nSize=0, nReadSize;
uint8 * pBuf=NULL;

fh=OpenImageFile(psz);
if(!fh)
return false;

nSize=GetFileSize(fh);
if(!nSize) return false;
pBuf=(uint8 *)malloc(nSize);
if(!pBuf)
{
dprintf("\n*** Error: malloc failed to read file!");
return false;
}
memset(pBuf, 0, nSize);
nReadSize=fread(pBuf, 1, nSize, fh);
if(nReadSize != nSize)
{
dprintf("\n*** Error: Read size %d != Real size %d", nReadSize, nSize);
}
fclose(fh);
bRet=ConvertBmpToImgInf(pRetInf, pBuf);
if(!bRet)
{
dprintf("\nConvertBmpToImgInf failed!");
}
free(pBuf);
return bRet;
}


FILE * OpenImageFile(const char * psz)
{
FILE *fh;
char szPathName[MAX_PATHNAME];

if(!psz || !(*psz)) return false;
AddDefPath_Postfix(szPathName, psz, NULL, NULL);
fh=fopen(szPathName, "rb");
if(!fh)
{
dprintf("\nOpen %s failed!", szPathName);
return NULL;
}
return fh;
}

bool ConvertBmpToImgInf(ImgInf * pImgInf, uint8 * pBuf)
{
ColorTbl * pTbl, * pCurrTbl;
uint16 nBitsPerPixel, biCompression, biPlanes;
uint8 * pData, * pDataCurr, * pLineDataCurr;
uint32 nCurrX, nCurrY, nWidth, nHeight;
int nLineDataSize, nTmp;
uint32 nSrcColor, nSht, biSize;
color CurrColor, *pCurrCol;

if(!pImgInf || !pBuf) return false;
biSize =*((uint32*)(pBuf+nSizeBmpFileHeader+0));
nWidth =*((uint32*)(pBuf+nSizeBmpFileHeader+4));
nHeight =*((uint32*)(pBuf+nSizeBmpFileHeader+8));
biPlanes =*((uint16*)(pBuf+nSizeBmpFileHeader+12));
nBitsPerPixel =*((uint16*)(pBuf+nSizeBmpFileHeader+14));
biCompression =*((uint32*)(pBuf+nSizeBmpFileHeader+16));

if(biCompression)
{
dprintf("\n*** Error: Can not open compressed file");
return false;
}
if(nBitsPerPixel != 1 && nBitsPerPixel != 2 && nBitsPerPixel != 4 && nBitsPerPixel != 8 &&
nBitsPerPixel != 16 && nBitsPerPixel != 24)
{
dprintf("\n*** Error: The Specified file has an unknown bit format!");
return false;
}

pImgInf->size.x=nWidth;
pImgInf->size.y=nHeight;
pImgInf->pData=(color *)malloc(sizeof(color)*pImgInf->size.x*pImgInf->size.y);
if(!pImgInf->pData)
{
dprintf("\n*** Error: Alloc memory for image info failed!");
return false;
}
pCurrCol=pImgInf->pData;

pData=pBuf+*(uint32*)(pBuf+10);
if(nBitsPerPixel<=8)
pTbl=(ColorTbl*)(pBuf+nSizeBmpFileHeader+biSize);

nLineDataSize=nWidth*nBitsPerPixel/8;
nTmp=nLineDataSize%4;
if(nTmp)
nLineDataSize+=(4-nTmp);
for(nCurrY=0; nCurrY<nHeight; nCurrY++)
{
pDataCurr=pData+(nHeight-nCurrY-1)*nLineDataSize;
nSht=0;
nSrcColor=0;
for(nCurrX=0; nCurrX<nWidth; nCurrX++)
{
CurrColor&=0;