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

Need a primer - stuck!

Started by nibelung44, 2 August 2011, 14:36:45

Previous topic - Next topic

nibelung44

Hello,

I'm running in circle since some hours, achieving nothing. I apologize for the seemingly stupid problem I have, but after reading several time the help (low level imaging, high level imaging) plus the demo, I'm still stuck.

I'm using BDS2007. What I want to achieve is to display two PNG, with alpha channel preserved, on the canvas of a TImage. The PNGs will be rotated also.

So... seems obvious?

First, I create a TSingleImage, then rotate it for good measure.

  SImg    := TSingleImage.CreateFromParams(10, 10, ifA8R8G8B8);
  SImg.LoadFromFile('candles.png');
  SImg.Rotate(135);


Then, I want to try using the canvas... Correct me if I'm wrong, but some manipulations are made of TSingleImage, while others are made on ImagingCanvas, right? Say I'll reverse the color.


  FImageCanvas := TImagingCanvas.Create;
  FImageCanvas.CreateForImage(SImg);
  FImageCanvas.InvertColors;


Question 1: Do I need to do a CreateForImage each time I bind a canvas to an image? Am I not doing a memory leak here, as I already created the canvas, so doing CreateForImage which is also a Constructor seems weird here.


Next step, if I want to display properly on a TImage (I named my Viewport), I need to replace its Graphics with a TImagingBitmap, so I do

  FBitmap := TImagingBitmap.Create;
  ViewPort.Picture.Graphic := FBitmap;


And again, a question, if I do that, what about the original Graphic of the TImage? It is lost in limbo and so ... memory leak?

Last step, I want to display something.
  ViewPort.Picture.Graphic.Assign(SImg);

It works! But here I'm displaying SImg onto the whole TImage Canvas... But what if I wanted to add twice this image? As this is an assign, one will replace another, so not good!

Another solution, that will not work either  :o is to not associate a TImagingBitmap to the TImage Graphic, so I can use:
  DisplayImage(ViewPort.Canvas, 50, 50, SImg);
  DisplayImage(ViewPort.Canvas, 75, 75, SImg);

But here the images are not shown with correct transparency...

So basically I'm stuck. Plus I have several questions... The logic of the library is difficult to grasp for me.... You have to replace the Graphic part of a TImage with a special TImagingBitmap, then you can do some operations directly on class  TSingleImage, but some require a special TCanvas... and all that, how you use it in the end to display combinated images with transparency? I feel dumb and I need directions.

Just to summarize ... I want to be able to display in a TImage several PNG which are rotated and with their alpha channel preserved (so not just transparent/not transparent)... Is it possible? Would you help me understand how to do that?

Alen

It's simple...

var
  Img: ImagingClasses.TSingleImage;

procedure...
begin
  Img.LoadFromFile('test.png');
  ...
  ImagingComponents.DisplayImage(PaintBox.Canvas, PaintBox.BoundsRect, Img);
end;

Alen

Actually, look at the VCLImageBrowser demo, you'll find all the answers there.

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