This topic provides example code that shows how to use the pixel manipulation functions in TBitmapUtil
. In this example they are used to create a bitmap that is a rotated version of an existing bitmap.
/* create a new bitmap (iBitmap4), with the same size as an existing bitmap (iBitmap1), but with the height and width swapped */ iBitmap4 = new (ELeave) CFbsBitmap(); TSize inSize = iBitmap1->SizeInPixels(); User::LeaveIfError(iBitmap4->Create(TSize(inSize.iHeight,inSize.iWidth), iBitmap1->DisplayMode()); // create the bitmap utils TBitmapUtil bitmap1Util(iBitmap1); TBitmapUtil bitmap4Util(iBitmap4); // Begin manipulation with bitmap1Util, setting initial pixel to 0,0 bitmap1Util.Begin(TPoint(0,0)); // Begin manipulation with bitmap4Util, setting initial pixel to 0,0 bitmap4Util.Begin(TPoint(0,0),bitmap1Util); // set the bits of iBitmap4 as iBitmap1, rotated through 90 degrees TInt xPos; for (TInt yPos=0;yPos<inSize.iHeight;yPos++) { bitmap1Util.SetPos(TPoint(0,yPos)); bitmap4Util.SetPos(TPoint(yPos,0)); for (xPos=0;xPos<inSize.iWidth;xPos++) { bitmap4Util.SetPixel(bitmap1Util); bitmap1Util.IncXPos(); bitmap4Util.IncYPos(); } } // each Begin() must have a corresponding End() bitmap1Util.End(); bitmap4Util.End();
Notes
Begin()
and End()
calls must surround the other TBitmapUtil
function calls. They tell the Font and Bitmap Server when to lock (that is, not to attempt to compress) the heap where bitmaps are stored, while operations are in progress.
The second call to Begin()
specifies that the heap has already been locked by bitmap1Util
.