Page 1 of 2

Vector graphics support ?

Posted: Sunday 18th April 2021 6:17am
by Doctor Watson
I was wondering, does Gambas support vector graphics (.AI, .EPS., .SVG, .DRW)?
I tried to use some, but Gambas doesn’t seem to know them.
It would be ideal for setting quality stable backgrounds, buttons and such. Certainly when you would be using resizable controls or background pictures for small controls like buttons.
Wishful thinking perhaps.

Re: Vector graphics support ?

Posted: Sunday 18th April 2021 1:43pm
by cogier
You can use .svg files as an image for a button or form. You do need to change the filter to All files(*) so that you can see the file. I'm not sure about the others you mention .AI, .EPS., .DRW, I can't say I have even come across them before. I suggest you try it and see what works.

Re: Vector graphics support ?

Posted: Monday 19th April 2021 7:38am
by Doctor Watson
Hi Cogier.
After changing the filter to ‘All Files’ you can indeed use any vector graphics, also as Form background and Controls with the ‘Picture’ property.
Unfortunately the result is not what I hoped for, namely that such vector graphics would adapt automatically to their container’s size – like a button with width 60, height 30 or expand when used as background. So you need one with the ‘right dimensions’ just like any others (.gif, etc.)
Actually that would mean the opposite of ‘AutoResize’, where the Control takes the size of it’s content.
One advantage of vector graphics : they are very sharp and clear.

Re: Vector graphics support ?

Posted: Monday 19th April 2021 10:08am
by BruceSteers
dr watson wrote: Unfortunately the result is not what I hoped for, namely that such vector graphics would adapt automatically to their container’s size –
there is an SvgImage.class

So if you
Dim MyImage as SvgImage
and use that image you may have further control like using Paint and Resize to make it correct size

It also looks like a QT control so do not know if it also works on gtk.

also wiki says SvgImage in QT4 is buggy (qt5 in unknown)

Re: Vector graphics support ?

Posted: Monday 19th April 2021 11:17am
by Doctor Watson
OK Bruce, I'll have a go at it.

Re: Vector graphics support ?

Posted: Tuesday 20th April 2021 6:08am
by Doctor Watson
Hi Bruce
This SvgImage seems to be useless for actual resizing an .svg image.
The example in gb.qt4 does work, but both setting width & height or using Resize give as result a cropped section of somewhere in the middle of the original image. Resize should apply to the entire image.
If would have liked to send the Flag_UK.svg I've used, but this forum does'nt allow to attach .svg graphics. :?
Inkscape is a nice vector editor to have a look at svg graphics.
Dim MyImage As SvgImage
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")

'This works - source gb.qt4
Paint.Begin(MyImage)
Paint.Brush = Paint.RadialGradient(200, 140, 40, 215, 115, [Color.RGB(255, 0, 0, 64), Color.White], [1.0, 0.1])
Paint.Arc(200, 140, 40)
Paint.Fill
Paint.End
'Result: A Union Jack with a red ball in it
MyImage.Save(Application.path & "/SVG/Flag_UK_RedBall.svg")

'But this doesn't resize at all, it 'Crops'
MyImage.Clear
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
MyImage.Resize(100, 50)
MyImage.Save(Application.path & "/SVG/Flag_UK_Resize.svg")
'is just the same as
MyImage.Clear
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
MyImage.width = 100
MyImage.Height = 50
MyImage.Save(Application.path & "/SVG/Flag_UK_W&H.svg")
It would have been usefull if it worked ...

Re: Vector graphics support ?

Posted: Tuesday 20th April 2021 5:42pm
by BruceSteers
Doctor Watson wrote: Tuesday 20th April 2021 6:08am Hi Bruce
This SvgImage seems to be useless for actual resizing an .svg image.
The example in gb.qt4 does work, but both setting width & height or using Resize give as result a cropped section of somewhere in the middle of the original image. Resize should apply to the entire image.
If would have liked to send the Flag_UK.svg I've used, but this forum does'nt allow to attach .svg graphics. :?
Inkscape is a nice vector editor to have a look at svg graphics.
Dim MyImage As SvgImage
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")

'This works - source gb.qt4
Paint.Begin(MyImage)
Paint.Brush = Paint.RadialGradient(200, 140, 40, 215, 115, [Color.RGB(255, 0, 0, 64), Color.White], [1.0, 0.1])
Paint.Arc(200, 140, 40)
Paint.Fill
Paint.End
'Result: A Union Jack with a red ball in it
MyImage.Save(Application.path & "/SVG/Flag_UK_RedBall.svg")

'But this doesn't resize at all, it 'Crops'
MyImage.Clear
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
MyImage.Resize(100, 50)
MyImage.Save(Application.path & "/SVG/Flag_UK_Resize.svg")
'is just the same as
MyImage.Clear
MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
MyImage.width = 100
MyImage.Height = 50
MyImage.Save(Application.path & "/SVG/Flag_UK_W&H.svg")
It would have been usefull if it worked ...
Aah sorry dude i thought that might be the answer.
You'd have thought "scalable" vector graphics would be easier to resize.
Looks like it's the same behaviour as the Image.class where "resize" is different to "stretch"

Are you on the gambas mailing list?
might be an idea to ask on there if there is a way

Re: Vector graphics support ?

Posted: Wednesday 21st April 2021 5:39am
by Doctor Watson
I never considered the Stretch option, so I tried it now.
I thought the following code could get a ‘stretched’ Image into a control, also in one that only accepts Pictures. Problem solved? NO.
The code runs without errors, but the result is just an empty black graphic.
I am obviously forgetting something or getting it completely wrong :cry:
You need PictureBox1 and Button1
' Gambas class file
Private MyGraphic As Image

Public Sub Form_Open()
MyGraphic = New Image(250, 200, False)
MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
MyGraphic.Stretch(Button1.width, Button1.height)
PictureBox1.Image = MyGraphic
Button1.picture = MyGraphic.picture
End

Re: Vector graphics support ?

Posted: Wednesday 21st April 2021 11:08am
by BruceSteers
Doctor Watson wrote: Wednesday 21st April 2021 5:39am I never considered the Stretch option, so I tried it now.
I thought the following code could get a ‘stretched’ Image into a control, also in one that only accepts Pictures. Problem solved? NO.
The code runs without errors, but the result is just an empty black graphic.
I am obviously forgetting something or getting it completely wrong :cry:
You need PictureBox1 and Button1
' Gambas class file
Private MyGraphic As Image

Public Sub Form_Open()
MyGraphic = New Image(250, 200, False)
MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
MyGraphic.Stretch(Button1.width, Button1.height)
PictureBox1.Image = MyGraphic
Button1.picture = MyGraphic.picture
End
the stretch command "Returns" the new image it looks like you want full size image for picturebox and stretched image for button

maybe this (or something like it)..
Public Sub Form_Open()
MyGraphic = New Image(250, 200, False)
MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic

PictureBox1.Image = MyGraphic
Button1.picture = MyGraphic.Stretch(Button1.width, Button1.height).Picture
End

Re: Vector graphics support ?

Posted: Wednesday 21st April 2021 2:30pm
by Doctor Watson
Nope. Still black is black.
Tried with other graphics formats as well.
Sigh :(