Languages

Menu
Sites
Language
CreateContent from ByteBuffer - how?

Hi There,

Running the following code works:

  _file_1.Construct( filename_1_jpg );
  _file_1.Read(myByteBuffer);

  _file_2.Construct( filename_2_jpg , "w+"));
  _file_2.write(myByteBuffer);

  contentId = contentManager.CreateContent( filename_2_jpg , outFileName, true, 0);

But if I want to create the content from the bytebuffer, it fails:

  _file_1.Construct( filename_1_jpg );
  _file_1.Read(myByteBuffer);

  contentId = contentManager.CreateContent(myByteBuffer, outFileName, 0);

> [E_INVALID_ARG] byteBuffer is invalid.
> [E_INVALID_ARG] CreateContent failed.

Ok, maybe I have to decode the raw file data:

  _file_1.Construct( filename_1_jpg );
  _file_1.Read(myByteBuffer);

  myByteBuffer_2 = _image.DecodeToBufferN(myByteBuffer, IMG_FORMAT_JPG, BITMAP_PIXEL_FORMAT_RGB565, w, h);
  contentId = contentManager.CreateContent(myByteBuffer_2, outFileName, 0);

This is E_SUCCESS now, but when I open the gallery, I see this:

So it seems the image is lost.

----------------------------

So, what is the correct usage of CreateContent using a bytebuffer as source?

Thank you

 

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

4 Replies
hgw7
You should encode the buffer with the image. The following code worked: ByteBuffer* buf = new ByteBuffer(); buf->Construct(1024); buf = img.EncodeToBufferN(*(App::GetInstance()->GetAppResource()->GetBitmapN(L"image.jpg", BITMAP_PIXEL_FORMAT_ARGB8888)), IMG_FORMAT_JPG); ByteBuffer byteBuffer; r = byteBuffer.Construct(buf->GetPointer(), 0, b->GetCapacity(), b->GetCapacity()); contentId = contentManager.CreateContent(byteBuffer, Tizen::System::Environment::GetMediaPath() + "Images/new.jpg", &imageContentInfo); AppLog("CreateContent %s", GetErrorMessage(GetLastResult()));
Zoltan Puski
I have not tried this yet, but does not look really good. As I have the encoded image raw data in the memory Bytebuffer, let's say downloaded from the internet a JPG file. Now you are saying I should: 1) decode ByteBuffer->BMP 2) encode the BMP->ByteBuffer 3) pass this one to contentManager I want to do: 1) decode ByteBuffer-> ByteBuffer 2) pass this one to contentManager And this one should work, but I think it has some bug somewhere? Or we don't know some trick here?
Alex Dem
Hi. Just simple way, you could write modified Bytebuffer via temporary file and delete temp file after: File tmpFile; Tizen::Base::String tmpFilePath = Tizen::App::App::GetInstance()->GetAppRootPath() + L"data/tmp"; tmpFile.Construct(tmpFilePath,"w+"); ... tmpFile.Write(myByteBuffer); ... contentId = contentManager.CreateContent(tmpFilePath, destPath, true, 0); Alexey.
Zoltan Puski
Thanks Alex, but this is what I want to avoid. As I have the file in the memory in a Bytebuffer, so writing to a file and then let the contentManager read it back looks waste for me.