scale a bitmap
| Wed, 2004-07-07 12:52 | |
|
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 |
|






Forum posts: 981
You can use instead CMdaBitmapScaler::Scale() operation
Lucian
pirosl
This class has been deprecated in 7.0s, it's functionality is now part of Bitmap Transform. For more information see CBitmapScaler.
Ash
Forum posts: 7
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
Forum posts: 981
If not User::WaitForRequest(iConvStatus) will wait forever for smb to notify it's semaphore.
Lucian
pirosl
Forum posts: 7
I was just trying to keep the code as simple as possible. But, I guess, theres no alternative to using CActive.
Ash
Forum posts: 114
CellaGameS.com
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
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;
Forum posts: 8
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
Experience is a good teacher..
Are you a good student ?
Ash
Forum posts: 110
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.
Forum posts: 12
DrawBitmap is a good idear!!
Thank you!
Forum posts: 1134
Note though, that with CBitmapScaler you can scale with filtering, which will produce a much better end result then just a DrawBitmap call.
Forum posts: 5
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.
Forum posts: 68
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
Forum posts: 68
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