Alpha blending and UIView background color - ios

When I draw semitransparent textures with OpenGL, it looks like that I get them blended with EAGLView backgroundColor.
((EAGLView*)my_view).backgroundColor = [UIColor redColor];
opaque property is set to YES.
Now that image looks red, when I change to black it turns to gray(blended with black), to white it becomes white (even semitransparent black).
What can it be?
my blending function setting is: src BFP_SRC_ALPHA, dest ONE_MINUS_SRC_ALPHA
I tried also(possibly something like premultiplied alpha):
src ONE dest GL_ONE_MINUS_SRC_ALPHA - it gives good result, but I get problems when drawing semitransparent quad(not texture).

the problem is in premultiplied alpha use src ONE dest GL_ONE_MINUS_SRC_ALPHA, and args must be with premultiplied alpha too glColor4f(r*a, g*a, b*a, a)

Related

How do I make the alpha channel more opaque?

I am dealing with a game texture. The alpha channel determines the smoothness.
I would like to paint the alpha channel (make it opaque or transparent) in GIMP.
I have clicked the alpha channel in the Layer tab.
When I select a brush, select White and paint, the checkerboard shows up more:
However, when I paint with Black to make the alpha channel opaque, nothing happens.
What am I doing wrong?
Thank you.
Yes, you are doing it wrong. When you enable/disable a channel in the Channels tab, you make it sensitive to paint operation. But when you paint with the brush on a transparent area the value of the alpha channel is always 100% (or more accurately the opacity of the brush).
If you want to paint the alpha-channel, you have to use "layer masks":
Layer > Mask > Add layer mask to add a mask (in you cae you probably want to initialize with "Transfer layer's alpha channel"
On the status bar at the bottom if the image, the layer name is now "{name of layer} mask"
You also have a thumbnail of the mask newt to the layer thumbnail in the Layers list.
Paint on the mask (black is transparent, white is opaque)
You can switch from painting RGB or Alpha channelby clicking the layer or mask thumbnail in the Layers list.
Possibly Layer > Mask > Apply layer mask when done (but you should be able to export the image directly, this will apply the mask)

GPUImage GPUImageFalseColorFilter giving wrong color and coloring transparent areas

I have a green button with a white icon and title. I am trying to use the GPUImage library that I just learned about to change the green to blue, but keep the white as white. Here is my code:
UIImage *inputImage = [UIImage imageNamed:#"pause-button"];
GPUImageFalseColorFilter *colorSwapFilter = [[GPUImageFalseColorFilter alloc] init];
colorSwapFilter.firstColor = (GPUVector4){0.0f, 0.0f, 1.0f, 1.0f};
colorSwapFilter.secondColor = (GPUVector4){1.0f, 1.0f, 1.0f, 1.0f};
UIImage *filteredImage = [colorSwapFilter imageByFilteringImage:inputImage];
There are 2 problems:
The resulting image is a pale purple instead of blue. Almost as though the blue is being overlaid with a 50% opacity or something and the original green was set to white.
The button isn't a rectangle (more of an oval), and the transparent areas of the PNG (the corners) are now filled in with a semi-transparent blue (well, pale purple actually). Basically the button is now a rectangle with a darker oval in the middle.
Am I using this filter incorrectly? Do I have to do some pre-processing before using this filter?
The GPUImageFalseColorFilter is probably not what you want to use to alter the hue of something. It's a reimplementation of the filter by the same name in Core Image, which first converts an image to its luminance and then replaces white with one color and black with another. Instead of a grayscale, you get a variable mix between these colors. I also don't think it respects alpha channels at present.
You might want something more like a GPUImageHueFilter (again, not sure if it respects alpha) or a GPUImageLookupFilter. You might need to build a custom filter to locate a color within a certain threshold (look at the chroma keying ones for that) and to replace that with your given color. Hue changes might do the job, though.

Delphi TBitBtn white layer

How can I get rid of the white layer drawn under the bitmap images by Delphi/Windows when Glyph property of TBitBtn is used. I just want to draw the image, no shadow under it, no other layers that comes automatically. I am inserting round shaped 24 bit bitmap images.
Since you have a 24-bit bitmap, there is no alpha transparency, so Delphi uses the bottom left pixel of the image to determine the transparent color. All pixels with that color are treated as transparent. The part of the image with the shadow effect is not an exact match for the designated transparent color, so those pixels are painted normally, just like the rest of the image.
The shadow appears white because there was a white background in the graphic program when your designer applied the shadow effect.
Either edit the image to remove the shadow, or use a 32-bit image with alpha transparency. You'll be hard-pressed to apply alpha transparency after the fact. Fix the source image.

openCV: adding transparency to IplImage

I have a 3-channel IplImage. I would like to create a 4-channel image and set the alpha channel for it to a value less than 1.0 to make it semi-transparent.
First I set the alpha channel (the 4-th channel) to 0.5:
cvSet(Image_c4, cvScalar(0,0,0,0.5);
Here is the command that I used to copy the 3-channel image into a 4-channel image.
cvCvtColor(Image_c3, Image_c4, CV_RGB2RGBA);
The problem: Image_c3 is in color. Image_c4 becomes a gray scale copy of Image_c3 (and with no transparency).
Update:
It turned out that the code above is actually correct and works and is actually more concise than the suggested solutions in the answers below. I had an unrelated bug somewhere else.
Maybe there is another way but I add transparency like this:
// BGR split
cvSplit(im1_bgr, im1_b, im1_g, im1_r, NULL);
// Alpha channel creation (transparency)
IplImage *im1_a = cvCreateImage(cvGetSize(im1_bgr), 8, 1);
// Set the alpha value
cvSet(im1_a, cvScalar(128), NULL);
// Merge the 4 channel to an BGRA image
IplImage *im1_bgra = cvCreateImage(cvGetSize(im1_bgr), 8, 4);
cvMerge(im1_b, im1_g, im1_r, im1_a, im1_bgra);
//This code help to make a transparency image But it take src image as one //single color background see![Removing background and added black background color ][1]
Mat dst;//(src.rows,src.cols,CV_8UC4);
Mat tmp,alpha;
cvtColor(src,tmp,CV_BGR2GRAY);
threshold(tmp,alpha,0,255,THRESH_BINARY);
Mat rgb[3];
split(src,rgb);
Mat rgba[4]={rgb[0],rgb[1],rgb[2],alpha};
merge(rgba,4,dst);
imwrite("dst.png",dst);
//dst is transparency image see here![output image as transparency image][2]
[1]: http://i.stack.imgur.com/9THqs.png
[2]: http://i.stack.imgur.com/mpmgy.png

WebGL transparent black

I have a strange problem that I can't figure out when trying to do blending in WebGL. Black is rendered fully transparent , and everything with shades of grey in it is rendered also semi transparent. I have set it to use the alpha channel as the source for transparency, and in some respect it works, every thing that isn't black/grey is rendered differently when changing the alpha value. but even when I set the alpha to 1, black is still displayed transparent.
This is how I enable transparency:
this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE);
this.gl.enable(this.gl.BLEND);
this.gl.disable(this.gl.DEPTH_TEST);
And the part of the shader that does transparency:
gl_FragColor = vec4(texColor.rgb * vLightWeight, texColor.a * uAlpha);
where texColor is the texture color that is being sampled, vLightWeight is the shadowing that is being calculated in the vertex shader, and uAlpha the uniform which I use for transparency.
I think you should have gl.ONE_MINUS_SRC_ALPHA where you currently have gl.ONE.
gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );

Resources