//可純貼圖並可橫向縱向切分的貼圖函數,就是可橫向縱向平均分割一個圖像並選定其中之一進行貼圖,分割數要可整除圖像寬度,通過調用時是否傳遞切分參數來控制是否進行切分
void DrawBmp(const TPoint& aPoint, CFbsBitmap* srcBitmap, CFbsBitmap* aBitmap, TInt aSplitColNum=1, TInt aSplitColIndex=0, TInt aSplitRowNum=1, TInt aSplitRowIndex=0 )
{
DrawBmp( aPoint, srcBitmap , aBitmap, TRect(aBitmap->SizeInPixels()), FALSE, TRgb(0,0,0), aSplitColNum, aSplitColIndex, aSplitRowNum, aSplitRowIndex );
}
//帶透明遮罩色並可橫向縱向切分的貼圖函數,就是目標圖中和aMaskColor顏色相同的透明,使用可以正確轉爲4k色的Rgb色如0xff00ff轉爲0xf0f,通過調用時是否傳遞切分參數來控制是否進行切分
void DrawBmp(const TPoint& aPoint, CFbsBitmap* srcBitmap, CFbsBitmap* aBitmap, TRgb aMaskColor, TInt aSplitColNum=1, TInt aSplitColIndex=0, TInt aSplitRowNum=1, TInt aSplitRowIndex=0 )
{
DrawBmp( aPoint, srcBitmap , aBitmap, TRect(aBitmap->SizeInPixels()), TRUE, aMaskColor, aSplitColNum, aSplitColIndex, aSplitRowNum, aSplitRowIndex );
}
//目標圖有選定區域且可橫向縱向切分的貼圖函數,通過調用時是否傳遞切分參數來控制是否進行切分
void DrawBmp(const TPoint& aPoint, CFbsBitmap* srcBitmap, CFbsBitmap* aBitmap, const TRect& aRect, TInt aSplitColNum=1, TInt aSplitColIndex=0, TInt aSplitRowNum=1, TInt aSplitRowIndex=0 )
{
DrawBmp( aPoint, srcBitmap , aBitmap, aRect, FALSE, TRgb(0,0,0), aSplitColNum, aSplitColIndex, aSplitRowNum, aSplitRowIndex );
}
//目標圖有選定區域並帶透明遮罩色且可橫向縱向切分的貼圖函數,通過調用時是否傳遞切分參數來控制是否進行切分
void DrawBmp(const TPoint& aPoint, CFbsBitmap* srcBitmap, CFbsBitmap* aBitmap, const TRect& aRect, TRgb aMaskColor, TInt aSplitColNum=1, TInt aSplitColIndex=0, TInt aSplitRowNum=1, TInt aSplitRowIndex=0 )
{
DrawBmp( aPoint, srcBitmap , aBitmap, aRect, TRUE, aMaskColor, aSplitColNum, aSplitColIndex, aSplitRowNum, aSplitRowIndex );
}
//完整貼圖函數
void DrawBmp(const TPoint& aPoint, CFbsBitmap* srcBitmap , CFbsBitmap* aBitmap, const TRect& aRect, TBool aMask , const TRgb& aMaskColor, TInt aSplitColNum=1, TInt aSplitColIndex=0, TInt aSplitRowNum=1, TInt aSplitRowIndex=0 )
{
// 鎖定
TBitmapUtil bmpUtil1(srcBitmap);
TBitmapUtil bmpUtil2(aBitmap);
bmpUtil1.Begin(TPoint(0,0));
bmpUtil2.Begin(TPoint(0,0), bmpUtil1);
//當橫向和縱向的索引值在分割數的範圍內才進行貼圖
if( aSplitColNum>0 && aSplitColNum>aSplitColIndex && aSplitColIndex>=0 && aSplitRowNum>0 && aSplitRowNum>aSplitRowIndex && aSplitRowIndex>=0 )
{
TInt width1 = srcBitmap->SizeInPixels().iWidth; //獲得源圖寬度
TInt height1 = srcBitmap->SizeInPixels().iHeight; //獲得源圖高度
TInt width2 = aBitmap->SizeInPixels().iWidth; //獲得目標圖寬度
TInt height2 = aBitmap->SizeInPixels().iHeight; //獲得目標圖高度
//選定區域對目標圖有效時才進行貼圖
if(aRect.iBr.iX>0 && aRect.iTl.iX<=width2 && aRect.iBr.iY>0 && aRect.iTl.iY<=height2 )
{
TInt rectfromx = aRect.iTl.iX<0?0:aRect.iTl.iX; //目標圖實際選中區起始X座標
TInt rectfromy = aRect.iTl.iY<0?0:aRect.iTl.iY; //目標圖實際選中區起始Y座標
TInt rectcutw = aRect.iBr.iX>width2?aRect.iBr.iX-width2:0; //目標圖選中區右邊被裁寬度
TInt rectcuth = aRect.iBr.iY>height2?aRect.iBr.iY-height2:0; //目標圖選中區下邊被裁高度
TInt width2s=(aRect.iBr.iX-rectfromx-rectcutw)/aSplitColNum; //獲得目標圖有效選中區寬度
TInt height2s=(aRect.iBr.iY-rectfromy-rectcuth)/aSplitRowNum; //獲得目標圖有效選中區高度
//目標圖有效選中區貼在源圖有效區內才進行貼圖
if( aPoint.iX+width2s>0 && aPoint.iX<=width1 && aPoint.iY+height2s>0 && aPoint.iY<=height1 )
{
TInt line1 = CFbsBitmap::ScanLineLength(width1, EColor4K) / 2; //獲得源圖行長度
TInt line2 = CFbsBitmap::ScanLineLength(width2, EColor4K) / 2; //獲得目標圖行長度
TInt rectx = aPoint.iX<0?0:aPoint.iX; //源圖起始X座標
TInt recty = aPoint.iY<0?0:aPoint.iY; //源圖起始Y座標
TInt fromx = aPoint.iX<0?rectfromx+aSplitColIndex*width2s-aPoint.iX:rectfromx+aSplitColIndex*width2s; //目標圖起始X座標
TInt fromy = aPoint.iY<0?rectfromy+aSplitRowIndex*height2s-aPoint.iY:rectfromy+aSplitRowIndex*height2s; //目標圖起始Y座標
TInt cutw = aPoint.iX+width2s>width1?aPoint.iX+width2s-width1:0; //目標圖右邊被裁寬度
TInt cuth = aPoint.iY+height2s>height1?aPoint.iY+height2s-height1:0; //目標圖下邊被裁高度
TInt rectw = rectfromx + width2s * (1 + aSplitColIndex) - fromx - cutw; //目標圖被貼寬度
TInt recth = rectfromy + height2s * (1 + aSplitRowIndex) - fromy - cuth; //目標圖被貼高度
TInt jump1 = line1 - rectw; //獲得源圖地址掃描跳躍量
TInt jump2 = line2 - rectw ; //獲得目標圖地址掃描跳躍量
// 獲取首地址
TUint16* addr1 = (TUint16*)srcBitmap->DataAddress();
TUint16* addr2 = (TUint16*)aBitmap->DataAddress();
// 獲取貼圖首地址
TUint16* p1 = addr1 + recty*line1 + rectx;
TUint16* p2 = addr2 + fromy*line2 + fromx;
// 獲取貼圖末地址
TUint16* p2end = p2 + line2* (recth - 1) + rectw;
//是否進行透明遮罩
if(aMask)
{
//轉換RGB色爲TUint16表示的4K色
TInt maskcolor=aMaskColor.Color4K();
while( p2 < p2end)
{
TUint16* p2endline = p2 + rectw;
while(p2!=p2endline)
{
if( *p2!=maskcolor)
{
*p1 = *p2;
}
p1++;
p2++;
}
p1+=jump1;
p2+=jump2;
}
}
else
{
while( p2 < p2end)
{
TUint16* p2endline = p2 + rectw;
while(p2!=p2endline)
{
*p1 = *p2;
p1++;
p2++;
}
p1+=jump1;
p2+=jump2;
}
}
}
}
}
// 解鎖
bmpUtil2.End();
bmpUtil1.End();
}
參數說明
const TPoint& aPoint 貼圖相對與源圖的左上角起始座標
CFbsBitmap* srcBitmap 源圖指針
CFbsBitmap* aBitmap 目標圖指針
const TRect& aRect 目標圖選定區域
TBool aMask 是否有透明遮罩
const TRgb& aMaskColor 透明遮罩色
TInt aSplitColNum=1 橫向切分總數,默認爲1,即不切分
TInt aSplitColIndex=0 橫向切分索引,默認爲0,即橫向切分序列中的第一個
TInt aSplitRowNum=1 縱向切分總數,默認爲1,即不切分
TInt aSplitRowIndex=0 縱向切分索引,默認爲0,即縱向切分序列中的第一個
自己用着還可以,還未發現錯誤,不知道有無可精簡修改之處。如果有人試用可提出意見。
比較繁瑣的就是計算源圖和目標圖座標的部分,有待優化。
爲了減少函數重載的數量設置了切分參數的默認值,不知是否可以進一步減少
另外在橫向和縱向分割圖像的部分當目標圖存在選定區域時爲選定有效區域的分割,不知道這種應用較多還是選定區域應該爲整個圖像分割後選中的部分的有效選定區域?我覺的現在的這種應用較多,這樣就可以把多個圖像序列整合到一個位圖裏。