Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Help in Creating Indexed8 image from a buffer
QtWS25 Last Chance

[SOLVED] Help in Creating Indexed8 image from a buffer

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.4k Views
  • 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 Offline
    X Offline
    xenonforlife
    wrote on last edited by
    #1

    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
    0
    • X Offline
      X Offline
      xenonforlife
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        [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
        0
        • X Offline
          X Offline
          xenonforlife
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            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
            0
            • X Offline
              X Offline
              xenonforlife
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xenonforlife
                wrote on last edited by
                #7

                figured it out on my own. Thanks

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved