Error while copying bitmap (with pics)
| Thu, 2005-07-21 10:02 | |
|
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 |
|






Forum posts: 142
yucca
Forum posts: 93
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
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 :
Then I was so upset that I've tried, this method :
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 :
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
Forum posts: 26
In your earlier code, try something like this,
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.