PDA

View Full Version : [SOLVED] Cannot create Indexed8 image from buffer



xenonforlife
23rd April 2012, 09:57
Hi,

I am having trouble creating image of the format Indexed8 from a buffer that I have defined…my code is as follows:-

my_buffer= (uchar*)malloc(x*y);
for(i=0;i<x*y;i++)
my_buffer[i]=(uchar)qrand()%(255);

img= new QImage(my_buffer,x,y,QImage::Format_Indexed8);


for(int i=0;i<256;i++)
{
colors.append());
}

img.setColorTable(colors);
scene = new QGraphicsScene;
img3=img.scaledToWidth(500);
pix=QPixmap::fromImage(img3);
item= new QGraphicsPixmapItem(pix);
scene->addItem(item);
view=new QGraphicsView(scene);
view->show();
When I execute this piece of code I can just see a black image. Can someone please help me out what am I doing wrong? here colors is a QVector.

xenonforlife
23rd April 2012, 12:53
figured it out on my own.