DrawImage in a circle
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
DrawImage in a circle
I would like to load an image file (gif, jpg) into memory and then only draw part of the image inside a round circle. Can this be done with little API programming?
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
It is transparent to show an image inside.
Actually this is what i am trying to do. I want to move the mouse over an image, and the circle will act like a magnifying glass to magnify part of the image over the mouse. The circle will be directly under the mosue pointer.
Can this be done with little API programming?
Actually this is what i am trying to do. I want to move the mouse over an image, and the circle will act like a magnifying glass to magnify part of the image over the mouse. The circle will be directly under the mosue pointer.
Can this be done with little API programming?
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Ok, done. Try this test program out. It should do what you're after.
Code: Select all
LoadFont(0,"Arial",18,#PB_Font_Bold)
CreateImage(0,500,500)
StartDrawing(ImageOutput())
Box(0,0,500,500,RGB(255,255,255))
DrawingFont(UseFont(0))
For i = 0 To 475 Step 25
Locate(0,i)
DrawText("The rain in Spain falls mainly on the plain.")
Next i
StopDrawing()
CopyImage(0,1)
ResizeImage(1,300,300)
OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Magnifying Glass example by Network Maestro")
InitSprite():InitMouse():InitKeyboard()
OpenWindowedScreen(WindowID(0),50,50,300,300,0,0,0)
CreateSprite(0,94,94)
TransparentSpriteColor(0,70,20,80)
Repeat
ExamineMouse()
GrabImage(0,2,MouseX()*1.67,MouseY()*1.67,94,94)
StartDrawing(SpriteOutput(0))
DrawImage(UseImage(2),0,0)
FrontColor(70,20,80)
DrawingMode(4)
Circle(46,46,45)
DrawingMode(1)
FillArea(2,2,RGB(70,20,80),RGB(70,20,80))
StopDrawing()
StartDrawing(ScreenOutput())
DrawImage(UseImage(1),0,0)
StopDrawing()
DisplayTransparentSprite(0,MouseX(),MouseY())
FlipBuffers()
Delay(1)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All) Or MouseButton(#PB_MouseButton_Left) Or MouseButton(#PB_MouseButton_Right)
Last edited by netmaestro on Sat Sep 17, 2005 4:28 pm, edited 1 time in total.
BERESHEIT
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Kidding aside, the example isn't meant to be a bulletproof functioning app, just a code snippet to demonstrate the technique. Mouse clicks are not used or anticipated. You can take it from here with my best wishes for success. btw, it sounds like you're making a cool app, I hope you'll demo it for us when it's done!"Doctor, doctor, my arm hurts when I do this!"
"Don't do that."
** EDIT ** I've edited the example code so that any keypress or mouse click will end the program. GPF's ain't cool, even in snippets.
BERESHEIT
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
Of course, you are right. A couple of questions here.
How can i make the top left position of the window Screen to be the same as the main Window? At the moment, the 0,0 position of the window screen seems to be shift down and right to the main Window.
Here is my code:
Cecil
How can i make the top left position of the window Screen to be the same as the main Window? At the moment, the 0,0 position of the window screen seems to be shift down and right to the main Window.
Here is my code:
Code: Select all
UseJPEGImageDecoder()
InitSprite():InitMouse():InitKeyboard()
OpenWindow(0,0,0,600,600,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Magnifying Glass example by Network Maestro")
OpenWindowedScreen(WindowID(0),0,0,106,75,0,0,0)
LoadImage(0,"image1.jpg")
CopyImage(0,1)
ResizeImage(1,106,75)
CreateSprite(0,94,94)
TransparentSpriteColor(0,70,20,80)
Repeat
ExamineMouse()
GrabImage(0,2,MouseX()*4,MouseY()*4,94,94)
StartDrawing(SpriteOutput(0))
DrawImage(UseImage(2),0,0)
FrontColor(70,20,80)
DrawingMode(4)
Circle(46,46,20)
DrawingMode(1)
FillArea(2,2,RGB(70,20,80),RGB(70,20,80))
StopDrawing()
StartDrawing(ScreenOutput())
DrawImage(UseImage(1),0,0)
StopDrawing()
DisplayTransparentSprite(0,MouseX(),MouseY())
FlipBuffers()
Delay(1)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_All) Or MouseButton(#PB_MouseButton_Left) Or MouseButton(#PB_MouseButton_Right)
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
-
cecilcheah
- Enthusiast

- Posts: 168
- Joined: Wed Jun 04, 2003 8:44 am
- Location: Switzerland
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
The reason the magnifier won't go to the corners is that you resized the circle in the magnifier sprite but left the sprite and the image that gets drawn on it at the bigger size. The result is a wide margin of transparent pixels around the circle. Your sprite and image should be 4 pixels larger than your circle in both dimensions to work properly, but no more. Off the top of my head I'd say that 4x is too much magnification to look right, but you can play with that and find something that looks good. If I were doing it, I'd probably add some gray space to the original image as well as the smaller one and make the windowed screen fit the small image + grayspace, that way your magnifier can go past the edge and it will look right. Anyway, you're off and running now. Good luck!
BERESHEIT
-
zefiro_flashparty
- User

- Posts: 74
- Joined: Fri Mar 04, 2005 7:46 pm
- Location: argentina
:P
486dx 66mhz + 8MB ram, trident 9680 pci 1MB, Monitor Monochrome 14" 640x480@60 , Win 95