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

Drawing White PNG Images: Problem

Started by mar_je, 12 March 2009, 21:15:51

Previous topic - Next topic

mar_je

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

mar_je

Sorry, but I have screen for second procedure. ->Look attachment.

Galfar

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;

mar_je

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

Galfar

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;


mar_je

Man, you're GREAT  ;D. It's working...

//Awensome support for a libary :)

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

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

SMF spam blocked by CleanTalk