Vector graphics support ?

Post

Posted
Rating:
#1 (In Topic #639)
Regular
Doctor Watson is in the usergroup ‘Regular’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
Doctor Watson is in the usergroup ‘Regular’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘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)
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
Doctor Watson is in the usergroup ‘Regular’
 OK Bruce, I'll have a go at it.

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
Doctor Watson is in the usergroup ‘Regular’
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)

  1. Dim MyImage As SvgImage
  2. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  3.  
  4. 'This works - source gb.qt4
  5. Paint.Begin(MyImage)
  6. Paint.Brush = Paint.RadialGradient(200, 140, 40, 215, 115, [Color.RGB(255, 0, 0, 64), Color.White], [1.0, 0.1])
  7. Paint.Arc(200, 140, 40)
  8. Paint.Fill
  9. Paint.End
  10. 'Result: A Union Jack with a red ball in it
  11. MyImage.Save(Application.path & "/SVG/Flag_UK_RedBall.svg")
  12.  
  13. 'But this doesn't resize at all, it 'Crops'
  14. MyImage.Clear
  15. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  16. MyImage.Resize(100, 50)
  17. MyImage.Save(Application.path & "/SVG/Flag_UK_Resize.svg")
  18. 'is just the same as
  19. MyImage.Clear
  20. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  21. MyImage.width = 100
  22. MyImage.Height = 50
  23. 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.
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘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)

  1. Dim MyImage As SvgImage
  2. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  3.  
  4. 'This works - source gb.qt4
  5. Paint.Begin(MyImage)
  6. Paint.Brush = Paint.RadialGradient(200, 140, 40, 215, 115, [Color.RGB(255, 0, 0, 64), Color.White], [1.0, 0.1])
  7. Paint.Arc(200, 140, 40)
  8. Paint.Fill
  9. Paint.End
  10. 'Result: A Union Jack with a red ball in it
  11. MyImage.Save(Application.path & "/SVG/Flag_UK_RedBall.svg")
  12.  
  13. 'But this doesn't resize at all, it 'Crops'
  14. MyImage.Clear
  15. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  16. MyImage.Resize(100, 50)
  17. MyImage.Save(Application.path & "/SVG/Flag_UK_Resize.svg")
  18. 'is just the same as
  19. MyImage.Clear
  20. MyImage = SvgImage.Load(Application.path & "/SVG/Flag_UK.svg")
  21. MyImage.width = 100
  22. MyImage.Height = 50
  23. 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
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
Doctor Watson is in the usergroup ‘Regular’
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

Code (gambas)

  1. ' Gambas class file
  2. Private MyGraphic As Image
  3.  
  4. Public Sub Form_Open()
  5. MyGraphic = New Image(250, 200, False)
  6. MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
  7. MyGraphic.Stretch(Button1.width, Button1.height)
  8. PictureBox1.Image = MyGraphic
  9. Button1.picture = MyGraphic.picture

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘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 Button1

Code (gambas)

  1. ' Gambas class file
  2. Private MyGraphic As Image
  3.  
  4. Public Sub Form_Open()
  5. MyGraphic = New Image(250, 200, False)
  6. MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
  7. MyGraphic.Stretch(Button1.width, Button1.height)
  8. PictureBox1.Image = MyGraphic
  9. Button1.picture = MyGraphic.picture

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)..

Code (gambas)

  1. Public Sub Form_Open()
  2. MyGraphic = New Image(250, 200, False)
  3. MyGraphic.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
  4.  
  5. PictureBox1.Image = MyGraphic
  6. Button1.picture = MyGraphic.Stretch(Button1.width, Button1.height).Picture
Online now: No Back to the top

Post

Posted
Rating:
#10
Regular
Doctor Watson is in the usergroup ‘Regular’
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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
have had the same problem with picturebox ... picture inverse und form black on black ... problem was solved by creating a new form ...
Online now: No Back to the top

Post

Posted
Rating:
#12
Regular
Doctor Watson is in the usergroup ‘Regular’
Hi PJBlack
I already tried that and even a whole new project.
Same - negative - result.

To all : I'll be away for a couple of days. :D

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#13
Guru
BruceSteers is in the usergroup ‘Guru’
I also have issues using Image  but not using Picture

Code (gambas)

  1.  
  2. ' Gambas class file
  3. Private MyGraphic As Picture
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   MyGraphic = Picture.Load(Application.path & "/GB_FLAG.svg") 'or take any other graphic
  8.  
  9.   PictureBox1.Picture = MyGraphic.Image.Stretch(PictureBox1.W, PictureBox1.H).Picture
  10.   Button1.Picture = MyGraphic.Image.Stretch(Button1.W, Button1.H).Picture
  11.  
  12.  
  13.  
Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘Guru’
 There's a big difference between an Image and a Picture that is hard to explain.

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)
Online now: No Back to the top

Post

Posted
Rating:
#15
Regular
Doctor Watson is in the usergroup ‘Regular’
Congratulations Bruce! That one needed some thinking over indeed.
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.
Online now: No Back to the top

Post

Posted
Rating:
#16
Avatar
Regular
Askjerry is in the usergroup ‘Regular’
I was playing with SVG in Gambas and the images look stunning. I can create nice gradients and such that always look nice.

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()
End

In 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
Online now: No Back to the top

Post

Posted
Rating:
#17
Avatar
Guru
cogier is in the usergroup ‘Guru’
Try the code below, then resize the form. I think the PictureBox.Mode command is quite powerful and under used. I wrote the help for it here.  

Code (gambas)

  1. PictureBox1 As PictureBox
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   With Me
  6.     .Height = 400
  7.     .Width = 500
  8.     .Padding = 5
  9.     .Arrangement = Arrange.Vertical
  10.     .Center
  11.  
  12.   With PictureBox1 = New PictureBox(Me) As "PictureBox1"
  13.     .Expand = True
  14.     .Alignment = Align.Center
  15.     .Mode = PictureBox.Contain
  16.     .Picture = Picture["./pg.svg"]
  17.  
  18.  
  19. Public Sub PictureBox1_MouseDown()
  20.  
  21.   Me.Close()
  22.  

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>
Online now: No Back to the top
1 guest and 0 members have just viewed this.