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...
Asked
Active
Viewed 289 times
-1
-
1Seems like a perfect job for [`TJPEGImage.LoadFromStream`](https://docwiki.embarcadero.com/Libraries/en/Vcl.Imaging.jpeg.TJPEGImage.LoadFromStream). – Andreas Rejbrand Dec 26 '21 at 21:21
-
I highly doubt you [multiplexed](https://en.wikipedia.org/wiki/Multiplexing#Video_processing) data streams. Most likely you just [concatenated](https://en.wiktionary.org/wiki/concatenate) them. Your [bu**ff**ers](https://en.wiktionary.org/wiki/buffer#Noun_2). – AmigoJack Dec 26 '21 at 21:53
-
Give each image a different id – David Heffernan Dec 26 '21 at 22:12
-
@DavidHeffernan indeed, it will be simple that way but I don't want anyone to use a resource editor and extract that image. – Marus Gradinaru Dec 26 '21 at 22:58
-
@MarusNebunu: They can still use a resource editor to extract your images. – Andreas Rejbrand Dec 27 '21 at 00:06
-
@AndreasRejbrand Yes, but it's combined with other things and ecrypted. – Marus Gradinaru Dec 27 '21 at 00:16
1 Answers
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