Question 1 and 2 about image storage when using wxWidget

Source: Internet
Author: User

1. in the laboratory, the actual color order of CCD is 14 bits. Each value of the obtained original image data is stored in one word, that is, the color order is 16 bits, that is, the data with the highest two bits is always 0, at the same time, the obtained image information is only a 16-color grayscale image. However, wxWidget cannot directly save 16-bit numeric strings as image formats, such as tiff format, how can we save 16-bit numeric strings as images?

After a few days of hard work, we finally found a solution, that is, converting 16-bit numeric strings into 8-bit numeric strings. Maybe you will think of this method very quickly, nValue * max (uint8)/max (uint16); used to represent the converted value. It is not enough to consider the actual color order of CCD. Because it is 14 bits, therefore, we can use this method nValue * max (uint8)/max (uint14). However, since we process images directly, conversion is only a prerequisite for the display of images on the display screen. Although the above method can be relatively accurate for conversion, it requires a certain amount of computing, this conversion process can be carried out more quickly through similar conversions, and the obtained images still have better clarity. The following describes the methods I have used:

1: unsigned short nPicData16 = new unsigned short [nBufSize]; // nBufSize is the size to store pic
2:
3: // to get the nPicData16
4 ://..................
5: // get the nPicData16
6:
7: char * pcPicData8 = new char [nBufSize];
8: for (size_t I = 0; I <nBufSize; ++ I ){
9: pcPicData8 [I] = (char) (nPicData16> 6 );
10 :}
11:
12:

Because the proportion of 2 ^ 6 in 2 ^ 14 is small, this approximate method can be used. (The specific role or defect of this method has not been discussed in detail. Please take a look at it.) www.2cto.com

2. After successfully converting the 14-digit numeric string into a 8-digit numeric string, try to save the image in the following ways and find that the result is black and the value is 0:

1: // The result shows that the saved save.bmp image is 24b.
2: wxBitmap bitmap (pcPicData8, 1392,1040, 8 );
3: bitmap. SaveFile (wxT ("save.bmp"), wxBITMAP_TYPE_BMP );
4:

Therefore, we assume that wxWidget uses the rgb mode to save the directly obtained data string. It may only save images in the 24-byte format, that is, when you want to display the image to the screen, you should also use a 24 B image. However, wxWidget can read 8-bit images for image data. However, when the above method is used for storage again, it becomes 32 bytes, (Do you know if you can save 8 bitmap directly ).

Therefore, the 8-digit numeric string is assigned to R, G, and B respectively. In this way, the grayscale image is created and then saved to solve the problem.

1: unsigned char * rgbData = new unsigned char [1392*1040*3];
2: unsigned char * ptr1 = (unsigned char *) pcPicData8;
3: unsigned char * ptr2 = rgbData;
4: for (int I = 0; I <1392*1040; ++ I ){
5: * ptr2 ++ = * ptr1;
6: * ptr2 ++ = * ptr1;
7: * ptr2 ++ = * ptr1 ++;
8 :}
9: wxImage myImage (1392,1040, rgbData );
10: myImage. SaveFile (wxT ("save.bmp"), wxBITMAP_TYPE_BMP );


Author: Zhong xiwei

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.