Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] Help in Creating Indexed8 image from a buffer

    General and Desktop
    3
    8
    2042
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xenonforlife last edited by

      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(xy);
      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.

      1 Reply Last reply Reply Quote 0
      • X
        xenonforlife last edited by

        oh no my code lost all its formatting...its not even readable now!!

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

          [quote author="xenonforlife" date="1334582807"]oh no my code lost all its formatting...its not even readable now!!
          [/quote]

          hit the edit link on the right of it and add the @-tags, that adds formatting to your code.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply Reply Quote 0
          • X
            xenonforlife last edited by

            I have updated the code so that it is more readable...I hope someone can help me!!

            1 Reply Last reply Reply Quote 0
            • G
              goetz last edited by

              If you had removed the whitespace on the beginning of the lines it would be even more readable...

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply Reply Quote 0
              • X
                xenonforlife last edited by

                That too is done now...hope someone knows about this issue!!

                1 Reply Last reply Reply Quote 0
                • X
                  xenonforlife last edited by

                  figured it out on my own. Thanks

                  1 Reply Last reply Reply Quote 0
                  • M
                    mlong last edited by

                    What was the solution? (In case others with the same issue read this thread in the future.)

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post