-1

I want to store a jpeg image in a RC_DATA resource, but not a single image in one single RC_DATA. There are many things in that RC_DATA, all muxed together. At runtime I load that RC_DATA in a bufer and extract all the object, including this Jpeg. Now I have this image in a memory buffer and I need to load it in a TJpegImage or TBitmap. How can I do that ? I saw that those classes doesn't have some methods to achieve this...

Marus Gradinaru
  • 2,824
  • 1
  • 26
  • 55

1 Answers1

1

Copy the JPEG bytes from your buffer into a TMemoryStream (or, use a TCustomMemoryStream to point directly at the JPEG bytes to avoid making a copy). And then you can pass that stream to TJPEGImage.LoadFromStream().

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • But if I use `TCustomMemoryStream` I must make e new class from it and override `SetPointer` procedure ? Because I see that it si protected and I cannot access it as it is... Hm, it seems it cannot be ovrride it because is not a virtual procedure. – Marus Gradinaru Dec 26 '21 at 23:07
  • 1
    @MarcusNebunu No, `SetPointer()` is not virtual, so you can't override it. You would create a new class that *calls* `SetPointer()`, such as in the constructor, eg: `type TMemBufferStream = class(TCustomMemoryStream) public constructor Create(ABuffer: Pointer; ASize: NativeInt); end; ... constructor TMemBufferStream.Create(ABuffer: Pointer; ASize: NativeInt); begin inherited SetPointer(ABuffer, ASize); end;` – Remy Lebeau Dec 26 '21 at 23:26