Author |
Topic |
|
jwest
Brazil
67 Posts |
Posted - Jun 20 2011 : 11:35:39
|
Hi, I have a ImageEnVect with layer[0] to background image and Layer[1]. I need to put Layer[1] exactly over ImageEnVect1 all the time, taking account zoom and form resizing. I have tried many alternatives without success. Here is my last snippet code used in onresize event of the form.
with ImageEnVect1.Layers[1] do begin width:=trunc(ImageEnVect1.ClientWidth*100/ImageEnVect1.Zoomx); Height:= trunc(ImageEnVect1.ClientHeight*100/ImageEnVect1.ZoomY); Posx:=PosX + trunc((ImageEnVect1.XScr2Bmp(0) - ImageEnVect1.XScr2Bmp(ImageEnVect1.Layers[1].ClientAreaBox.Left)); Posy:=Posy + (ImageEnVect1.YScr2Bmp(0) - ImageEnVect1.YScr2Bmp(ImageEnVect1.Layers[1].ClientAreaBox.Top)); end;
Please, some help would be wellcome.
Best Regards,
Luiz |
|
fab
1310 Posts |
Posted - Jun 20 2011 : 12:14:28
|
Hi,
>...taking account zoom and form resizing.
the default is already this. All layers will be resized when zoom changes. All layers will scroll when the scroll changes.
As already mentioned in another topic it is not supported to have a layer that is independent by the others. |
|
|
jwest
Brazil
67 Posts |
Posted - Jun 20 2011 : 12:22:07
|
Mr Fabrizio,
But I can resize a layer. There is a sample on demo.
I only want resize the Layer[1] to put exactly over the rectangle of a TimageEnVect component, not over TimageEnVect.Bitmap. I don't want make it independent. I want calculate PosX and PosY of the Layer to do it.
How could I do it by hand?
Regards,
Luiz |
|
|
fab
1310 Posts |
Posted - Jun 20 2011 : 13:13:06
|
>I only want resize the Layer[1] to put exactly over the rectangle of a TimageEnVect >component, not over TimageEnVect.Bitmap.
I cannot help using layers (this is an atipical use), but you can still handle the event OnDrawBackBuffer. For example this paints an ellipse inside the TImageEnVect area. It doesn't depend by the scroll and zoom.
procedure TForm1.ImageEnVect1DrawBackBuffer(Sender: TObject);
begin
with ImageEnVect1.BackBuffer.Canvas do
begin
Pen.Color := clRed;
Ellipse(0, 0, ImageEnVect1.BackBuffer.Width, ImageEnVect1.BackBuffer.Height);
end;
end;
|
|
|
jwest
Brazil
67 Posts |
Posted - Jun 20 2011 : 13:45:40
|
Hi,Mr Fabrizio,
Thank you for your patience. I think I was misunderstood. Please, my question is not draw on the Layer. I only want set PosX, PosY,Width and Height properties of this layer.
For example, I have a TimageEnvect with: Left=10; Top=10; Width=50;Height=60. When I create a layer, it is created into the TImageEnvect, but with dimensions smallest than TimageEnvect.
|
|
|
jwest
Brazil
67 Posts |
Posted - Jun 20 2011 : 13:48:27
|
Continue(I am having problem posting, it seems the forum is cutting the text.) I only want to set the properties of the Layer just created in runtime: PosX:=??, PosY:=? Width:=?, Height:=? such as this layer take the same dimensions of TImageEnVect and the same Left and Top coordinates. This layer will cover all TImageEnvect component.It would work as if I had done a stretch this layer into TImageEnvect.
Thanks in advance,
Luiz |
|
|
fab
1310 Posts |
Posted - Jun 20 2011 : 22:31:42
|
I'm sorry, maybe I continue to not understand you! This will adapt the layer to the client area:
ImageEnVect1.LayersAdd();
ImageEnVect1.CurrentLayer.PosX := ImageEnVect1.XScr2Bmp(0);
ImageEnVect1.CurrentLayer.PosY := ImageEnVect1.YScr2Bmp(0);
ImageEnVect1.CurrentLayer.Width := ImageEnVect1.XScr2Bmp(ImageEnVect1.ClientWidth) -
ImageEnVect1.XScr2Bmp(0);
ImageEnVect1.CurrentLayer.Height := ImageEnVect1.YScr2Bmp(ImageEnVect1.ClientHeight) -
ImageEnVect1.YScr2Bmp(0);
You could have math rounding problems, hence the layer cannot exactly match the client area.
Anyway I still think the right way is to use OnDrawBackBuffer.
|
|
|
jwest
Brazil
67 Posts |
Posted - Jun 21 2011 : 05:44:34
|
Mr Fabrizio,
It works like a charm.
I also will try with OnDrawBackBuffer.
Thanks, Luiz
|
|
|
jwest
Brazil
67 Posts |
Posted - Jun 21 2011 : 06:39:28
|
Using OnDrawBackBuffer works better. I have less flicker on image.
Using OnDrawBackBuffer, I written some tags on it.
Is there a way to merge the Canvas of DrawBackBuffer with Layer[0] of ImageEnVect to print?
I had seen samples using layers, but this is a different case.
Regards, Luiz |
|
|
fab
1310 Posts |
Posted - Jun 21 2011 : 06:45:11
|
>Is there a way to merge the Canvas of DrawBackBuffer with Layer[0] of ImageEnVect to print?
this should work:
ImageEnVect1.IEBitmap.Assign( ImageEnVect1.BackBuffer ); ImageEnVect1.Update(); |
|
|
jwest
Brazil
67 Posts |
Posted - Jun 27 2011 : 15:56:10
|
Hi, >>ImageEnVect1.IEBitmap.Assign( ImageEnVect1.BackBuffer ); >>ImageEnVect1.Update(); Using it, Does the BackBuffer will shrink or expand to IEBitmap width and height? In my tests, it seems doesn´t happen. If not, How could I do it? I need it to print or I will print large black areas in my image.
Regards,
Luiz
|
|
|
fab
1310 Posts |
Posted - Jun 28 2011 : 00:18:25
|
BackBuffer has the same width and height of TImageEnView/Vect client area. It is not related to the bitmap size. |
|
|
jwest
Brazil
67 Posts |
Posted - Jun 28 2011 : 04:24:17
|
Hi,
For printing, I need resize the backbuffer to same size of the bitmap. Something as: bmp:=TIEBitmap.Create; backbuff:=TBitmap.Create; try backbuff.assign(ImageEnVect1.BackBuffer); bmp.assign(ImageEnVect1.IEBitmap); backbuff.resize(bmp.width,bmp.height); //How I do it?
bmp.Assign( backbuff ); print_bmp; //Print the bmp finally bmp.free; backbuff.free; end;
Regards Luiz |
|
|
fab
1310 Posts |
Posted - Jun 28 2011 : 06:10:46
|
with TImageEnProc.CreateFromBitmap( ImageEnVect1.BackBuffer ) do
begin
ResampleTo(bmp, ImageEnVect1.IEBitmap.Width, ImageEnVect1.IEBitmap.Height, rfFastLinear);
Free();
end;
print_bmp();
Hope this helps. |
|
|
jwest
Brazil
67 Posts |
Posted - Jun 28 2011 : 14:31:05
|
Hi, I am trying it, but I am losting resolution. I am trying also other code, but the image disappear and becomes Black, in the line marked below. I have some tags in BackBuffer: Item := TImageEnvect.Create(self); .... .... Item.Background:=clWhite;
Item.OnDrawBackBuffer:=ImageEnVect1.OnDrawBackBuffer; Item.Assign(ImageEnVect1); Item.Update; //here the backbuffer is ok and shows with the image Item.IEBitmap.Assign(Item.BackBuffer);>>Here is the problem--> Black without Image on Item Component Item.Update;
Regards, Luiz |
|
|
fab
1310 Posts |
Posted - Jun 28 2011 : 14:48:09
|
The question was:
"For printing, I need resize the backbuffer to same size of the bitmap."
the code I posted does it, of course "after" the back buffer is valid (ie after Update()).
|
|
|
fab
1310 Posts |
Posted - Jun 28 2011 : 14:51:47
|
>I am trying it, but I am losting resolution.
this is also normal. The backbuffer is used to "print" on the screen (which has low resolution compared with the resolution of a printer). The resampling just interpolates the missing pixels, but the result will be still poor. |
|
|
jwest
Brazil
67 Posts |
Posted - Jun 28 2011 : 15:16:20
|
You are correct. My original post was about printing.
But, I forgot to say I am selecting the images and putting it in a GridPanel before print. Is there a way to show on screen the iebitmap with your backbuffer with the same dimensions(width and height), as you did with resample procedure to print? I am trying the next, but it doesn't work.
Item.Background:=clWhite;
Item.OnDrawBackBuffer:=ImageEnVect1.OnDrawBackBuffer; Item.Assign(ImageEnVect1); Item.Update; //here the backbuffer is ok and shows with the image Item.IEBitmap.Assign(Item.BackBuffer);>>Here is the problem--> Black without Image on Item Component Item.Update; add_item_grid_panel;//add Item to GridPanel
Regards, Luiz |
|
|
fab
1310 Posts |
Posted - Jun 28 2011 : 23:57:57
|
> Is there a way to show on screen the iebitmap with your backbuffer with the same >dimensions(width and height)
put another TImageEnView and execute ResampleTo using it as destination.
|
|
|
|
Topic |
|