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.
Vector graphics support ?
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Vector graphics support ?
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Vector graphics support ?
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.
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Vector graphics support ?
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.
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.
You eat an elephant one small bite at a time.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Vector graphics support ?
there is an SvgImage.classdr watson wrote: Unfortunately the result is not what I hoped for, namely that such vector graphics would adapt automatically to their container’s size –
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
BruceS
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Vector graphics support ?
OK Bruce, I'll have a go at it.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Vector graphics support ?
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.
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.
![Confused :?](./images/smilies/icon_e_confused.gif)
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.
You eat an elephant one small bite at a time.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Vector graphics support ?
Aah sorry dude i thought that might be the answer.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.It would have been usefull if it worked ...
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")
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
BruceS
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Vector graphics support ?
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
You need PictureBox1 and Button1
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
![Crying or Very Sad :cry:](./images/smilies/icon_cry.gif)
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.
You eat an elephant one small bite at a time.
- BruceSteers
- Posts: 1578
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Vector graphics support ?
the stretch command "Returns" the new image it looks like you want full size image for picturebox and stretched image for buttonDoctor 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![]()
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
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
BruceS
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: Vector graphics support ?
Nope. Still black is black.
Tried with other graphics formats as well.
Sigh![Sad :(](./images/smilies/icon_e_sad.gif)
Tried with other graphics formats as well.
Sigh
![Sad :(](./images/smilies/icon_e_sad.gif)
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.