Vampyre Imaging Library Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Imaging 0.26.4 Released!

Author Topic: images - array of bytes TO png jpeg  (Read 597 times)

bunak

  • Imaging User
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
images - array of bytes TO png jpeg
« on: 7 November 2009, 09:06:11 »

I have images that fill by bytes.
This images- 1024х1280х1- opened in Photoshop as RAW - format, with parameter depth - 8 Bits, Count - 1, Width, Height

In code image save in
Code: [Select]
imageBuf: array[0..1279, 0..1023] of byte;
Is it possible convert this array of bytes to jpeg or png
Logged

bunak

  • Imaging User
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: images - array of bytes TO png jpeg
« Reply #1 on: 7 November 2009, 09:27:18 »

Do like this

Code: [Select]
  mem_st := TMemoryStream.Create;
  Img := TSingleImage.Create;
  try
    mem_st.WriteBuffer(imageBuf, 1280 * 1024);
    mem_st.Position := 0;
    Img.LoadFromStream(mem_st);
    Img.SaveToFile(DirSave_path + '\' + node_img_name.NodeValue + '.jpg');
  finally
    mem_st.Free;
    Img.Free;
  end;

In result - is nothing
Logged

Galfar

  • Administrator
  • Imaging User
  • *****
  • Offline Offline
  • Posts: 249
    • ICQ Messenger - 327174200
    • View Profile
    • Galfar's Homepage
    • Email
Re: images - array of bytes TO png jpeg
« Reply #2 on: 7 November 2009, 19:23:07 »

There's no need to load the image from somewhere if it's already in memory. You can just create empty image with desired size and format, and then copy memory from your imageBuf to image's Bits property.
Logged

bunak

  • Imaging User
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: images - array of bytes TO png jpeg
« Reply #3 on: 8 November 2009, 19:26:40 »

Thank you

Help me please
I do like this
Code: [Select]
var
  singl_Img: TSingleImage;
  Img : TImageData;
begin
  if not NewImage(img_W, img_H, ifIndex8, Img) then Exit;
  CopyMemory(Img.Bits, @imageBuf[0], Img.Size);
  singl_Img.CreateFromData(Img);

  try
    singl_Img.SaveToFile(DirSave_path + '\' + node_img_name.NodeValue + '.jpg');
  finally
    singl_Img.Free;
  end;
but get "Access violation" error on singl_Img.CreateFromData(Img);

the error erise in this procedure
Code: [Select]
{ TBaseImage class implementation }
constructor TBaseImage.Create;
begin
  SetPointer;
end;
« Last Edit: 8 November 2009, 19:52:19 by bunak »
Logged

bunak

  • Imaging User
  • *
  • Offline Offline
  • Posts: 4
    • View Profile
Re: images - array of bytes TO png jpeg
« Reply #4 on: 8 November 2009, 20:14:47 »

And in result i do like this, and I happy
Code: [Select]
  singl_Img := TSingleImage.Create;
  singl_Img.CreateFromParams(img_W, img_H, ifGray8);
  CopyMemory(singl_Img.Bits, @imageBuf[0], singl_Img.Size);

  try
    singl_Img.SaveToFile(DirSave_path + '\' + img_name + '.' + cmbx_ImageExt.Text);
  finally
    singl_Img.Free;
  end;
« Last Edit: 24 November 2009, 08:29:35 by bunak »
Logged
 

Page created in 0.085 seconds with 20 queries.