LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Save a binary bitmap in LabWindows

I'm using LabWindows/CVI version 9.0.1. I can save bitmaps with no problems, but we're concerned about space. Each bmp file is just over 500K and we'll be generating a lot of them during our product testing. The bitmaps are simple black and white graphs so we don't need color. If I use another software program to convert to monochrome, we get the space savings we need. How can I do this within LabWindows? I'm currently using GetCtrlDisplayBitmap and SaveBitmapToBMPFile. I made some attempts using GetBitmapInfo,GetBitmapData, etc., but this process got very cumbersome and was only partially successful (I managed to generate a properly sized bitmap but it was solid black).

 

Is there a simple way to perform this conversion or will I have to go pixel by pixel?

0 Kudos
Message 1 of 13
(7,177 Views)

Do you really need a BMP file format? Most programs can handle PNG files these days, which for graphs are likely to be quite efficient. Check out SaveBitmapToPNGFile().

 

JR

0 Kudos
Message 2 of 13
(7,175 Views)
Unfortunately, yes. We have another database management program that needs to access the images and it can only open bitmaps.
0 Kudos
Message 3 of 13
(7,172 Views)

Hi,

 

why not use SaveBitmapToPNGFile()to generate the image file and then use an external program such as Irfanview ... to convert the png to bmp only when needed? I am using this function call SaveBitmapToPNGFile() and the files are pretty small, so there should be no concern on storage capacity. If you need to postprocess the image, you could temporarily convert it to a bmp, use your other program, and then delete the bmp....

 

Wolfgang

0 Kudos
Message 4 of 13
(7,144 Views)
If all we were worried about were storing the images, that would work great, but every image that we save will need to be read by the database system as soon as it's saved (unless we re-think how we handle this, which is entirely possible since we're just getting it going). We have several other options on the table and haven't entirely nailed down what we'll do. Thanks for the suggestions, though.
0 Kudos
Message 5 of 13
(7,140 Views)
There are some functions in Vision that allow you to convert an image to a string, and then  you could save the string in a database, and then convert the string back to the image with CVI. You can add this to your set of options. Another alternative to sore files to a centeral location and then in the database you only need to store the location to the image.
Richard S -- National Instruments -- (former) Applications Engineer -- Data Acquisition with TestStand
0 Kudos
Message 6 of 13
(7,112 Views)

It's sort of complicated, but we have an existing Visual FoxPro program that we use to manage our production parameters and generate reports. Right now, the operator manually prints out the waveforms directly from the scope and attaches them to the report. We want to automate that by having the VFP program load the bitmaps after the LabWindows program generates them. We actually saw 2 directions we could go:

 

1) Purchase the SQL toolkit and try to get the LabWindows program to access the production parameters from the DB directly and generate the reports itself.

2) Have the existing VFP program handle the reports and pass/fail decisions while the LabWindows program simply collects data.

 

We're in the midst of option 2 but our network is a bit overtaxed at this point, which is why I wanted to save smaller bmp files. We're looking at several other options as well that may render the question moot, such as automatically saving the entire report, including waveforms, as a pdf.

 

It does seem a little strange to me that there doesn't appear to be a "simple" way to save b&w bitmaps directly from LabWindows.

 

Thanks again for all the input.

0 Kudos
Message 7 of 13
(7,102 Views)

You could let the file system do some of the work by saving the bitmaps to a compressed drive.  Since they are simply bitmaps, they will probably compress well and everything will still appear to your programs as a normal bitmap.

Otherwise, I think you'll have to create a second bitmap in monochrome, then loop through a routine that manually copies the data pixel by pixel while at the same time reducing the color depth.

0 Kudos
Message 8 of 13
(7,093 Views)

It shouldn't be very difficult to convert color bitmaps to black & white bitmaps using the GetBitmapData/SetBitmapData functions. You mentioned you already tried it, but ran into problems (bitmaps were all black). If you'd like to give it another shot, we'd be happy to try to assist you, if you give us some more detailed information.

 

Luis

0 Kudos
Message 9 of 13
(7,037 Views)

When I ran into this thread I started thinking to a couple of solutions for it.

One option could be to connect to Paint via ActiveX or DDE and let that program do the job: possibly not the fastest method and prone to some unpredictable problems due to the poorness or lack of documentation on both methods.

Another option was to dig into MSDN resources, were I ultimately found this page with a little documentation and sample code: someone with C++ experience and MS compilator can use it as a framework to develop its own tool.

Using  GetBitmapData/SetBitmapData as Luis suggests could be another option, but I ran into this warning in online help for NewBitmap () so I decided to skip this step: "Regardless of the color depth that you specify, the new bitmap matches the color depth of the display screen."

 

Next I looked at BMP file structure, using this Wikipedia page, and decided to try directly generating a BMP file with new values. How to convert from color to grayscale was found in this page, while I have found no informations on conversion to monochrome. The result of my effort is in the attached project, where a complete conversion from true color bitmaps to grayscale 8-bit bitmaps can be found: conversion is perfomed starting from a .BMP file and generating a new one. The project includes also an attempt to generate monochrome bitmaps that gives very poor results: maybe sombody can improve it or find some errors in my procedures. Conversion to grayscale reduces file size approx to 1/3. If the conversion to monochrome cannot be completed satisfactory, some more reduction in file dimension can be achieved by compressing the 8-bit bitmap with RLE algorithm: if the image comes from a diagram from screen, with possibly large areas with constant colour, RLE compression should give good results (provided your Foxpro application can read RL-encoded bitmaps).

 

Hope all this helps.

Message Edited by Roberto Bozzolo on 01-13-2010 06:36 PM


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?
0 Kudos
Message 10 of 13
(7,012 Views)