copying bitmap
Login to reply to this topic.
Fri, 2008-10-31 13:29
Joined: 2007-05-15
Forum posts: 138

How to copy a bitmap?
suppose 2 bitmap pointers are there.
CFbsbitmap* bitmap1;
CFbsbitmap* bitmap2;

if I use
bitmap2=bitmap1;

it copies the address of bitmap object pointed to by bitmap1 into bitmap2

I need bitmap2 should point to a different bitmap , where this one is a copy of previous one.

Regards!


Fri, 2008-10-31 13:51
Joined: 2008-01-16
Forum posts: 231

Hi Sandeepmhptr,

Checkout this:-http://www.newlc.com/topic-3539
hopefully you will solve your problem.


Thanks & Regards,
Md.Khalid Ahmad

Fri, 2008-10-31 13:53
Joined: 2008-01-16
Forum posts: 231

you can also do it like this:-

void CMyBitMapClass::CopyFbsBitmapL(CFbsBitmap * orig, CFbsBitmap * dest)
{
TSize s = orig->SizeInPixels();
User::LeaveIfError(dest->Create(s, orig->DisplayMode()));

TBitmapUtil orig_util(orig);
TBitmapUtil dest_util(dest);
orig_util.Begin(TPoint(0,0));
dest_util.Begin(TPoint(0,0), orig_util);

TInt xPos;
for (TInt yPos=0;yPos {
orig_util.SetPos(TPoint(0,yPos));
dest_util.SetPos(TPoint(0,yPos));
for (xPos=0;xPos {
dest_util.SetPixel(orig_util);
orig_util.IncXPos();
dest_util.IncXPos();
}
}
orig_util.End();
dest_util.End();
}

Smiling


Thanks & Regards,
Md.Khalid Ahmad

Fri, 2008-10-31 14:04
Joined: 2007-05-15
Forum posts: 138

hi khalid,
I think some text is missing............... in the two for loops

I think you have used "<" symbol in for loop

type "< " instead.
include a space after the symbol.
else this site does not display anything in the line that follows "<" symbol

Regards!

Fri, 2008-10-31 14:08
Joined: 2008-02-13
Forum posts: 11

Why u need that ?

see SDK Help:--
CFbsBitmap instances cannot be shared between different threads. They use some shared thread local storage data. If you want to share a bitmap between threads, use Duplicate().

Sun, 2008-11-02 11:08
Joined: 2008-01-16
Forum posts: 231

Hi sandeepmhptr,

Thanks for advice.I will take care next time onwards.
I hope this might helped you?
Again pasting code below:-
void CMyBitMapClass::CopyFbsBitmapL(CFbsBitmap * orig, CFbsBitmap * dest)
{
TSize s = orig->SizeInPixels();
User::LeaveIfError(dest->Create(s, orig->DisplayMode()));

TBitmapUtil orig_util(orig);
TBitmapUtil dest_util(dest);
orig_util.Begin(TPoint(0,0));
dest_util.Begin(TPoint(0,0), orig_util);

TInt xPos;
for (TInt yPos=0;yPos"<"s.iHeight;yPos++)
{
orig_util.SetPos(TPoint(0,yPos));
dest_util.SetPos(TPoint(0,yPos));
for (xPos=0;xPos {
dest_util.SetPixel(orig_util);
orig_util.IncXPos();
dest_util.IncXPos();
}
}
orig_util.End();
dest_util.End();
}


Thanks & Regards,
Md.Khalid Ahmad

Mon, 2008-11-03 04:52
Joined: 2007-05-15
Forum posts: 138

is there any way to find each row and column of the bitmap also..................????????????

Mon, 2008-11-03 09:52
Joined: 2004-11-29
Forum posts: 1419

The above posted code, whilst perfectly correct, it is an extremely slow and roundabout way of copying a bitmap.

If you want an exact copy in a new bitmap (same color format etc) you should use Mem::Copy.

I'd expect it to be somewhere between 10x to 100x as fast:


CFbsBitmap* dstbmp = new (ELeave) CFbsBitmap();
if(KErrNone == dstbmp->Create(aSourceBmp->SizeInPixels(), aSourceBitmap->DisplayMode()))
{
aSourceBmp->LockHeap();

TInt length = aSourceBmp->SizeInPixels().iHeight * aSourceBitmap->DataStride();

Mem::Copy( dstbmp->DataAddress(),  aSourceBmp->DataAddress(),  length);

aSourceBmp->UnlockHeap();
}

Wed, 2009-08-12 14:53
Joined: 2005-11-07
Forum posts: 4

Use as

TInt scanlinelenght = iIconBitmap->ScanLineLength(imgWidth,iIconBitmap->DisplayMode());
TInt iBufLength = imgHeight * scanlinelenght;
Mem::Copy(iNewIconBitmap->DataAddress(),iIconBitmap->DataAddress(),iBufLength);

it works Smiling

Mon, 2008-11-03 10:43
Joined: 2005-11-20
Forum posts: 1321

Is this use of Mem::Copy the "official" way to do it?

I mean, it works alright, but doesn't this fly in the face of all good object-oriented and abstraction-based programming?

I was surprised anyway to see no method that directly copies a bitmap in the desired way.


René Brunner

Mon, 2008-11-03 12:21
Joined: 2004-11-29
Forum posts: 1419

official enough Smiling

Its just a bit low-level, nothing really that weird, it does not depend on any undocumented features or anything, and it does it as efficiently as the current available API:s allow you to, and it takes all precautions needed.

Even in an object oriented language you will have to move memory around sometimes, but sure, the "OOP way" would be to overload operator=() or something, and allow you to do:

*dstbmp = *srcbmp;

...or something...

But I think they chose to not include a function like that, to avoid that less avid programmers copy their bitmaps unnecessarily, when they could have used Duplicate() instead and saved a lot of memory.

Its not really that often you have to copy bitmaps...

And you can also achieve it by using CFbsBitGc, CFbsBitmapDevice and BitBlt (this also a lot faster then the TBitmapUtil way)


copyright 2003-2009 NewLC SARL