Results 1 to 2 of 2

Thread: [SOLVED] Cannot create Indexed8 image from buffer

  1. #1
    Join Date
    Jan 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default [SOLVED] Cannot create Indexed8 image from buffer

    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.
    Last edited by xenonforlife; 23rd April 2012 at 13:56.

  2. #2
    Join Date
    Jan 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default [SOLVED] Cannot create Indexed8 image from buffer

    figured it out on my own.

Similar Threads

  1. Replies: 0
    Last Post: 24th January 2011, 12:12
  2. Create Transparent PNG Image
    By hvitual in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2009, 15:35
  3. Replies: 1
    Last Post: 1st February 2009, 00:00
  4. Replies: 2
    Last Post: 29th September 2008, 01:08
  5. OpenGL show image from buffer memory leak[SOLVED]
    By ^NyAw^ in forum Qt Programming
    Replies: 0
    Last Post: 30th January 2008, 17:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.