03-12-2018 02:39 AM
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.
03-12-2018 10:30 AM
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.
03-12-2018 08:51 PM
These functions all return 0 or positive number,but the pitcure deplayed error.
03-13-2018 06:19 AM
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.