How to draw a basic circle on an image
Posted
#1
(In Topic #1559)
Regular

Things I'm confused about.
<LIST>
- <LI>should I be using draw or paint - and what's the difference - I think they are the same but paint has superseded draw - although there is no paint event so you still use draw for event handling?</LI>
<LIST>
- <LI>How the whole drawing/paint system works</LI>
This is as much as I gleaned from various resources online, but I will be honest I really don't understand what this is doing, but it was my best (and failed) attempt at simplifying the examples.
Code (gambas)
- ' Gambas class file
- ImageView1.Update(exampleImage)
- paintCircle()
- 'I think this simply set up the paint parameters and triggers the draw event
- 'i.e. I want to draw a circle at (50,50) with a radius of 100 in red ink with a line width of 5 pixels
- Paint.Brush = Paint.Color(Color.red)
- Paint.LineWidth = 5
- Paint.circle(50, 50, 100)
- Paint.End
- 'I think this actually draws what was requested onto the imageView1.Image
- paint.End
I don't think I'm an idiot, but I'll accept that I am if you say so…
Posted
Guru

Most Paint methods have to be finished with either Paint.Stroke or Paint.Fill
Things that include the word Paint or Draw usually do not like Paint.DrawImage)
Code (gambas)
- 'I think this simply set up the paint parameters and triggers the draw event
- 'i.e. I want to draw a circle at (50,50) with a radius of 100 in red ink with a line width of 5 pixels
- Paint.Brush = Paint.Color(Color.red)
- Paint.LineWidth = 5
- Paint.circle(50, 50, 100)
- Paint.Stroke ' use Paint.Fill for a solid circle
- Paint.End
Posted
Regular

Thanks I got that right thenBruceSteers said
use Paint.class , Draw is drepreciated.
OK I added that but it still doesn't workBruceSteers said
Most Paint methods have to be finished with either Paint.Stroke or Paint.Fill
:?: Very cryptic, what should I be using? I'm genuinely stumbling in the dark, but perhaps a little elevated that it seems like I'm almost there without knowing what I'm doing :!:BruceSteers said
Things that include the word Paint or Draw usually do not like Paint.DrawImage)
Posted
Guru

I would just load the image directly to the ImageView
Code (gambas)
- ' Gambas class file
- paintCircle()
- Paint.Background = Color.red ' this is an easier way to set brush color :)
- Paint.LineWidth = 5
- Paint.circle(50, 50, 45) ' size is radius (from the center to edge)
- Paint.Stroke
- Paint.End
Posted
Guru

DIYTinkerer said
:?: Very cryptic, what should I be using? I'm genuinely stumbling in the dark, but perhaps a little elevated that it seems like I'm almost there without knowing what I'm doing :!:BruceSteers said
Things that include the word Paint or Draw usually do not like Paint.DrawImage)
Well not many have it, there is…
Paint.DrawImage Draw an Image, or part of it.
Paint.DrawPicture Draw a Picture, or part of it.
Paint.DrawRect Draw a rectangle frame
Paint.DrawRichText Draws a piece of rich text.
Paint.DrawRichTextShadow Draw the shadow of a rich text.
Paint.DrawText Draws the specified text.
Paint.DrawTextShadow Draw the shadow of a text.
For example Paint.DrawText will write the text without using Paint.Stroke or Paint.Fill
But Paint.Text will need it.
You'll get used to it and what you should use for your needs as you get more experience
Posted
Regular

But in my actual program the circle then disappears, so I thought; ahh, perhaps that is what the draw event is for - maintaining the drawn elements, but as soon as I add a draw event the imageview1.image disappears.
Is there a simpletons description of how drawing works, the relationship between the contents of an an imageview and the draw event handler
Posted
Regular

Posted
Guru

DIYTinkerer said
Ah I fixed it :!:, I draw to the actual image rather than the ImageView1.Image - I'm assuming that the ImageView1.Image gets refreshed with the content it is pointing to - which wasn't drawn on, so the circle disappears, by drawing to the actual limage that imageview1 points to the refresh retains the circle thanks for your help - and you patience with beginners like myself!
Well i do not know if all that is true, I am loading and writing directly to the imageview.Image just fine.
Without seeing all your code i could not guess why the circle gets overwritten again, (I would guess you are still using the ImageView1_Draw event)
but you got it working now so cool
The following code works okay writing directly to the ImageView.image property.
Code (gambas)
- Paint.Begin(hImage)
- ' use a fancy gradient color :)
- Paint.Brush = Paint.LinearGradient(X - 50, Y - 50, X - 50, Y + 50, [Color.Red, Color.Yellow, Color.Red], [0, 0.5, 1])
- Paint.LineWidth = 5
- Paint.circle(X, Y, 45)
- Paint.Stroke
- Paint.End
Posted
Regular

I've put my source code on github https://github.com/SimonTelescopium/ViewFromAbove if you are interested.
This is genuinely my first gambas project so I expect there are quite a few area that will cause a frown
Thanks Again.
Posted
Guru

ImageView_Draw is not for the novice.
you have to manually draw the image. working out zoom and scroll, etc :=/
PS. a Draw event happens inside the controls Paint.Begin and Paint.End instructions so you should not use Paint.Begin and Paint.End in a Draw event.
1 guest and 0 members have just viewed this.



