Image data into HBufC8*

Login to reply to this topic.
Wed, 2007-04-04 12:31
Joined: 2007-04-04
Forum posts: 5
Greetings,

I have tried to read jpg file data into HBufC8* without success. In Forum Nokia I have tried to get help for my problem in this thread:

http://discussion.forum.nokia.com/forum/showthread.php?p=297058#post297058

Basically my problem is that CImageEncoder's Convert() method adds only four first characters in HBufC8* just like it did with RFile by doing like this:

Code:
RFile infile;
TInt val=infile.Open(fs,path,EFileShareExclusive|EFileRead);
TBuf8<256> data8;
infile.Read(data8, 256);

data8 includes "ÿØÿá" string

JPG file start like this, if I open file with notepad:

Code:
ÿØÿáXExif  II*         n       N73

I did like this to have a bitmap data into HBufC8*:

Code:
iImageEncoder=CImageEncoder::DataNewL(iBuffer, _L8("image/jpeg"), CImageEncoder::EOptionNone);

iState=EEncoding;

iImageEncoder->Convert(&iStatus,*iBitmap);
    SetActive(); 

iBuffer includes "ÿØÿá" string.

Any ideas what is the problem?
Regards,
Arachidyl

Wed, 2007-04-04 12:50
Joined: 2005-06-04
Forum posts: 131
Re: Image data into HBufC8*
Try this

HBufC8* data = HBufC8::NewL(<filesize>);
TPtr8 dataptr = data->Des();
infile.Read(dataptr,<filesize>);

You can reach data with data->Ptr() /TUint8*/

Ro0p
Wed, 2007-04-04 13:28
Joined: 2007-04-04
Forum posts: 5
Re: Image data into HBufC8*
I did like this:

Code:
RFs fs;
User::LeaveIfError(fs.Connect());

RFile infile;

TInt val=infile.Open(fs,path,EFileStream|EFileRead);
if(val==KErrNone)
{
TInt file_size;
infile.Size(file_size); // file_size =~137000

HBufC8* bufImageData;
bufImageData = HBufC8::NewL(file_size);

TPtr8 ptr_bufImageData=bufImageData->Des();

infile.Read(ptr_bufImageData, file_size); // bufImageData = ÿØÿáXExif

const TUint8* temp = ptr_bufImageData.Ptr(); // temp = 610412724

Now it reads 10 characters but that isn't enough. What should I do for const TUint8* temp variable?

- Arachidyl
Wed, 2007-04-04 13:53
Joined: 2005-06-04
Forum posts: 131
Re: Image data into HBufC8*
I think you use wrong class.
From SDK help:

Class CImageEncoder
"This class provides functions that convert image data held in CFbsBitmap objects into well know formats and store the results in either files of descriptors."

You need Decoder.
Class CImageDecoder
"This class provides functions to decode images held in files or descriptors. To decode buffered images use the buffered version of this class CBufferedImageDecoder."
Wed, 2007-04-04 14:34
Joined: 2007-04-04
Forum posts: 5
Re: Image data into HBufC8*
How can I get image data into HBufC8 with CImageDecoder? Is it possible?

I have used CImageDecoder for having jpg image in bitmap:

Code:

    iBuffer = aBuffer;
   
    delete iImageDecoder;
    iImageDecoder = NULL;
    delete iBitmap;
    iBitmap = NULL;

    // create the decoder
    iImageDecoder = CImageDecoder::FileNewL( iFs, aFileName );
               
    // create the destination bitmap
    iBitmap = new (ELeave) CFbsBitmap();

    iBitmap->Create( iImageDecoder->FrameInfo().iOverallSizeInPixels,
                     iImageDecoder->FrameInfo().iFrameDisplayMode ); ;
    // start conversion to bitmap
    iState = EDecoding;
    iImageDecoder->Convert( &iStatus, *iBitmap );
    SetActive();
Thu, 2007-04-05 11:27
Joined: 2007-04-04
Forum posts: 5
Re: Image data into HBufC8*
I got it working. It was my fault not code fault. Image data was always been in HBufC8* but carbide debugger just show me first characters not whole string.

Both solutions DataNewL and RFile should work.
  • Login to reply to this topic.