×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94

    Reduce the image size but increase the file size

    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 ;
    }

  2. #2
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    94

    Re: Reduce the image size but increase the file size

    Can anyone tell me why?

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Reduce the image size but increase the file size

    You have not provided the "CFrameImageData *aFrameImageData=NULL" argument, thus the encoder uses best quality. CFrameImageData contains TImageDataBlock-s, for example a TJpegImageData. And TJpegImageData has an iQualityFactor. Try something like 70-80 (%).

Similar Threads

  1. reading image file from server ??
    By nitrajpal in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2006-01-30, 07:50
  2. Replies: 1
    Last Post: 2005-05-26, 14:22
  3. Loading Image data from 'raw' bytes
    By LongSteve in forum Mobile Java General
    Replies: 2
    Last Post: 2002-11-20, 17:38
  4. Replies: 0
    Last Post: 2002-06-10, 12:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×