Vector graphics support ?
Posted
#1
(In Topic #639)
Regular

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.
You eat an elephant one small bite at a time.
Posted
Guru

Posted
Regular

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.
Posted
Guru

dr watson said
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)
Posted
Regular

Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Regular

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.
Code (gambas)
- '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
- 'But this doesn't resize at all, it 'Crops'
- MyImage.Clear
- MyImage.Resize(100, 50)
- 'is just the same as
- MyImage.Clear
- MyImage.width = 100
- MyImage.Height = 50
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.
Posted
Guru

Doctor Watson said
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.Code (gambas)
'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 'But this doesn't resize at all, it 'Crops' MyImage.Clear MyImage.Resize(100, 50) 'is just the same as MyImage.Clear MyImage.width = 100 MyImage.Height = 50
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
Posted
Regular

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
Code (gambas)
- ' Gambas class file
- MyGraphic.Stretch(Button1.width, Button1.height)
- PictureBox1.Image = MyGraphic
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

Doctor Watson said
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 Button1Code (gambas)
' Gambas class file MyGraphic.Stretch(Button1.width, Button1.height) PictureBox1.Image = MyGraphic
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)..
Posted
Regular

Tried with other graphics formats as well.
Sigh
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Enthusiast

Posted
Regular

I already tried that and even a whole new project.
Same - negative - result.
To all : I'll be away for a couple of days.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

Code (gambas)
- ' Gambas class file
Posted
Guru

I see it like if I have a Picture and I look at it then i have an "Image" of that "Picture" in my head
But the "picture" is the real thing while the "image" is not
Or maybe I can get an "Image" of something in my head and make a "Picture" from it. but the "Image" is not real only the "Picture" is once drawn.
hmm , like i say , it's hard to explain.
Suffice to say , Use the "Picture" property/class for final image rendering and the "Image" property to manipulate (colour/stretch/etc)
Posted
Regular

There is unfortunately almost nothing to be found on how to use ‘stretch’ in the Gambas documentation, certainly no example code.
Now that the right way of using the ‘stretch’ property has been found, I’d like to explain why I wanted to be able to use vector graphics. I’ll put it in a post in the General section, so perhaps others may benefit.
P.S. I just came across what looks to me like the best Gambas manual till now. It’s in German, but the authors are working on an English translation. Certainly well worth it to pay a visit.
start [GAMBAS BOOK 3.19.5]. It has some examples on ‘stretch’.
Have a nice weekend.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Regular

Code
Gambas class file
Public Sub Form_Open()
Dim pic As Picture
pic = Image.Load("./pg.svg").Stretch(PictureBox1.w, PictureBox1.h).Picture
PictureBox1.Picture = pic
End
Public Sub PictureBox1_MouseDown()
Me.Close()
EndIn this example (sent to me) the file pg.svg is loaded and stretched to the size of the picturebox automatically. This works out very well for stationary SVG… but playing around in HTML a long time ago I discovered that if I named something like "pointer" in the drawing… I could then assign it an angular rotation or movement and do all sorts of things with it. I'm wondering now if once an image is loaded… can I somehow manipulate the object? If so… I can make some incredible gauges and displays.
Check these out… steal the code… see what you can do with it… but if you get something to work in Gambas… please share!
SVG Experiments
Jerry
Posted
Guru

Code (gambas)
- PictureBox1 As PictureBox
- .Height = 400
- .Width = 500
- .Padding = 5
- .Arrangement = Arrange.Vertical
- .Center
- .Alignment = Align.Center
Regarding a 'gauge' have a look at the code here.
Tip: - When adding Gambas code on this site use the gb button for results similar to the above.
<IMG src="https://www.cogier.com/gambas/gb.png">
</IMG>
1 guest and 0 members have just viewed this.


