Access and change rgb values of pixels
Contents
[
Hide
]
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 :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.FileFormats.Tiff; | |
using Aspose.Imaging.FileFormats.Tiff.Enums; | |
using Aspose.Imaging.ImageOptions; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
using (TiffImage image = (TiffImage)Image.Load(dataDir + "template.tiff")) | |
{ | |
Color[] colors = image.LoadPixels(image.Bounds); | |
int length = colors.Length; | |
for (int i = 0; i < length; i++) | |
{ | |
if (i % 2 == 0) | |
{ | |
colors[i] = Color.Red; | |
} | |
} | |
image.SavePixels(image.Bounds, colors); | |
image.Save(dataDir + "result.png", new PngOptions()); | |
} | |
File.Delete(dataDir + "result.png"); |