有人知道我怎么才能得到一张图片并将其存储在Tstream中?
我的目标是在内存上使用它,并在TIimage中显示给用户。
使用 * OleSavePictureFile * 可以将图像保存为任何格式(PNG,BMP,JPG等),但保存在磁盘上。有人知道如何获得IPicture并将其保存到流中,并将其放在TIimage上吗?
我试过这种方法
// Obtaining the IPicture
var LPicture := DPBiometria.DPSC.ConvertToPicture(pSample) as IPicture;
// This line saves the image correctly, but i dont want this way.
// OleSavePictureFile(IPictureDisp(LPicture), 'D:\teste.jpg');
// Trying stores it on the stream and put on a bitmap or show on a TImage
var LStream := TBytesStream.Create;
var LOleG := TOleGraphic.Create;
LOleG.Picture := LPicture;
LOleG.SaveToStream(LStream);
// When loading it on a TImage, it doesnt shows...
// When loadgin on a TBitMap or TJPegImage, and trying to
// save to a file, its saved with 0 bytes.
// The TImage doesnt shows the image
SomeTImage.LoadFromFile(LStream);
// Saved with 0 bytes
var Lbmp := TBitmap.Create;
Lbmp.LoadFromStream(LStream);
Lbmp.SaveToFile('D:\testeStream.bmp');
谢谢你的帮助
1条答案
按热度按时间dfty9e191#
在将图像保存到流之后和加载流之前,不能将
TBytesStream.Position
属性设置回0。也就是说,如果您只想在
TImage
中显示IPcture
,则不需要将IPicture
保存到流中,然后将流加载到TBitmap
中。由于TOleGraphic
派生自TGraphic
,因此您只需将TOleGraphic
直接赋给TImage.Picture.Graphic
属性,例如: