Results 1 to 3 of 3

Thread: Copy to a memory image png or bmp

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Copy to a memory image png or bmp

    Hello everyone, I have an image assets / stall.png where asset is a directory located under the root of my program. I would like to copy my image in memory starting from img_flip.
    This is the code that I wrote:
    Qt Code:
    1. QImage img;
    2. img.load(filename);
    3. if (img.isNull())
    4. {
    5. printf( "unable to open image: %s\n", filename );
    6. return 0;
    7. }
    8.  
    9. QImage gldata = QGLWidget::convertToGLFormat(img);
    10. uchar *pixels = (uint8_t *)gldata.bits();
    11.  
    12. //vertically flip the image
    13. int img_size = gldata.width() * gldata.height() * gldata.depth();
    14. uint8_t *img_flip = new uint8_t[ img_size ];
    15.  
    16. const int row_width = gldata.width() * gldata.depth();
    17.  
    18. for( int i = 0; i < gldata.height(); i++ )
    19. memcpy( img_flip + ( i * row_width ), pixels + ( (gldata.height() - i - 1) * row_width ),
    20. row_width );
    To copy to clipboard, switch view to plain text mode 
    I must have made a mistake because the execution stops after copying with i = 7.
    Can you help me fix my error ?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Copy to a memory image png or bmp

    gldata.depth(); return the size in bit(s), so you will have to use gldata.depth()/8 for size in byte. Also bit depth 1 has to taken are of.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Copy to a memory image png or bmp

    Thanks Santosh Reddy

Similar Threads

  1. Qwebview Copy Text And Save Image
    By ShapeShiftme in forum Qt Programming
    Replies: 4
    Last Post: 11th August 2016, 06:30
  2. How can I copy image from anohter image
    By chong_kimkeang in forum Newbie
    Replies: 12
    Last Post: 27th September 2012, 11:05
  3. Image: out of memory, returning null image
    By darek_hecpl in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd September 2010, 13:48
  4. Replies: 1
    Last Post: 29th November 2009, 20:33
  5. How to copy sellected ellipse area from image
    By adamsakli in forum Newbie
    Replies: 2
    Last Post: 24th September 2009, 22:11

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.