Foto’s (of andere beelden) vergroten of verkleinen

Om later eens te gebruiken …

Ik vond in een voorbeeld app in Gambas volgend stukje code:

Public Sub Add(ImagePath As String)
Dim img As Image
Dim newPicture As Result
'Dim pictureData As String
Dim scale As Float
Dim eTime As Float
newPicture = databaseConnection.Create("pictures")
' Save temp image as png file
img = Image.Load(ImagePath)
img.Save(tempFile)
newPicture["image"] = File.Load(tempFile)
' Create image thumb
If img.Width > thumbSize Or img.Height > thumbSize Then
' Calc factor to scale isotropic
scale = Min(ThumbSize / img.Width, ThumbSize / img.Height)
img = img.Stretch(img.Width * scale, img.Height * scale)
img.Save(tempFile)
End If
newPicture["thumb"] = File.Load(tempFile)
' Add description and update
newPicture["description"] = "Image " & File.BaseName(ImagePath) & " added: " & Format(Now, "dddd, dd mmmm yyyy hh:nn:ss")
eTime = Timer
newPicture.Update()
Print "Done in "; Format(Timer - eTime, "#.###"); " s"
If Exist(tempFile) Then Kill tempFile
Catch
Error.Raise("Add database record error


Error:
" & DConv(Error.Text))
End

This entry was posted in Gambas3, Hoe - in Gambas. Bookmark the permalink.