scale a bitmap

Login to reply to this topic.
Wed, 2004-07-07 12:52
Joined: 2003-10-27
Forum posts: 7
Hi,

I am trying to scale a bitmap to fit to screen, but the below code hangs at
User::WaitForRequest().
Any clues what I am doing wrong?

Ta,
Ash


// Bitmap zoomer
CBitmapScaler* iBitmapScaler;
iBitmapScaler = CBitmapScaler::NewL();

TRequestStatus iRequestStatus;
iBitmapScaler->Scale(&iRequestStatus, *iBitmap, TSize(176,208));    // fit
screen

// wait for the conversion to complete
 User::WaitForRequest(iRequestStatus);        /****  hangs here!!! */
// clean up
delete iBitmapScaler;

Ash


Wed, 2004-07-07 13:11
Joined: 2004-05-24
Forum posts: 981
Re: scale a bitmap
Are you sure  that Scale operation from CBitmapScaler is asynchronous?

You can use instead CMdaBitmapScaler::Scale() operation

Lucian

pirosl

Wed, 2004-07-07 13:38
Anonymous (not verified)
Forum posts: 2019
Re: scale a bitmap
The SDK says...

This class has been deprecated in 7.0s, it's functionality is now part of Bitmap Transform. For more information see CBitmapScaler.



Ash
Wed, 2004-07-07 16:01
Joined: 2003-10-27
Forum posts: 7
Re: scale a bitmap
Quote from: pirosl
Are you sure  that Scale operation from CBitmapScaler is asynchronous?

You can use instead CMdaBitmapScaler::Scale() operation

Lucian

Why is it that I can use  User::WaitForRequest(iConvStatus) when converting an image and not use the same when scaling an image. Both the methods are being part of my Container class, and both CImageDecoder and CBitmapScaler classes dont seem to inherit the CActive class.
 
TInt Error;
 CImageDecoder* iConverter = NULL;
 //initialise
 TRAPD(Error,iConverter = CImageDecoder::FileNewL(CEikonEnv::Static()->FsSession(),aImageFile,CImageDecoder::EOptionAlwaysThread));
 
if(Error == KErrNone)
 {
  //Get the frame info
  TFrameInfo frameInfo = iConverter->FrameInfo();
 
  // create a blank bitmap to copy the image into
  Err = iBitmap->Create(frameInfo.iOverallSizeInPixels,EColor4K);
 
  if(Err == KErrNone)
  {
 
   // Convert the image into a bitmap
   iConverter->Convert(&iConvStatus,*iBitmap);
   
   // wait for conversion to complete
   TRequestStatus iConvStatus;
   User::WaitForRequest(iConvStatus);
 
   // clean up
   iConverter->Cancel();
   delete iConverter;
}
}

Ash

Wed, 2004-07-07 18:53
Joined: 2004-05-24
Forum posts: 981
Re: scale a bitmap
Because the operation has to be asynchronous to use User::WaitForRequest(iConvStatus). That was my question: Are you sure that Scale operation from CBitmapScaler is asynchronous?
If not User::WaitForRequest(iConvStatus) will wait forever for smb to notify it's semaphore.

Lucian

pirosl

Thu, 2004-07-08 09:17
Joined: 2003-10-27
Forum posts: 7
Re: scale a bitmap
Thanks Lucian,

I was just trying to keep the code as simple as possible. But, I guess, theres no alternative to using CActive.

Ash

Sun, 2004-07-11 09:31
Joined: 2004-05-23
Forum posts: 114
scale a bitmap
Alternativly you can create empty bitmap, get bitmap adresses for new and old bitmaps and scale bitmap manually.

Mon, 2004-07-12 01:04
Anonymous (not verified)
Forum posts: 2019
Re: scale a bitmap
Hi,
maybe it will sound strange, but try to set the iRequestStatus to KRequestPending before invoking the scale operation. I had the same problem with the CMdaBitmapScaler and this solved it. Ever before I expected that the asynchronous method itself is responsible for this, but maybe there is a bug in it.

Best regards,

Jan Vorlicek

Quote from: Ash
Hi,

I am trying to scale a bitmap to fit to screen, but the below code hangs at
User::WaitForRequest().
Any clues what I am doing wrong?

Ta,
Ash


 // Bitmap zoomer
 CBitmapScaler* iBitmapScaler;
 iBitmapScaler = CBitmapScaler::NewL();

 TRequestStatus iRequestStatus;
 iBitmapScaler->Scale(&iRequestStatus, *iBitmap, TSize(176,208));    // fit
screen

 // wait for the conversion to complete
  User::WaitForRequest(iRequestStatus);        /****  hangs here!!! */
 // clean up
 delete iBitmapScaler;
Mon, 2004-07-12 06:07
Joined: 2004-05-20
Forum posts: 8
Re: scale a bitmap
Quote from: Ash
Thanks Lucian,

I was just trying to keep the code as simple as possible. But, I guess, theres no alternative to using CActive.

it looks like you want to perform Bitmap Scaling in Sync, since using User::WaitForRequest()

an alternative would be to use Appropriate DrawBitmap(...) method of CFbsBitGc
hope this helps  Evil

Experience is a good teacher..
Are you a good student ?

Mon, 2004-07-12 10:29
Anonymous (not verified)
Forum posts: 2019
Re: scale a bitmap
Thanks! I knew there was an easier way of doing it. Remember doing it a year back, but just could'nt remember how. Thanks again!

Ash
Sat, 2004-07-17 15:26
Joined: 2004-07-17
Forum posts: 110
Re: scale a bitmap
You can use DrawBitmap or CBitmapScaler to scale bitmaps. DrawBitmap is synchronous and CBitmapScaler is asynchronous.

Your code is single-threaded so you can't simply wait on a request (with only one thread running the request will never complete)

The CImageImageDecoder code works because you gave it the always thread option. The always thread option tells the image decoder to do the conversion in a seperate thread. Remove this option and, just like your scaler code, it won't work.

Use an active object and a callback function instead. (Use an M class for the callback)

Also don't use Always thread for image conversion unless you really have to - the decoding will require a higher system overhead and will probably take longer as a result.
Wed, 2007-09-19 12:12
Joined: 2007-09-12
Forum posts: 12
Re: scale a bitmap

DrawBitmap is a good idear!!
Thank you!

Mon, 2007-09-24 09:34
Joined: 2004-11-29
Forum posts: 1134
Re: scale a bitmap

Note though, that with CBitmapScaler you can scale with filtering, which will produce a much better end result then just a DrawBitmap call.

Tue, 2007-10-09 17:40
Joined: 2007-10-03
Forum posts: 5
Re: scale a bitmap

Hi,

I am also trying to scale a bitmap using the CBitmapScaler::Scale() method. However, i do not want to draw the result to the screen, or any device, I want the scaled data to be in the CFbsBitmap object which also holds the original unscaled data. So according to this, it seems that CFbsBitGc::DrawBitmap() will not work for me, and CBitmapScaler is the API I am interested in. (am I correct in assuming this?) Is it really necessary to implement this as an active object, or is there some way around this?? I am trying to keep my code as simple as possible, as it is nothing more than test code.

Wed, 2007-10-10 08:11
Joined: 2006-09-18
Forum posts: 68
Re: scale a bitmap

Hi I also used CBitmapScaler previously. Yes, if I remember correctly you need to use an Active Object, I also wanted to do it synchronously, so I employed CActiveSchedulerWait.

I found that CBitmapScaler was extremely slow. On EMediumQuality and after calling DisablePostProcessing(), It still took in the order of 3 seconds to scale, down from 7 seconds. OK it was large bitmaps 1280x1024, which I halved.

I then decided to halve the size using these articles, http://www.ddj.com/184405045 and www.compuphase.com/graphic/scale.htm

Of course if you want to keep it simple use CBitmapScaler::Scale() and an ActveObject.

O yes the time required to scale was something like 0.2 sec

Wed, 2007-10-10 08:30
Joined: 2006-09-18
Forum posts: 68
Re: scale a bitmap

I just realized you could use CFbsBitGc::DrawBitmap() to scale it, if you use CFbsBitmapDevice with CFbsBitmap.

CFbsBitmap *scaledBitmap = new (ELeave) CFbsBitmap();
scaledBitmap->Create(scaledRect,originalBitmap->DisplayMode());
CFbsBitmapDevice *bitmapDevice = CFbsBitmapDevice::NewL(scaledBitmap);
CleanupStack::PushL(bitmapDevice);
CFbsBitGc * bitmapGc = CFbsBitGc::NewL();
CleanupStack::PushL(bitmapGc);
bitmapGc->Activate(bitmapDevice);
bitmapGc->DrawBitmap(scaledRect,originalBitmap);

Cheers

  • Login to reply to this topic.