void MainWindow::on_pushButton_clicked() { //创建一个绘图设备,QImage::Format_ARGB32背景是透明 QImage image(400,300,QImage::Format_ARGB32); image.fill(Qt::red); //对绘图设备前50个像素点进行操作 // for(int i = 0; i < 50;i++) // { // for(int j = 0; j < 50;j++) // { // image.setPixel(QPoint(i,j), qRgb(0,255,0) ); // } // } //通过bit的方式 来修改像素 int r = 30, ox = 50, oy = 50; QRgb *pixs = (QRgb*)image.bits(); //int W = (image.width() + 3) / 4 * 4; //pixs[i * W + j] = qRgb(0, 0, 255); QRgb fg = qRgb(0, 0, 255); *pixs = fg; for (int i=0;i<30;i++) { *pixs = fg; pixs++; } // int W = image.width(); // for (int i=60;i<=80;i++) // { // for (int j=0;j<30;j++) // { // *pixs = fg; // pixs++; // } // pixs+=W; // } //使用QPixmap来呈现QImage图片 QPixmap mp; mp = mp.fromImage(image); ui->label->clear(); ui->label->setPixmap(mp); }

浙公网安备 33010602011771号