PDA

View Full Version : problem with setPixel



sar_van81
2nd February 2007, 06:01
hi...

i have a problem with QImage.setPixel() function. i used it as follows:
QImage img(100,100,32);
for (int i = 0; i <x; i++ )
{
for (int j = 0; j <y; j++ )
{
QRgb pixel;
pixel = qRgb(255,0,255);
image.setPixel( i, j, pixel );
}
}

. when i draw this image using painter. it plots the colour in the pixel.this is fine,but when i give rgb values from a buffer. it does not draw well. i did is this: i opened a BMP file read only the RGB datas (reading the image after 54 bytes.i.e after the headers ). i store them in an array. when i feed them to the qRgb function and draw image, the pixel values are not alligned propeerly.there is a offset between the each row.also the image
is rotated right.

can anyone say me why is this..? i used the same function and same for loop.but only the values are different.Instead of a particular RGB value, i give it from a buffer.

am i missing something else ...? is this correct way..?

thanks in advance

ChristianEhrlicher
2nd February 2007, 07:35
1. Please use code tags so we can read your code better
2. When you really want to read out bmp by your own (don't know why you need this, Qt can do this for you) you should inform you about the bmp-format. It's not just a sequence of pixel values. There are also fill bytes to align the lines on a 4(?) byte boundary.

sar_van81
2nd February 2007, 08:58
hi..

my requirement is that if i recieve some RGB datas from some external devices, I should be able to plot them on a widget and display them on the screen.for that i first try with the RGB datas from an image file. thats all i have to do.

i had read from the file and stored in a temproray buffer,but the plotting is not perfect.

Any suggestions or solutions....?

ChristianEhrlicher
2nd February 2007, 09:07
As I said - bmp is not only an array of pixels - there are also fill bytes for aligment. You *have* to know your format you want to read. If the format from your external device is a bmp, you can use QImage to read it, if it's in another (unsupported) format, you have to read the specs of the format and write your own import function

sar_van81
2nd February 2007, 10:27
hi...

i accept what you say.if i want to display the incoming datas then by adding a valid header and just feed the whole buffer(header + incoming RGB datas) to loadFromData function, then this will work. no problem in that. but if i need to process RGB datas(such as threashold value or interpolation etc) and then display it , is there any need for header there...?... my question is that the function QRgb qRgb ( int r, int g, int b ) in QColor class just require raw r,g,b data and construct the pixel. what if the raw datas come from the bitmap image data....?

is my understanding correct...? or have i left any information...?

ChristianEhrlicher
2nd February 2007, 10:39
my question is that the function QRgb qRgb ( int r, int g, int b ) in QColor class just require raw r,g,b data and construct the pixel. what if the raw datas come from the bitmap image data....?

It works, as long as you read the pixel data from the bitmap correct. And you don't do that because you did not take a look into the bmp defintion. When you would do this (e.g here: http://en.wikipedia.org/wiki/Windows_bitmap#Bitmap_data) you would see that you can't access a bmp by lpBMPData[x][y] !
But I said this already in my first post.

wysota
2nd February 2007, 11:16
Just for the record, this thread is related with this one (http://www.qtcentre.org/forum/f-qt-programming-2/t-how-to-use-loadfromdata-in-painter-5298.html). Some of the issues have already been discussed there, so maybe there is no point in repeating it here.