我有一种操作Blackberry照片的方法。我目前循环所有像素并更改原始图像中的RGB值。这主要是为了练习C++
和Blackberry 10
。但是,这有些慢。我想知道是否有更好的方法(时间和空间的复杂性)?
代码:
void PhotoBomberApp::manipulatePhoto2(const QString &fileName)
{
QImageReader reader;
// Set image name from the given file name.
reader.setFileName(fileName);
QImage image = getRotateImage(fileName); //reader.read();
QSize imageSize = image.size();
QColor color;
for (int i = 0; i < imageSize.width(); i++)
for (int ii = 0; ii < imageSize.height(); ii++) {
color = QColor(image.pixel(i, ii));
if(color.green() > 0 && color.green() > color.red() && color.green() != 255)
color.setGreen(0);
if(color.blue() > 0 && color.blue() > color.red() && color.blue() != 255)
color.setBlue(0);
image.setPixel(i, ii, color.rgb());
}
// Paint an image on top of another image, so we add the gray-scaled image first.
QPainter merger(&image);
QString appFolder(QDir::homePath());
appFolder.chop(4);
// Save the image.
image.save(fileName, "JPG");
// Show the photo by using this function that take use of the InvokeManager.
showPhotoInCard(fileName);
}