Results 1 to 6 of 6

Thread: อยากทราบวิธีโหลดภาพแบบ png ครับ

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    อยากทราบวิธีโหลดภาพแบบ png ครับ

    ผมลองดูตัวอย่างอันหนึ่ง มันเป็นตัวอย่างเกี่ยวกับการโหลดภาพ gif แล้วเซฟเป็น bitmap(ตัวอย่างชื่อ bmpmanip) ผมลองเปลี่ยนแปลงโค้ดโดยให้โหลดภาพ png ขึ้นมา มันสามารถแสดงได้เหมือนภาพ gif แต่ผมไม่ทราบวิธีเอา transparent layer ของภาพแบบ png มา mask กับภาพของมันเองได้ ใครพอบอกวิธีเอา transparent layer ออกมาได้บ้างครับ
    ฟังก์ชั่นที่ใช้คือ
    ConvertL(CFbsBitmap& aBitmap,CFbsBitmap& aMaskBitmap,TInt aFrameNumber)
    โดยปัญหาของผมคือ พารามิเตอร์ตัวที่สองครับ ไม่รู้ว่าจะเอา mask ที่มันเก็บอยู่ในภาพ png ออกมาได้ยังไง ใครทราบวิธี รบกวนช่วยบอกทีครับ ขอบคุณครับ

  2. #2
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: อยากทราบวิธีโหลดภาพแบบ png ครับ

    คือโดยปกติแล้วตัว Symbian SDK มี tool ในการสร้างภาพ mask ให้เป็น bitmap 1 bit ชื่อไรจำมะได้
    หรือไม่ก็สร้าง mask เอง (CFbsBitmap)
    แต่ถ้าให้เอามาจาก png อันนี้มะรู้

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: อยากทราบวิธีโหลดภาพแบบ png ครับ

    [src]
    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();
    }[/src]

    ลองอ่านดูวิธีสร้าง mask เอง ไม่ยาก

  4. #4
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: อยากทราบวิธีโหลดภาพแบบ png ครับ

    ทำงี้ครับ
    จาก Example นะ
    [src]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;
    };[/src]

  5. #5
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: อยากทราบวิธีโหลดภาพแบบ png ครับ

    [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];


  6. #6
    Junior Member
    Join Date
    Dec 2006
    Posts
    0


    Re: อยากทราบวิธีโหลดภาพแบบ png ครับ

    ขอบคุณมากครับ :-)

Similar Threads

  1. Replies: 1
    Last Post: 14-05-2009, 09:47 PM
  2. Replies: 2
    Last Post: 20-02-2009, 07:05 PM
  3. Replies: 0
    Last Post: 29-01-2008, 05:33 PM
  4. รวมรหัสอินเตอร์เน็ตฟรี ครับ
    By bombman in forum Computer Tip & Trick / Tutorial
    Replies: 5
    Last Post: 02-12-2006, 02:31 PM

Members who have read this thread : 0

Actions : (View-Readers)

There are no names to display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •