Author Topic: Problem on copy memory containing image bits  (Read 1428 times)

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Problem on copy memory containing image bits
« on: 4 June 2009, 11:50:48 »
I have the necessity to store in a buffer the bits image so I use this code:

Code: [Select]
  ...
    FBitmap: TImagingBitmap;
    FImage: TSingleImage;
    s: LongInt;
    gbuff: Pointer;
  ...

  FImage := TSingleImage.Create;
  FBitmap := TImagingBitmap.Create;
  Image.Picture.Graphic := FBitmap;
  ...
  FImage.LoadFromFile('test.jpg');
  Image.Picture.Graphic.Assign(FImage);
  s := FImage.Size;
  GetMem(gbuff, s);
  {$ifdef Linux}
  Move(FImage.Bits, gbuff, s);
  {$endif}
  {$ifdef Win32}
  CopyMemory(gbuff, FImage.Bits, s);
  {$endif}

The code work well under Windows but under Linux I get an exception on Move instruction.

I use Lazarus 0.9.26 & fpc 2.2.2, WinXP+SP2, Linux Fedora Core 8.

In the attached file there is the complete source code.


Can you help me?

Thanks & goodbye

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: Problem on copy memory containing image bits
« Reply #1 on: 4 June 2009, 18:30:17 »
Move procedure from RTL takes dereferenced pointers as arguments, so you'll need to use it this way:

Code: [Select]
Move(FImage.Bits^, gbuff^, s);
Btw why do you use CopyMemory instead of Move in Windows?

Offline mos

  • Imaging User
  • *
  • Posts: 23
    • View Profile
Re: Problem on copy memory containing image bits
« Reply #2 on: 4 June 2009, 20:05:23 »
Yes you have right, now I have seen that in FreePascal the CopyMemory is implemented through a Move! Under Windows I have always used winapi CopyMemory  :(

I must read the FreePascal documentation.

Thanks for your suggestion.