Hi Chris,
If you talk about "effet" I assuming your are under FMX application. Am I right ?
Your idea is good, but not faisable as is :
1) Effet are RunTime only : Due to the TEffect architecture it's unfortunally difficult to get the result as a TBitmap : I do not know why they do not introduce an event on Effect level, other subject !).
2) You can, as suggested, translate the c code to apply a monochrome effet, but that will not reduce, as is, the size of your bitmap : You'll have to reduce the Pixel format setting.
3) As I see, the goal is to save the image in a "compressed" form in your database : Your code is correct, but you save a BITMAP image, which is very big. The biggest state in fact
For reduce the size, why not saving it in, for example, JPG format ?
Put an image on a form, a button, and a Memo, and put this code in the on click : It is a exemple of Image Format manipulation in FMX.
procedure TForm1.Button1Click(Sender: TObject);
var l : TBitmapCodecManager;
s : TBitmapSurface;
lm : TMemoryStream;
begin
l := TBitmapCodecManager.Create;
lm := TMemoryStream.Create;
s := TBitmapSurface.Create;
try
s.Assign(Image1.Bitmap);
lm.Clear;
l.SaveToStream(lm,s,'bmp');
Memo1.Lines.Add(Format('BMP Image bitmap size : %d bytes',[lm.size]));
lm.Clear;
l.SaveToStream(lm,s,'jpg');
Memo1.Lines.Add(Format('JPG Image bitmap size : %d bytes',[lm.size]));
lm.Clear;
l.SaveToStream(lm,s,'png');
Memo1.Lines.Add(Format('PNG Image bitmap size : %d bytes',[lm.size]));
finally
FreeAndNil(l);
FreeAndNil(lm);
FreeAndNil(s);
end;
end;
Hi
I am using Delphi 10.1 Berlin Update 2 Anniversary edition.
The TMonochromeEffect is added as sub-class of TImage
When i load the file to TImage, the image appeared is monochrome.
When i save the bitmap of the TImage to the database and later retrieve it back for viewing, the image is coloured.
Please help as i want to reduce the size of the image when storing into database.
l_stream := TMemoryStream.Create;
l_stream.Position := 0;
l_surface := TBitmapSurface.Create;
l_surface.Assign(Image1.Bitmap); <== Image1.bitmap is still colour even though TMonochrome effect is added as sub class of TImage
// SQL statements
ParamByname('image').loadFromStream(l_stream, ftBlob);
ExecSQL
l_stream.Free;
Please help
thanks
chris
Connect with Us