Results 1 to 2 of 2

Thread: Convert 8bpp Image to Qimage

  1. #1
    Join Date
    May 2017
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Convert 8bpp Image to Qimage

    I had a program i originally wrote in C#, but I need it to run on linux now. So I've been porting it to c++ to use the QT GUI. It's almost done say for 1 thing. I have a few biometeric libraries (fingerprint, palm, and facial) that are used for authentication.

    I have those 3 working for the most part. One thing I do in the c# version is show the captured image from the biometeric readers. Problem is I really suck and Image processing and converting formats. Both the Palm and Fingerprint scanners return a raw 8bpp image (no headers). Where as the Facial recognition library is a Jpeg format.

    In my c# version I convert the 8bpp images to jpegs using this function:
    Qt Code:
    1. public byte[] CreateRawJpegFrom8BPP(byte[] bytes, int width, int height)
    2. {
    3. byte[] rgbBytes = new byte[bytes.Length * 3];
    4.  
    5. for (int i = 0; i <= bytes.Length - 1; i++)
    6. {
    7. rgbBytes[(i * 3)] = bytes[i];
    8. rgbBytes[(i * 3) + 1] = bytes[i];
    9. rgbBytes[(i * 3) + 2] = bytes[i];
    10. }
    11. Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
    12.  
    13. BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
    14.  
    15. for (int i = 0; i <= bmp.Height - 1; i++)
    16. {
    17. long s = data.Scan0.ToInt64();
    18. int l = data.Stride;
    19.  
    20. IntPtr p = new IntPtr(data.Scan0.ToInt64() + data.Stride * i);
    21. System.Runtime.InteropServices.Marshal.Copy(rgbBytes, i * bmp.Width * 3, p, bmp.Width * 3);
    22. }
    23.  
    24. bmp.UnlockBits(data);
    25.  
    26. System.IO.MemoryStream ms = new System.IO.MemoryStream();
    27. bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    28. byte[] byteImage = ms.ToArray();
    29. ms.Close();
    30. ms.Dispose();
    31.  
    32. return byteImage ;
    33. }
    To copy to clipboard, switch view to plain text mode 

    Now I sure if I could get the Image data into a QImage I could figure out the rest.
    I've tired:
    Qt Code:
    1. /* For refences this is teh structure format.
    2. typedef struct dpfpdd_image_info {
    3. unsigned int size; /**< size of the structure */
    4. unsigned char* image_data; /**< image data */
    5. unsigned int image_size; /**< size of the image data */
    6. unsigned int width; /**< width of the captured image */
    7. unsigned int height; /**< height of the captured image */
    8. unsigned int res; /**< resolution of the captured image */
    9. unsigned int bpp; /**< pixel depth of the captured image */
    10.  
    11. } DPFPDD_IMAGE_INFO;
    12. */
    13.  
    14. QImage* img = new QImage(pImageInfo.width, pImageInfo.height, QImage::Format_Indexed8);
    15. img->fromData(pImageInfo.image_data, pImageInfo.image_size);
    To copy to clipboard, switch view to plain text mode 

    I then try to save it off as a Bitmap to look at it, but i'm told it's not a proper bitmap file.

    So i'm not sure if i am even close to the direction on loading this image data into a Qimage.

    Any direction would be great. I've been searching around all day, but just have not had much of any luck.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Convert 8bpp Image to Qimage

    I had a program i originally wrote in C#, but I need it to run on linux now. So I've been porting it to c++ to use the QT GUI.
    You do know that you can simply use Mono with your C# code on linux don't you?

    Is the image data you are loading on to the QImage already converted to jpeg?
    The docs say:
    If format is not specified (which is the default), the loader probes the file for a header to determine the file format. If format is specified, it must be one of the values returned by QImageReader::supportedImageFormats().
    So you might want to specify jpg and see if it helps, since your image data does not have a header.

    Did you have a look at how QImage is using indexed8 format and does your code prepares the data accordingly?
    http://doc.qt.io/qt-5/qimage.html#image-formats
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. How to convert QString to QImage
    By gunturrohith in forum Qt Programming
    Replies: 12
    Last Post: 28th July 2015, 07:34
  2. How to convert multi page Magick++ Image to QImage?
    By eadorean in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2013, 18:28
  3. How To Convert CGImageRef to QImage
    By nareshqt in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2008, 08:21
  4. Convert RAW 8 bit pixels into a QImage
    By danielperaza in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2008, 14:53
  5. Problems working with 8bpp and 24bpp images
    By SkripT in forum Qt Programming
    Replies: 20
    Last Post: 17th February 2006, 13:07

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.