Хорошо, поэтому я работаю над программой на C ++, которая должна выполнять следующее:
реализует 4 функции, которые редактируют пиксели, полученные из данных изображений:
Одна, которая создает и сохраняетновое изображение с инвертированными цветами данного изображения.
Тот, который создает и сохраняет монохромную версию данного изображения в градациях серого.
Тот, который создает и сохраняет новое изображение, которое объединяет два заданных изображения на основена извлеченном альфа-значении (прозрачность).
Тот, который создает и сохраняет желтую версию изображения.
Я сделал 2 функции (версия в оттенках серого и желтая версия), но яне уверен, как сделать последние два. Есть ли способ изменить мои первые две функции, чтобы создать инвертированные изображения или объединить два изображения? Вот мой код:
void makeYellowImage(QImage originalImage)
/*
* Copy the given image and make a new one filled with yellow.
* This function is an example of how to access and set pixels of a QImage.
* Input: A QImage object of some loaded image.
* Output: None; the new image is saved to a file named "yellow."
*/
{
QImage yellowImage = originalImage; // Copies the original image into a new QImage object.
QColor origPixel, newPixel;
int width;
int height;
// Retrieve the dimensions of the image with the width() and height() methods.
width = originalImage.width();
height = originalImage.height();
// Iterate over the pixels of the image, for each row and column per row.
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
// This function call retrieves a pixel with RGBA values from the original image.
// You can print out values by uncommenting the printf() commands.
origPixel = getRgbaPixel(col, row, yellowImage);
printf("Red: %d, Green: %d, Blue: %d, Alpha: %d\n",
origPixel.red(), origPixel.green(), origPixel.blue(), origPixel.alpha());
// Get a pixel ready with yellow with no transparency.
newPixel.setRgb(255, 255, 0);
newPixel.setAlpha(255);
// Use that pixel's RGBA channels to write to a pixel location in the new image.
yellowImage.setPixel(col, row, newPixel.rgba());
}
}
yellowImage.save("../Images/yellow.png");
}
void makeGreyscaleImage (QImage originalImage)
{
QImage grayImage = originalImage;
QColor origPixel, newPixel;
int width;
int height;
width = originalImage.width();
height = originalImage.height();
// Iterate over the pixels of the image, for each row and column per row.
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
// This function call retrieves a pixel with RGBA values from the original image.
origPixel = getRgbaPixel(col, row, grayImage);
//printf("Red: %d, Green: %d, Blue: %d, Alpha: %d\n",
//origPixel.red(), origPixel.green(), origPixel.blue(), origPixel.alpha());
// Get a pixel ready with yellow with no transparency.
newPixel.setRgb(0, 0, 0);
newPixel.setAlpha(255);
// Use that pixel's RGBA channels to write to a pixel location in the new image.
grayImage.setPixel(col, row, newPixel.rgba());
}
}
grayImage.save("../Images/greyscale.png");
}