Re: [Gambas-user] an "Is this possible question" about images
Brought to you by:
gambas
From: Kevin F. <kev...@ei...> - 2011-04-15 06:15:19
|
On 04/15/2011 12:47 AM, richard terry wrote: > >> Do you need it to look like a fisheye-style lens effect, or just >> box-zoom an area? If the latter this can be done easily in gb code. > > Just the box-zoom . > > Any change of you giving me a helping hand? I've not done anything much with > images or drawing. > > I'll mail you a sample png if you want - the purpose here is to magnify areas > of either skin, xray films or dermatascope images - all are images at the end > of the day. > > Its for our open - source medical records project that Ian and I are chuggling > slowly along with - not releasable as yet by I'm hoping that by the end of > 2011 it will be pretty much beta. > That is very cool. I'm doing a game so I know a little about images in gb. I'm going to assume that you're using Qt or GTK and not SDL or OpenGL, but correct me if I'm wrong. For those the easiest way to do graphics is with a DrawingArea control. After creating it on the form I'd change the Cached property to True so it will automatically redraw itself if something moves over it. You create image variables and load image files into them like this: Dim/Public someimage As Image someimage = Image.Load("FleshEatingVirusNooooo.jpg") You write images to the DrawingArea control like this: Draw.Begin(DrawingArea1) Draw.Image(someimage, X, Y, [Width, Height, SrcX, SrcY, SrcWidth, SrcHeight]) ' Add more "Draw.Image" statements here to composite additional images into the DrawingArea. Draw.End ' Commits the composition to the DrawingArea so that it may be seen. May need a "Wait" statement if done repeatedly. The [bracketed] parameters are optional. someimage is the source and the DrawingArea is the target. You can specify a subset of the source (the area to be zoomed) by playing with SrcX and SrcY (upper-left corner of source to be drawn) and SrcWidth and SrcHeight (width and height relative to SrcX and SrcY of source to be drawn). You can scale the source by playing with Width and Height. So that the source image writes to the DrawingArea don't leave a trail, I'd first draw the main (unzoomed) image to the DrawingArea, then draw the zoomed area onto that for each "frame" that you draw. The logic would go something like: ' Create your image variables. ' Load images into your image variables. Draw.Begin(DrawingAreaControlName) ' Draw the main image into the DrawingArea. ' Draw part of the main image into the DrawingArea adjusted by cursor position, zoom area size and zoom level. ' Draw text or whatever else you need to into the DrawingArea. Draw.End To draw text, which is really cool, you may do something like this inside the Draw.Begin/End: Draw.Foreground = Color.Black Draw.Text("Look, it's text on an image with a crappy shadow!!!", X, Y) Draw.Foreground = Color.White Draw.Text("Look, it's text on an image with a crappy shadow!!!", X + 1, Y - 1) I don't have any project examples that are simple enough to demonstrate this, but if you're really having trouble I could put something together. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sa...@ei... phone: (770) 853-6271 |