Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 通过移动滑块撤消qt中的setPixel操作_C++_Qt_Pixel_Undo_Image Viewer - Fatal编程技术网

C++ 通过移动滑块撤消qt中的setPixel操作

C++ 通过移动滑块撤消qt中的setPixel操作,c++,qt,pixel,undo,image-viewer,C++,Qt,Pixel,Undo,Image Viewer,我在qt中有一个加载图像的应用程序。用户可以通过使用setPixel()移动滑块来设置十字。如果他减少滑块,十字应该变小,并且应该显示原始像素 但不幸的是,当我减小滑块时,什么也没有发生。十字架保持其最大尺寸 设置像素的函数 void ImageViewer::applyExampleAlgorithm(int kreuzBreite) { if(image!=NULL) { for(int i=0;i<((kreuzBreite*s

我在qt中有一个加载图像的应用程序。用户可以通过使用setPixel()移动滑块来设置十字。如果他减少滑块,十字应该变小,并且应该显示原始像素

但不幸的是,当我减小滑块时,什么也没有发生。十字架保持其最大尺寸

设置像素的函数

    void ImageViewer::applyExampleAlgorithm(int kreuzBreite)
{
    if(image!=NULL)
    {
       
        for(int i=0;i<((kreuzBreite*std::min(image->width(), image->height())/ 100) / 2);i++)
        {
                         image->setPixelColor(image->width()/2+i,image->height()/2,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2-i,image->height()/2,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2,image->height()/2+i,QColor(255,0,0,0));
                         image->setPixelColor(image->width()/2,image->height()/2-i,QColor(255,0,0,0));
            } 
                      }

updateImageDisplay();
    renewLogging();
    }

正如你所看到的,值改变了,但我的十字架没有改变


我想我必须保存原始像素并重写它,只要此时红十字消失。但是我真的不知道怎么做。

当滑块值减小时,您的函数只会在之前绘制的较大的红十字中“绘制”一个较小的红十字。可以将原始图像存储在不同的变量中。然后,在绘制红十字之前,恢复到原始图像。

不客气。请考虑投票并正确回答。
QSlider *slider1 = new QSlider(Qt::Horizontal,0);
    slider1->setRange(0,100);
    connect(slider1, SIGNAL(valueChanged(int)),this, SLOT(applyExampleAlgorithm(int)));