View Full Version : อยากทราบวิธีโหลดภาพแบบ png ครับ
ผมลองดูตัวอย่างอันหนึ่ง มันเป็นตัวอย่างเกี่ยวกับการโหลดภาพ gif แล้วเซฟเป็น bitmap(ตัวอย่างชื่อ bmpmanip) ผมลองเปลี่ยนแปลงโค้ดโดยให้โหลดภาพ png ขึ้นมา มันสามารถแสดงได้เหมือนภาพ gif แต่ผมไม่ทราบวิธีเอา transparent layer ของภาพแบบ png มา mask กับภาพของมันเองได้ ใครพอบอกวิธีเอา transparent layer ออกมาได้บ้างครับ
ฟังก์ชั่นที่ใช้คือ
ConvertL(CFbsBitmap& aBitmap,CFbsBitmap& aMaskBitmap,TInt aFrameNumber)
โดยปัญหาของผมคือ พารามิเตอร์ตัวที่สองครับ ไม่รู้ว่าจะเอา mask ที่มันเก็บอยู่ในภาพ png ออกมาได้ยังไง ใครทราบวิธี รบกวนช่วยบอกทีครับ ขอบคุณครับ
คือโดยปกติแล้วตัว Symbian SDK มี tool ในการสร้างภาพ mask ให้เป็น bitmap 1 bit ชื่อไรจำมะได้
หรือไม่ก็สร้าง mask เอง (CFbsBitmap)
แต่ถ้าให้เอามาจาก png อันนี้มะรู้
void Surface::CreateMask(DWord dwKey)
{
// Need to swap R&B
/*
dwKey = ((dwKey & 0xFF0000) >> 16) |
(dwKey & 0x00FF00) |
((dwKey & 0x0000FF) << 16);
*/
dwKey = ((( dwKey & 0x00F00000 ) >> 12) |
(( dwKey & 0x0000F000 ) >> 8) |
(( dwKey & 0x000000F0 ) >> 4));
delete m_hBitmapMasked;
m_hBitmapMasked = NBitmapMethods::CreateBitmapL(m_hBitmap->SizeInPixels(), EGray2);
Int lenSrc = CFbsBitmap::ScanLineLength(m_nWidth, EColor4K);
Int lenDst = CFbsBitmap::ScanLineLength(m_nWidth, EGray2);
HBufC8* pBufSrc = HBufC8::NewMaxLC(lenSrc);
HBufC8* pBufDst = HBufC8::NewMaxLC(lenDst);
int w = m_nWidth >> 3;
int r = m_nWidth & 7;
for (Int y = 0; y < m_nHeight; ++y)
{
Int mask, cr;
Int offset = 0;
m_hBitmap->GetScanLine(pBufSrc->Des(), TPoint(0, y), lenSrc, EColor4K);
for (Int x = 0; x < w; ++x)
{
mask = 0;
cr = (((pBufSrc->Des())[offset + 1]) << 8) | (((pBufSrc->Des())[offset + 0]));
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 0;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 1;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 2;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 3;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 4;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 5;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 6;
offset += 2;
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << 7;
offset += 2;
pBufDst->Des()[x] = (Byte) mask;
}
mask = 0;
for (Int i = 0; i < r; ++i)
{
if ((DWord)((pBufSrc->Des()[offset + 1] << 8) | (pBufSrc->Des()[offset + 0])) == dwKey)
mask |= 1 << i;
offset += 2;
pBufDst->Des()[x] = (Byte) mask;
}
m_hBitmapMasked->SetScanLine(pBufDst->Des(), y);
}
CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy();
}
ลองอ่านดูวิธีสร้าง mask เอง ไม่ยาก
ทำงี้ครับ
จาก Example นะ
TFrameInfo frameInfo;
iConverter->FrameInfo(KGifFrameIndex,frameInfo);
//จาก frameInfo จะมี flag บอกว่า frameนี้มี transparent หรือไม่ถ้ามี
//ก็ create CFbsBitmap มาเป็น mask bitmap ขนาดเท่ากับภาพ แล้วก็ส่งให้กับ iConvert->ConvertL(iBitmap, iMaskBitmap, frameIndex);
//ลองดูนะ
class TFrameInfo
{
public:
enum TFrameInfoFlags
{
EColor = 0x00000001, // Grayscale if not set
ETransparencyPossible = 0x00000002, // Fully opaque if not set
EFullyScaleable = 0x00000004, // Will only scale to 1/2,1/4 & 1/8th if not set
EConstantAspectRatio = 0x00000008, // Scaling need not maintain aspect ratio if not set
ECanDither = 0x00000010, // Will not use error diffusion if not set
EAlphaChannel = 0x00000020, // Set if the image contains alpha-blending information
ELeaveInPlace = 0x00000040, // }
ERestoreToBackground = 0x00000080, // } Mutually exclusive image disposal methods
ERestoreToPrevious = 0x00000100 // }
};
public:
TRect iFrameCoordsInPixels;
TSize iFrameSizeInTwips;
TInt iBitsPerPixel;
TTimeIntervalMicroSeconds iDelay;
TUint32 iFlags;
TSize iOverallSizeInPixels;
};
[code]
...
m_pConverter = CMdaImageFileToBitmapUtility::NewL(*this);
m_pConverter->OpenL(KGifFileName);
...
m_AllFrame = m_pConverter->FrameCount();
m_pBitmap = new CFbsBitmap[m_AllFrame];
m_pMask = new CFbsBitmap[m_AllFrame];
m_pInfo = new TFrameInfo[m_AllFrame];
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.