Error while copying bitmap (with pics)

Login to reply to this topic.
Thu, 2005-07-21 10:02
Joined: 2003-12-30
Forum posts: 93
Hello,

I'm facing a problem while trying to copy a bitmap to another.
In my Draw() Method I have this :

   CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap;
   iBitmap->Load(_L("C:\\nokia.mbm"),0); //-> perfectly displayed, so MBM is not corrupt

   CFbsBitmap* newBitmap = new(ELeave) CFbsBitmap();
   newBitmap->SetSizeInTwips(iBitmap->SizeInTwips());
   CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
   CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
   bitmapDevice->CreateContext(bitmapGc);
   bitmapGc->BitBlt(TPoint(0,0),newBitmap,TRect(newBitmap->SizeInPixels()));

   // WSERV 7 error
   gc.BitBlt(TPoint(0,0),newBitmap);

I'm pretty sure newBitmap is empty and I have no idea why. Could someone tell me how I could solve my problem, or to give me a tip how to copy a Bitmap to another ?
Thx a lot in advance,
MatD:-)

MatD


Thu, 2005-07-21 11:21
Joined: 2003-04-01
Forum posts: 142
Re: Error while copying bitmap
it looks quite dangerous to have such a lot of leaving code used in draw function. Anyway I think the problem is that you never construct the newBitmap, so the handle to it is bad.

yucca
Thu, 2005-07-21 23:17
Joined: 2003-12-30
Forum posts: 93
Re: Error while copying bitmap (with pics)
Hi,

Thx for your advice but unfortunately I still have problems. I left this first "method" to do a pixel to

pixel copy, but unfortunaly , still have problem ( the copied bitmap is incorrect).

First version :

      
   // I want to copy originalBitmap (correctly loaded) to iBitmap      

Code:
iBitmap = new (ELeave) CFbsBitmap();
TSize inSize = iOriginalBitmapSize;
User::LeaveIfError(iBitmap->Create(iOriginalBitmapSize, EColor16M)); // Display Mode is correct !

                // create the bitmap utils
TBitmapUtil bitmap1Util(iOriginalBitmap);
TBitmapUtil bitmap4Util(iBitmap);

                // 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);
TInt xPos;
for (TInt yPos=0;yPos<iOriginalBitmapSize.iHeight;yPos++)
{
bitmap1Util.SetPos(TPoint(0,yPos));
bitmap4Util.SetPos(TPoint(yPos,0));
for (xPos=0;xPos<iOriginalBitmapSize.iWidth;xPos++)
{
bitmap4Util.SetPixel(bitmap1Util);
bitmap1Util.IncXPos();
bitmap4Util.IncYPos();
                }

]
bitmap1Util.End();
bitmap4Util.End();

Result: lots of green and red dots and partial but very indistinguable parts

Original : -> Result :



Then I was so upset that I've tried, this method :

   
Code:
// Copies the content of the iOriginalBitmap into the iBitmap
delete iBitmap;
iBitmap = new(ELeave) CFbsBitmap();
TSize bmpSize = iOriginalBitmap->SizeInPixels();
iBitmap->Create(bmpSize, EColor16M );
                int scanLineLength = CFbsBitmap::ScanLineLength( bmpSize.iWidth, EColor16M);
    if (iBitmap && iBitmap->DataAddress() )
{
memcpy( (void*)iBitmap->DataAddress(), (void*) iOriginalBitmap->DataAddress(),
                scanLineLength * bmpSize.iHeight);
}

Here is the sad result :

Original : -> Result :


The bottom part is A picture that should be loaded in memory, but shouldn't appear. Seems as if the address of this second picture interfers with the first one. But why ?   
You may ask why I'm trying to copy a bitmap. It's because if you zoom In and out with the iBitmapScaler you're loosing quality and the picture is blurring. So a copy can ben used to used to avoid this.
If someone could really help me with this problem, I would be very very grateful !
Thx a lot in advance

MatD

Fri, 2005-07-22 07:55
Joined: 2005-06-10
Forum posts: 26
Re: Error while copying bitmap (with pics)
Hi,

In your earlier code, try something like this,

Quote
CFbsBitmap* iBitmap = new (ELeave) CFbsBitmap;
iBitmap->Load(_L("C:\\nokia.mbm"),0);

CFbsBitmap* newBitmap = new(ELeave) CFbsBitmap();
//create the bitmap with the same asize and display mode as the source
newBitmap->Create( iBitmap->SizeInPixels(), iBitmap->DisplayMode() );

//get the GC of this new bitmap
CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(newBitmap);
CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
bitmapDevice->CreateContext(bitmapGc);

//the copy happens here
bitmapGc->BitBlt( TPoint(0,0), iBitmap, TRect(iBitmap->SizeInPixels()) );

//now draw it to screen
gc.BitBlt(TPoint(0,0),newBitmap);

However, i agree with yucca on this being dangerous in the Draw() method, so do handle the leaves correctly.

Regards,
MoS.
  • Login to reply to this topic.