我写了一些代码,应该使一个新的形象。我的背景图像有黑色区域,当for循环出现黑色像素时,它应该在新图像中绘制蓝色区域,否则应该绘制原始像素。以为我可以这样做,但程序不断运行。Qt绘制一个蓝色的像素,如果原始像素是在一个新的图像黑色
QApplication a(argc, argv);
int c, m, y, k, al;
QColor color;
QColor drawColor;
QImage background;
QImage world(1500, 768, QImage::Format_RGB32);
QSize sizeImage;
int height, width;
background.load("Background.jpg");
world.fill(1);
QPainter painter(&background);
sizeImage = background.size();
width = sizeImage.width();
height = sizeImage.height();
for(int i = 0; i < height; i++)
{
for(int z = 0; z < width; z++)
{
color = QColor::fromRgb (background.pixel(i,z));
color.getCmyk(&c,&m,&y,&k,&al);
if(c == 0 && m == 0 && y == 0 && k == 0) //then we have black as color and then we draw the color blue
{
drawColor.setBlue(255);
painter.setPen(drawColor);
painter.drawPoint(i,z);
}
}
}
//adding new image to the graphicsScene
QGraphicsPixmapItem item(QPixmap::fromImage(background));
QGraphicsScene* scene = new QGraphicsScene;
scene->addItem(&item);
QGraphicsView view(scene);
view.show();
是我的循环错误还是我的画家?它是QImage :: pixel:坐标(292,981)超出范围,但对于很多像素来说,它的速度还不够快。
你是什么意思的“程序继续运行”?它永远不会出现for循环?你没有得到你期望的结果? – Bart 2012-02-16 13:06:16
仅仅是因为循环速度非常慢?在我看来,通过读取和写入像这样的单个像素来转换大图像会稍微滞后! – Robinson 2012-02-16 13:14:41
那么什么是更好的方法?我想也许只是重新绘制蓝色像素,但我不知道如何在图像上循环。 – user1007522 2012-02-16 13:27:40