Access and change rgb values of pixels

Access and change rgb values of pixels

Issue : Access and change rgb values of pixels.

Tips : To access and change rgb values of pixels there can be used LoadPixels method.

Example :

import aspose.pycore as aspycore
from aspose.imaging import Image, Color
from aspose.imaging.fileformats.tiff import TiffImage
from aspose.imaging.imageoptions import PngOptions
import os
if 'TEMPLATE_DIR' in os.environ:
templates_folder = os.environ['TEMPLATE_DIR']
else:
templates_folder = r"C:\Users\USER\Downloads\templates"
delete_output = 'SAVE_OUTPUT' not in os.environ
data_dir = templates_folder
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.tiff")), TiffImage) as image:
colors = image.load_pixels(image.bounds)
length = colors.length
for i in range(length):
if i % 2 == 0:
colors[i] = Color.red
image.save_pixels(image.bounds, colors)
image.save(os.path.join(data_dir,"result.png"), PngOptions())
if delete_output:
os.remove(os.path.join(data_dir,"result.png"))