Вопрос

Hi I'm trying to write BMP reader writer in ruby and now i'm stuck on write it on screen. I have picture stored in pixels array and on every pixel is stored rgb color. But nothing happens in in window? What I'm doing wrong? Or is there any qt object to which i can stored pixel data and simply paint it?

def initialize
    super

    setWindowTitle "Transparent rectangles"

    resize 590, 90
    move 300, 300

    show
end

def paintEvent event

      painter = Qt::Painter.new self
      bmp = BMP::Reader.new("picture.bmp")
      drawPicture(painter,bmp.getPixels())
      painter.end
end


def drawPicture(painter, pixels)

    painter.setPen Qt::NoPen
      0.upto(pixels.length-1) do |i|
        0.upto(pixels[0].length-1) do |j|
          painter.setBrush Qt::Brush.new Qt::Color.new pixels[i][j][2], pixels[i][j][1], pixels[i][j][0], 255
          painter.drawPoint(i,j)
        end
      end
end
Это было полезно?

Решение

QPainter.drawPoint uses the current pen, not the brush. Call painter.setPen before each point.

But you would be much better off storing the pixels in a QImage. Qt already has support for reading BMP files so there's no need to implement that yourself unless you have a good reason to.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top