Real Software Forums

Grab part of a loaded image
Page 1 of 1

Author:  ccfman2004 [ Tue Aug 16, 2011 12:57 am ]
Post subject:  Grab part of a loaded image

I am using the DoubleBuffer property of the canvas when my program runs in Windows. Problem is, it looses its transparency which removes the background image behind it. I need to grab the portion of the background image that is being discarded and redraw it where is needs to go.

The canvas has the following properties:
Left: 256
Top: 256
Height: 256
Width: 256

The background image is 1024 x 768.

The background image is stored in variable bgpic and the variable that controls the canvas image is imgTmp(2) which is located in the Paint event of that canvas.

I had an example project that showed me what to do but I can no longer find it.

Any help is appreciated.

EDIT: I finally got it.

In the paint event of the Canvas, I used the following code:
If index = 2 and TargetWin32 then
This way if only fires if the game is being run on Windows since Mac OS X does not require the DoubleBuffer on.

Author:  ccfman2004 [ Sat Jan 14, 2012 7:00 am ]
Post subject:  Re: Grab part of a loaded image


How do copy a portion of one Picture property to another?

The original picture is:

Height = 768
Width = 1024

I need to copy a small portion of this image into another picture property.

The new picture will be located at:

Left = 347
Top = 50
Width = 600
Height = 510

Any ideas?

Author:  DaveS [ Sat Jan 14, 2012 12:22 pm ]
Post subject:  Re: Grab part of a loaded image

g.drawpicture does everything you are asking about.

read up on it more in the LR

the main reason it needs two sets of coordinates, is to provide the ability to cut a piece from one picture and paste it into another
as well as zoom in/out at the same time

Image as Picture,
X as Integer, Y as Integer
,DestWidth as Integer, DestHeight as Integer
, SourceX as Integer, SourceY as Integer
, SourceWidth as Integer, SourceHeight as Integer

Draws the picture at the specified location. The picture can be shown at full size, cropped, or scaled. All units are pixels. X and Y are the distances from the top-left corner of the control or window from which the 0,0 point of the image will be drawn. The optional parameters are used to copy a portion of the picture (cropping) and for scaling the picture. If you are cropping, then DestWidth and DestHeight are also required. If you are doing scaling, then all of the optional parameters are required. You scale an image by making the destination width and height different from the source width and height.
The parameters SourceX, SourceY, SourceWidth, and SourceHeight describe the portion of the image that will be scaled. DestWidth and DestHeight are used to change the scaling of the picture when SourceWidth and SourceHeight are provided. SourceX and SourceY default to 0 and are used to determine the upper-left coordinate you wish to copy from.

If source X,Y,W,H are equal to Dest X,Y,W,H then it is simply a draw the picture as is
but if Dest X,Y are different... it will cut the piece as defined by source, and paste it to the coordinate defined in DEST

if the W,H value are different, then it will scale the picture based on the ratio between the two sets of values

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group