Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: How to get the Monochrome effect image to save into database



Permlink Replies: 2 - Last Post: Apr 20, 2018 1:22 AM Last Post By: Vincent Gsell Threads: [ Previous | Next ]
Chuah Yen Hua,C...

Posts: 73
Registered: 7/5/97
How to get the Monochrome effect image to save into database
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2018 8:25 PM
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

Alex Belo

Posts: 626
Registered: 10/8/06
Re: How to get the Monochrome effect image to save into database
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 14, 2018 10:41 PM   in response to: Chuah Yen Hua,C... in response to: Chuah Yen Hua,C...
Chuah Yen Hua,Christopher wrote:

l_surface.Assign(Image1.Bitmap); <== Image1.bitmap is still colour
even though TMonochrome effect is added as sub class of TImage

I convert color bmps to mono manually if needed (cpp code):

void __fastcall MakeGray(Graphics::TBitmap* const bmp)
{
TMaxLogPalette NewPalette;
NewPalette.palVersion=0x300;
NewPalette.palNumEntries=256;
for(int i=0; i<256; i++)
{
NewPalette.palPalEntry[i].peRed = (BYTE)i;
NewPalette.palPalEntry[i].peGreen = (BYTE)i;
NewPalette.palPalEntry[i].peBlue = (BYTE)i;
NewPalette.palPalEntry[i].peFlags = PC_NOCOLLAPSE;
}
bmp->PixelFormat=pf8bit;
bmp->Palette=CreatePalette((PLOGPALETTE)(&NewPalette));
}

--
Alex
Vincent Gsell

Posts: 5
Registered: 3/6/11
Re: How to get the Monochrome effect image to save into database
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2018 1:22 AM   in response to: Chuah Yen Hua,C... in response to: Chuah Yen Hua,C...
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;

Chuah Yen Hua,Christopher wrote:
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

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02