Vector graphics support ?

Ask about the individual Gambas components here.
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Vector graphics support ?

Post 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.
Old african saying:
You eat an elephant one small bite at a time.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Vector graphics support ?

Post 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.
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: Vector graphics support ?

Post 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.
Old african saying:
You eat an elephant one small bite at a time.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Vector graphics support ?

Post 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)
If at first you don't succeed , try doing something differently.
BruceS
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: Vector graphics support ?

Post by Doctor Watson »

OK Bruce, I'll have a go at it.
Old african saying:
You eat an elephant one small bite at a time.
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: Vector graphics support ?

Post 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 ...
Old african saying:
You eat an elephant one small bite at a time.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Vector graphics support ?

Post 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
If at first you don't succeed , try doing something differently.
BruceS
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: Vector graphics support ?

Post 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
Old african saying:
You eat an elephant one small bite at a time.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Vector graphics support ?

Post 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
If at first you don't succeed , try doing something differently.
BruceS
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: Vector graphics support ?

Post by Doctor Watson »

Nope. Still black is black.
Tried with other graphics formats as well.
Sigh :(
Old african saying:
You eat an elephant one small bite at a time.
Post Reply