LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL varbinary to bmp

Hi!!

I want to read image from SQL Server

I used these functions,but the picture is not displayed.

 

hstmt= DBActivateSQL (hdbc,"SELECT * FROM TABLE WHERE IMAGE_ID=30");
fromDBBits = malloc (BitsSize);

DBBindColBinary (hstmt, 4, BitsSize, fromDBBits,&bitsStatus); 

   

DBFetchNext(hstmt);     

NewBitmapEx (7776, 24,2592 ,1944, 0,fromDBBits,NULL,NULL,&bm );
SetCtrlBitmap (panelHandle,PANEL_PICTURE,0,bm);

 

please help me, thank you.

 


          

0 Kudos
Message 1 of 4
(3,120 Views)

Hi SINPROSINPRO,

 

A lot of those functions: DBBindColBinary, DBFetchNext, NewBitmapEx, SetCtrlBitmap all return statuses which will either be 0 indicating success or some negative value corresponding to an error code. The database functions will throw SQL Toolkit error codes and the bitmap functions will throw UI library error codes. I don't see anything in the snippet of code you provided that stands out as being incorrect, so I would recommend processing on those returned statuses and using them to determine if (and which) error codes are being thrown and verify the valu eof the connection handle to ensure it's non-negative, which also indicates failure.

Regards,
0 Kudos
Message 2 of 4
(3,082 Views)

These functions all return 0 or positive number,but the pitcure deplayed error.

0 Kudos
Message 3 of 4
(3,074 Views)

There is lot to say about bitmaps, but the most important concept is this one, that can be found in the help for the function that I suggest you to read carefully:

Regardless of the color depth that you specify, the new bitmap matches the color depth of the display screen unless the image has an alpha channel, in which case the depth is 24.

 

That is to say, even if you think you are creating a 24-bit RGB image, you are very likely to be getting a 32-bit image. Which also means that your bits array does not match with that format. It depends on screen properties but nowadays 32-bit is almost always the standard.

You may need to preprocess the bits array adding an extra null byte before any RGB triplet. Also, note that 24- and 32- bit image arrays are different: 24-bit bitmaps have red at the lowest memory address, while 32-bit ones have blue. During preprocessing you must probably also swap color components.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 4 of 4
(3,063 Views)