×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    How to create a bmp file from a TDesC.

    Hi, all,

    Thank you!

    The problem, simply, how to create a bmp file from a TDes.

    The situation is:

    I get a base64 string from socket, and then I decode it to TDesC8, after I call RFile::Write to write it to a bmp file.
    The file size is OK, but I can not review the file as a bitmap file.

    So do some one know how to create a bmp file from a TDesC or it has some method form a base64 directly?

    and I find the thread at http://discussion.forum.nokia.com/fo...d.php?t=110509, but I do as the thread exactly. Thank you!

    Regards
    Bill Wang

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to create a bmp file from a TDesC.

    You first need to get the actual data buffer by reversing the base64 encoding, then you could use CImageDecoder:ataNewL.

    For more heklp, please check Wiki for any exmaples, as well as do try out the API, and then ask more specific questions on the problems you are encountering.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    1,236

    Re: How to create a bmp file from a TDesC.

    Hi,
    You could follow the link on how decode base64 to tdesc8 http://discussion.forum.nokia.com/fo...ad.php?t=56668
    Regards,
    Sriky

  4. #4
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    Re: How to create a bmp file from a TDesC.

    Thank you!

    Yes, I have get the TDes8 from base64, and I check the CImageDecoder, and also check the Wiki.

    Now the problem is that I new a CFbsBitmap pointer, but how to convert the TDes8 to a CFbsBitmap, then I can use CImageDecoder::Convert to convert to a bitmap. Does the step right? If the step is right, then can some one tell me how to convert the TDes8 to a CFbsBitmap? Thank you!

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to create a bmp file from a TDesC.

    you can use similar approach as is used with this exmaple: http://wiki.forum.nokia.com/index.ph...Symbian_bitmap

    Except that you use DataNewL, and only have one image without a mask.

  6. #6
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    Re: How to create a bmp file from a TDesC.

    I use the following code:
    void CJpgSaver::ConstructL(const TDesC8& aContent, const TDesC& aFileName)
    {
    CActiveScheduler::Add( this );
    iEncoder = CImageDecoder:ataNewL(CCoeEnv::Static()->FsSession(),aContent,KMimeType);


    iBitmap = new(ELeave)CFbsBitmap();
    iBitmap->Create(iEncoder->FrameInfo(0).iOverallSizeInPixels,iEncoder->FrameInfo(0).iFrameDisplayMode);

    iEncoder->Convert(&iStatus,*iBitmap,0);
    SetActive();
    SetActive();
    }

    but some confuse:
    this is convert the data to CFbsBitmap, but how to save the CFbsBitmap to a local bmp file?

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    1,236

    Re: How to create a bmp file from a TDesC.

    Hi,
    You could use CFbsBitmap::Save to save it as bmp file. Follow this link for doc http://www.symbian.com/developer/tec...a%3aSave%28%29
    Regards,
    Sriky

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to create a bmp file from a TDesC.

    CFbsBitmap::Save does not produce bmp file, it will save the image as mbm.. Very different format indeed, anyway, there is jpg saving example in the wiki, so you could change it to save on bmp format pretty easily.

    All and all, if the buffer is already having a bmp image data on it, you could use simple RFile API to save it to file, then you would not need to do any conversions whatsoever.

  9. #9
    Registered User
    Join Date
    Dec 2005
    Posts
    1,236

    Re: How to create a bmp file from a TDesC.

    Thanks for correcting me yucca
    Regards,
    Sriky

  10. #10
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    Re: How to create a bmp file from a TDesC.

    Quote Originally Posted by symbianyucca View Post
    CFbsBitmap::Save does not produce bmp file, it will save the image as mbm.. Very different format indeed, anyway, there is jpg saving example in the wiki, so you could change it to save on bmp format pretty easily.

    All and all, if the buffer is already having a bmp image data on it, you could use simple RFile API to save it to file, then you would not need to do any conversions whatsoever.
    And I use RFile write to a file, the file cannot be view as a bmp file

    and back to the problem, that

    _LIT8(KMimeType,"image/jpeg");

    iDecoder = CImageDecoder:ataNewL(fs,aContent,KMimeType);

    it has error that -1, the KMineType seems not right.

    So what's the right one?

    THank you!
    Regards
    Bill

  11. #11
    Registered User
    Join Date
    Jun 2006
    Location
    India
    Posts
    1,043

    Re: How to create a bmp file from a TDesC.

    Hi,
    If you have the data in the buffer then it can be written into the bmp file easily (as synbianyucca has mentioned). What is the error you are getting while opening the file and what is it showing?? If the buffer data is correct then writing in file will solve the issue directly.
    Maximus
    S60 Developer
    Impossible is nothing

  12. #12
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    Re: How to create a bmp file from a TDesC.

    Quote Originally Posted by yogpan View Post
    Hi,
    If you have the data in the buffer then it can be written into the bmp file easily (as synbianyucca has mentioned). What is the error you are getting while opening the file and what is it showing?? If the buffer data is correct then writing in file will solve the issue directly.
    Yes, I save the date directly, the file size is right that the same with the server, but it can not be view.

    But when I send to sever, I read directly from file use RFile::Read(), then just convert to base64, server can get it right, and I no need to en/decode on client.

    Thank you!

  13. #13
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: How to create a bmp file from a TDesC.

    i suggest you save the file in a public place in your device and then use any FileExplorer to open it. if it can't open you have a wrong format of image.

  14. #14
    Regular Contributor
    Join Date
    Jul 2007
    Posts
    57

    Re: How to create a bmp file from a TDesC.

    I post my code here, but the file cannot be review at all.


    // aSourceBuf, is from socket is the base64 data contained a bitmap file.
    HBufC8* TUtil::Base64DecodeL(const TDesC8 & aSourceBuf)
    {

    TImCodecB64 B64;
    HBufC8 * buffer = HBufC8::NewL(aSourceBuf.Length()*3/4);
    B64.Initialise();
    TPtr8 buffPtr = buffer->Des();
    B64.Decode(aSourceBuf, buffPtr);
    return buffer;
    }

    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    TFileName photoName;
    photoName.Copy(KImagePath);
    photoName.Append(_L("1Pet1.bmp"));

    RFile photo;
    TInt err = photo.Replace(fs, photoName, EFileWrite);

    // aMsg is from socket, it is base64 data, which is a bitmap file.
    HBufC8* content = TUtil::Base64DecodeL(aMsg);

    err = photo.Write( *content);
    photo.Close();
    CleanupStack::PopAndDestroy(1);
    // the photo file cannot review use file explore.

    Do any one knows the bugs?

    Thank you!

  15. #15
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: How to create a bmp file from a TDesC.

    You may consider trying to copy the decoded file to a PC, and check if it can be opened and/or compare it to the original.
    It is also a viable option to copy the original image file to the device in order to make sure that it can be openend.

Similar Threads

  1. Unable to create file
    By Ajmal in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2008-06-05, 04:39
  2. Error with makesis.exe and creating the .pkg file
    By gramya87 in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-10-10, 13:53
  3. Contacts fields order??
    By timatima in forum Symbian
    Replies: 1
    Last Post: 2007-06-08, 13:51
  4. problem in parsing xml file using syexpat
    By sunny_singh in forum Symbian
    Replies: 21
    Last Post: 2006-07-17, 11:56
  5. Can't create settings file and log file.
    By skhimsara in forum Symbian
    Replies: 1
    Last Post: 2006-05-08, 09:25

Posting Permissions

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