Resize a picture

Post your Gambas programming questions here.
Post Reply
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Resize a picture

Post by cogier »

Can anybody tell me how to resize a picture without using a Shell command?

 Shell "convert pict.png -resize 100x100 /tmp/pict.png" Wait
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: Resize a picture

Post by PJBlack »

picturebox with stretch = true ???

otherwise ... the image class has a function called stretch
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Resize a picture

Post by cogier »

I am aware of 'Stretch'. Much better to use Mode than stretch.

What I am doing gets a picture to line up with a GridView when being dragged. Below you can see it works. This allows me to resize the form and the image still lines up, so it needs to be exact. So sorry, 'Stretch' doesn't cut it!

ImageImage
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: Resize a picture

Post by Cedron »

Does this "stretch" work for you? It seems to do what your shell command intends. (I just noticed PJBlack's second line, so here is an example.)

Ced

'=============================================================================
Public Sub Main()

        Dim P As Image = Image.Load("~/Pictures/Wallpaper1920/DogOnDock.JPG")
        
        Dim I As Image = P.Stretch(200, 200)

        I.Save("DoD.jpg")      

End
'=============================================================================
.... and carry a big stick!
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Resize a picture

Post by BruceSteers »

cogier wrote: Friday 25th November 2022 2:58pm Can anybody tell me how to resize a picture without using a Shell command?

 Shell "convert pict.png -resize 100x100 /tmp/pict.png" Wait
Image.Stretch


Dim hPic as Picture = Picture.Load(sMyPic)  ' original size

Dim hPicStretched As Picture = hPic.Image.Stretch(100,100).Picture ' resized picture


If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Resize a picture

Post by cogier »

Opps, sorry PJBlack. You were right, as is everybody else as well. It works like a charm.

Reminder, I must read posts more carefully! :?
Post Reply