• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Post reply

Other options

Shortcuts: ALT+S save/post or ALT+P preview

Topic summary

Posted by mos
 -  3 September 2008, 16:57:52
Thank you very much, your solution work great under Linux and under Windows  :)


Bye
Posted by Galfar
 -  3 September 2008, 13:46:36
I've found the reason: If any pixels of the bitmap have alpha>0 then
image is alpha blended on the form. All bitmaps converted
by Imaging from its images have full alpha information.
If you load that jpeg background it has alpha=255 so it is
blended correctly. But if you draw the line on canvas
using one of predefined color constant like clWhite they all
have alpha=0 (clWhite = TColor($FFFFFF)).
So the image is blended and only transparent thing is your line.

If you set the image alpha to 0 with following function it works ok:

procedure SetAlpha(const Image: TImageData; const Alpha: Word);
var
  Data: PByte;
  I: Integer;
begin
  with Image do
    Data := @PColor32Rec(Bits)^.A;
  for I := 0 to Image.Size div 4 - 1 do
  begin
    Data^ := Alpha;
    Inc(Data, 4);
  end;
end;



  Form1.Color := clGreen;
  FImage1 := TMultiImage.Create;
  FBitmap1 := TImagingBitmap.Create;
  Image1.Picture.Graphic := FBitmap1;
  FImage1.LoadFromFile('Tigers.jpg');
  FImage1.Format := ifA8R8G8B8;
  SetAlpha(FImage1.ImageDataPointer^, 0);
  Image1.Picture.Graphic.Assign(FImage1);

  Image1.Picture.Bitmap.Canvas.Pen.Color := clWhite;
  Image1.Picture.Bitmap.Canvas.Line(1, 1, 200, 200);     


Why it works this way or how to use canvas to draw on image with alpha
are questions for Lazarus forums, try there.
Posted by mos
 -  2 September 2008, 19:58:23
I'm trying to draw a line on an instance of TImage,  I have wrote this code with Lazarus 0.9.25:


procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Color := clBlack;

  FImage1 := TSingleImage.Create;
  FBitmap1 := TImagingBitmap.Create;
  Image1.Picture.Graphic := FBitmap1;
  FImage1.LoadFromFile('Tigers.jpg');
  Image1.Picture.Graphic.Assign(FImage1);
 
  Image1.Picture.Bitmap.Canvas.Pen.Color := clWhite;
  Image1.Picture.Bitmap.Canvas.Line(0, 0, 200, 200);
end;


where Image TImage type on Form1 of TForm.

This code work ok on Linux (Fedora), I see a white line, but on Windows (WinXP) I see a black line.
If I set "Form1.Color := clRed;" on Windows I see a red line, in Linux is always ok, I see a white line.

In conclusion, in Windows the line color is the same of the Form color, Why?

Can you help me?


Goodbye
SMF spam blocked by CleanTalk