Version

Goal:Save a picture
Difficulty:Beginner
Duration:5 minutes
Language:Python

Calling SavePicture before LoadPlugins will fail.

Note: For a list of the available output codecs and the parameters they take see [PictureIO].

# Load a picture and save it as JPEG

import os
import harfang as hg

hg.LoadPlugins()

# mount the system file driver
hg.MountFileDriver(hg.StdFileDriver())

# load picture
pic = hg.Picture()
ok = hg.LoadPicture(pic, "../_data/owl.jpg")

# IJG codec can only save RGB8
pic.Convert(hg.PictureRGB8)

# save as JPEG in the same folder (quality set to 20%)
hg.SavePicture(pic, "save.jpg", "IJG", "q:20")