11-09-2004 07:20 AM
11-09-2004 02:44 PM
11-09-2004 03:33 PM
11-09-2004 04:49 PM
09-13-2005 02:29 AM
09-13-2005 10:50 AM
I threw together a small example of what this would look like. Using the following code, you can just call
MakeColorTransparent(bitmap, VAL_WHITE);
for example, to make all white pixels in the bitmap transparent. You can use MakeColor() to use a color of your choice.
You can then place it in a picture control for which you have set ATTR_PICT_BGCOLOR to VAL_TRANSPARENT and place it wherever you want, with whatever fit mode is appropriate.
Hope this helps,
-alex
void MaskBitsOfColor (unsigned char *bits, int rowBytes, int color, int width, int height, unsigned char *mask)
{
int i, j, maskRowSize = ((width + 15) / 16 * 2);
for (i = 0; i < height; ++i)
for (j = 0; j < width; ++j)
{
if (*(int *)(bits + i * rowBytes + 4 * j) == color)
mask[maskRowSize * i + j / 8] &= ~(1 << (7 - (j & 0x7)));
}
}
void MakeColorTransparent(int bitmap, int color)
{
unsigned char *bits = NULL, *mask = NULL;
int width, height, rowBytes, pixelDepth = 32;
int maskSize, maskRowSize, hasMask;
GetBitmapInfo(bitmap, NULL, NULL, &maskSize);
GetBitmapData(bitmap, NULL, NULL, &width, &height, NULL, NULL, NULL);
rowBytes = 4 * width;
maskRowSize = ((width + 15) / 16 * 2);
hasMask = maskSize > 0;
maskSize = maskRowSize * height;
mask = malloc(maskRowSize * height);
bits = malloc(rowBytes * height);
if (hasMask)
GetBitmapData(bitmap, NULL, NULL, NULL, NULL, NULL, bits, mask);
else
{
memset(mask, 0xff, maskSize);
GetBitmapData(bitmap, NULL, NULL, NULL, NULL, NULL, bits, NULL);
}
MaskBitsOfColor (bits, rowBytes, color, width, height, mask);
SetBitmapData (bitmap, rowBytes, pixelDepth, NULL, NULL, mask);
free(mask);
free(bits);
}
09-13-2005 12:35 PM
I'll try your example, alex!
In my original application I ended up using a white background since the images needed to be printed too.
09-21-2005 09:03 AM
10-11-2007 02:23 AM
Hi, all
I've tried Alex D's code, it works well in my own computer, but when i tried it on the system which use NI PXI 8176(P3) ,it didn't work, does it have something about the hardware? such as vedio card?
thanks for your help!
10-11-2007 10:42 AM