Hi,
I would like to create an image (not from a png file or mbm) with alpha blending enabled.
To do that I would like to use BitBltMasked as the rendering method.
To do so, I build an image from an UInt8 array which contains the color data and then another one, the mask, with alpha value for blending (so with format EGray256).
In a previous post I succeeded to do so with a png file (the two CFbsBitmaps being created by CImageDecoder::FileNew() and a parameter which tells the method to create a mask).
But here I'd like to to it "manually".
Okay I have more code for color image, but this one is already not working.Code:// copying the buffer into bitmap const TInt KSizeWidth = 30; const TInt KSizeHeight = 30; TSize bitmapSize(KSizeWidth, KSizeHeight); //build alpha array TUint8 alphaArray [(KSizeWidth) * (KSizeHeight)]; for(int k = 0; k < KSizeWidth; k++){ for(int l = 0; l < KSizeHeight; l++){ if(k<KSizeWidth/2 && l<KSizeHeight/2){ alphaArray[(k + l * (KSizeWidth))] = 200; }else if(k>KSizeWidth/2 && l<KSizeHeight/2){ alphaArray[(k + l * (KSizeWidth))] = 100; }else if(k<KSizeWidth/2 && l>KSizeHeight/2){ alphaArray[(k + l * (KSizeWidth))] = 50; }else if(k>KSizeWidth/2 && l>KSizeHeight/2){ alphaArray[(k + l * (KSizeWidth))] = 255; } } } //put array in descriptor (-> why +1?? -> other wise it crashes, I don't know why, user panic 23, as if it was not declared big enough) HBufC8 * tmpBuf = HBufC8::NewMaxL((KSizeWidth) * (KSizeHeight) +1 ); tmpBuf->operator =(alphaArray); CFbsBitmap * iBitmapMask = new (ELeave) CFbsBitmap; iBitmapMask->Create(bitmapSize, EGray256 ); iBitmapMask->LockHeap(ETrue); Mem::Copy(iBitmapMask->DataAddress(), tmpBuf, tmpBuf->Length() -1 ); iBitmapMask->UnlockHeap(ETrue); delete tmpBuf;
So let's say I want to call BitBltMasked() with this bitmap for image and mask.
I should see a semi transparent 30x30 square, with 4 quarters having different tone.
What I see is a 30x30 square indeed, but the first 4 pixels (on the first line) are not set (as if iBitmapMask->DataAddress() didn't return a correct value... actually, I've tried to Mem::copy(iBitmapMask->DataAddress() - 1... and it worked ... But I don't know why, and it does not seem like something I should do)
I also miss about 64 pixels at the end (they're white), as if there was not enough data in the array to fill the bitmap.
And the 4 quarters are not correctly rendered, all lines seems shifted as if there was a pb with the TDisplayMode format...
I really don't understand what I see , I believe this code should work (even without the +/-1 stuff), because I'm so close to getting what i'm expecting, there just a glitch in the rendering...
And for the colored version, If I use the 32 bpp format EColor16MA I see the shape I draw alright, but with the true color 24 bpp format EColor16M, there the same pb of rendering, each line is shifted by one or two pixels, which deforms the image.
(I'd rather like to use EColor16M, because with the second bitmap with alpha infos, using EColor16MA would be redondant, and increase memory footprint. But If it is the only one that's working, I'll take it ! ^^)
Here's the code of the color array (EColor16MA version, for EColor16M, I only give 3 colors, and replace every 4 by 3 int the following code)
Sorry for the huge message but I would like to be as precise as possible.Code:TUint8 rgbArray [KSizeWidth * KSizeHeight * 4]; for(int i = 0; i < KSizeWidth *4 ; i+=4){ for(int j = 0; j < KSizeHeight ; j++){ if(i<(KSizeWidth *4)/2 && j < KSizeHeight/2){ rgbArray[(i + j * KSizeWidth*4) + 0] = 200; rgbArray[(i + j * KSizeWidth*4) + 1] = 20; rgbArray[(i + j * KSizeWidth*4) + 2] = 20; rgbArray[(i + j * KSizeWidth*4) + 3] = 20; }else if(i>(KSizeWidth *4)/2 && j < KSizeHeight/2){ rgbArray[(i + j * KSizeWidth*4) + 0] = 20; rgbArray[(i + j * KSizeWidth*4) + 1] = 200; rgbArray[(i + j * KSizeWidth*4) + 2] = 20; rgbArray[(i + j * KSizeWidth*4) + 3] = 20; }else if(i<(KSizeWidth *4)/2 && j > KSizeHeight/2){ rgbArray[(i + j * KSizeWidth*4) + 0] = 20; rgbArray[(i + j * KSizeWidth*4) + 1] = 20; rgbArray[(i + j * KSizeWidth*4) + 2] = 200; rgbArray[(i + j * KSizeWidth*4) + 3] = 20; }else if(i>(KSizeWidth *4)/2 && j > KSizeHeight/2){ rgbArray[(i + j * KSizeWidth*4) + 0] = 20; rgbArray[(i + j * KSizeWidth*4) + 1] = 200; rgbArray[(i + j * KSizeWidth*4) + 2] = 200; rgbArray[(i + j * KSizeWidth*4) + 3] = 20; } } }
Furthermore, I'd like someone to try this code to see if it gets the same result as I do, or tell me if there is something obviously wrong with it...
Thanks a lot!

...


