嗨,我正在尝试用 ruby 编写 BMP 阅读器,现在我被困在屏幕上。我将图片存储在像素数组中,并且每个像素都存储 rgb 颜色。但是在窗口中什么都没有发生?我做错了什么?或者是否有任何 qt 对象可以存储像素数据并简单地绘制它?
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