• 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 mar_je
 - 13 March 2009, 16:34:31
Man, you're GREAT  ;D. It's working...

//Awensome support for a libary :)
Posted by Galfar
 - 13 March 2009, 16:19:15
Ok I got it, the bitmap needs to be premultiplied by alpha for layered window to display properly. PNGImage does this by itself when converting to TBitmap.
You can try this code:
var
  testPNG:TImagingBitmap;
  X, Y: Integer;
  Dest, Src: PByte;
  Alpha: Byte;
begin
  FLayeredWindow:=TO3LayeredWindow.Create(Form1);
  FLayeredWindow.Parent:=Form1;
  testPNG:=TImagingBitmap.create;
  testPNG.LoadFromFile('..\Images\image_not_working.png');
  FLayeredWindow.Surface.Width:=testPNG.Width;
  FLayeredWindow.Surface.Height:=testPNG.Height;
  FLayeredWindow.Surface.PixelFormat:=pf32Bit;

  with FLayeredWindow.Surface do
    for Y := 0 to Height - 1 do
    begin
      Src := testPNG.Scanline[y];
      Dest := ScanLine[y];
      for X := 0 to Width - 1 do
      begin
        Alpha := Src[X * 4 + 3];

        Dest[X * 4 + 0] := Src[x * 4 + 0] * Alpha div 255;
        Dest[X * 4 + 1] := Src[x * 4 + 1] * Alpha div 255;
        Dest[X * 4 + 2] := Src[x * 4 + 2] * Alpha div 255;
        Dest[X * 4 + 3] := Alpha;
      end;
    end;

  FLayeredWindow.UpdateLayer;
end;

Posted by mar_je
 - 13 March 2009, 09:43:28
Thanks for a fast reply, but the result is the same as my procedure  :(. I create sample apps for You can check it (images, procedure with PNGImage, Your procedure, component for create layeredWindow).

(I uploaded it on my server, beacouse it's larger than maximum individual size in attachment. Download samples with sources from): http://communicom.w8w.pl/SampleApps.rar
Posted by Galfar
 - 13 March 2009, 02:41:48
What about if you convert PNG image loaded by Imaging to TBitmap instead of using DisplayImage? DisplayImage doesn't do any alpha blending which I guess is needed here.

You can directly use TImagingBitmap class to load the PNG:
TestPNG:=TImagingBitmap.Create;
TestPNG.LoadFormFile('Skinwindow.png');
FLayeredWindow.Surface.Width:=Form1.Width;
FLayeredWindow.Surface.Height:=Form1.Height;
FLayeredWindow.Surface.Assign(TestPNG);
FLayeredWindow.UpdateLayer;
Posted by mar_je
 - 12 March 2009, 21:22:15
Sorry, but I have screen for second procedure. ->Look attachment.
Posted by mar_je
 - 12 March 2009, 21:15:51
First of all, sorry for my English (I'm foreinger :))

Hi.

I want to draw image (you can download it from: http://communicom.w8w.pl/image_not_working.png) on a TBitmap, but it's some problem with a white parts of image (look at the screen):


The second (black) picture is painted well with the same code:

FImage2:=TMultiImage.create;
FImage2.loadmultifromfile('Skin\window.png');
FLayeredWindow.Surface.Width:=Form1.Width;
FLayeredWindow.Surface.Height:=Form1.Height;
ImagingComponents.DisplayImage(FLayeredWindow.Surface.Canvas,Rect(0,0,Form1.Width,Form1.Height),Fimage2);
FLayeredWindow.UpdateLayer;
FImage2.Free;


This code is working well for a white image too.:
TestPNG:=TPNGObject.Create;
TestPNG.LoadFormFile('Skin\window.png');
FLayeredWindow.Surface.Width:=Form1.Width;
FLayeredWindow.Surface.Height:=Form1.Height;
FLayeredWindow.Surface.Assign(TestPNG);
FLayeredWindow.UpdateLayer;


I think, you can understand me  ;). Can you help me to fix a problem?

//I'm using "O3LayeredWindow" component to create layered Form. System: Win XP SP2; Delphi 2009
SMF spam blocked by CleanTalk