Reduce the image size but increase the file size

Login to reply to this topic.
Wed, 2007-10-24 04:34
Joined: 2004-09-23
Forum posts: 46

Hi
I use the CImageDecoder,CImageEncoder to reduce the image size. it can scale and save to file. but i found the file size is bigger then the original file. original file is 25k but the destination file is 230k. I have try different mode of "EColor256","EColor64K","EColor16M". The same file size i got. Need i use CBitmapScaler to scaler the *bitmap?

void ConvertImageL(const TDesC& aFilename,const TDesC& aDestname)
{
RFs fsSession;
User::LeaveIfError(fsSession.Connect());
CFbsBitmap* bitmap = NULL;
TRequestStatus requestStatus;
TRequestStatus encodeStatus;
if (!BaflUtils::FileExists(fsSession, aFilename))
{
fsSession.Close();
return ;
}

TFileName filename = aFilename;
filename.UpperCase();
TParse parser;
parser.Set(filename, NULL, NULL);

CImageDecoder* imageDecoder;
TRAPD(errorCode, imageDecoder = CImageDecoder::FileNewL(fsSession, filename, CImageDecoder::EOptionAlwaysThread));

const TFrameInfo& frameInfo = imageDecoder->FrameInfo();
TSize imageSize = frameInfo.iOverallSizeInPixels;
TSize aDesiredSize = TSize(176,208);
TInt hScaleFactor = imageSize.iWidth / aDesiredSize.iWidth;
TInt vScaleFactor = imageSize.iHeight / aDesiredSize.iHeight;

TUint scaleFactor = Min(hScaleFactor, vScaleFactor);
if (scaleFactor >= 4)
scaleFactor = 4;
else if (scaleFactor >= 2)
scaleFactor = 2;
else
scaleFactor = 1;

TUint hCorrection = 0;
if (imageSize.iWidth % scaleFactor)
hCorrection = 1;
TUint vCorrection = 0;
if (imageSize.iHeight % scaleFactor)
vCorrection = 1;
imageSize.SetSize(imageSize.iWidth / scaleFactor + hCorrection, imageSize.iHeight / scaleFactor + vCorrection);


if (errorCode == KErrNone)
{
CleanupStack::PushL(imageDecoder);

bitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(bitmap);
User::LeaveIfError(bitmap->Create(imageSize, EColor16M));

imageDecoder->Convert(&requestStatus, *bitmap);
User::WaitForRequest(requestStatus);

bitmap->Save(aDestname);
CImageEncoder* imageEncoder;
_LIT8(KMimeType,"image/jpeg");
TUid aImageType = TUid::Uid(0x101f45b0);
TUid aImageSubType = TUid::Uid(0x0);
imageEncoder = CImageEncoder::FileNewL(fsSession, aDestname,CImageEncoder::EOptionAlwaysThread , aImageType,aImageSubType);

CleanupStack::PushL(imageEncoder);
imageEncoder->Convert(&encodeStatus, *bitmap);
User::WaitForRequest(encodeStatus);
CleanupStack::PopAndDestroy(imageEncoder);
CleanupStack::PopAndDestroy(bitmap);
CleanupStack::PopAndDestroy(imageDecoder);
}

fsSession.Close();

return ;
}


Tue, 2007-10-30 06:38
Joined: 2004-09-23
Forum posts: 46
Re: Reduce the image size but increase the file size

Anybody help me?

  • Login to reply to this topic.