as a fun little project, I am trying to create an 'overlay' program.
Perhaps you've heard of the program 'open broadcaster software'.
This is a streaming program that can 'record' windows and apply 'color key' to them (making a certain color transparent)
I have a program that creates a window with a green background, acting as the greenscreen. On this window I want to make images appear, dissapear and move.
So far so good, however the problem comes with transparent images. They have a color hue over them because the color key tries to remove or smoothen out the colors.
So my question is; is there a way to programmatically add a color to a picture, or strengthen other colors, so color key would instead render the original?
Sincerely,
JB
Rendering a pertially translucent image on a backgroud showing the background color shining trough is the whole point of translucency.
There is nothing you can do without sacrificing the transparency in some way or another. A few useful effects can be achieved with java.awt.AlphaComposite, but I'm not sure any of the effects suit your fancy.
You could preprocess the images and change translucency to simple transparent/opaque (e.g. alter alpha for each pixel to newAlpha = oldAlpha < threshHold ? 0x00 : 0xFF). Selecting a good-looking threshhold value might be tricky (no one-size fits all). Needless to say that this will result in a drop in perceived image quality.
Related
I have two pixel arrays, foreground and lighting. When I draw a white radial gradient (blurry circle) onto the lighting array, I want it to make the foreground visible - much like a torch in terraria/starbound. However, I also want to be able to mix different colors of lighting, rather than be stuck with black to white.
So how do I manipulate the pixel arrays so that they 'multiply' (I believe it's called)? Or is there an easier way using RGBA which I have not been able to get to work (flickering black on white or image getting ever more posterized)?
So far most responses regarding alpha channels / opacity have been using libraries from java which for this project I want to refrain from using.
Any help much appreciated!
If you want to know how the blending modes (such as "multiply") work in image editing programs on the pixel-value level, read this: How does photoshop blend two images together?.
Note that if you want to make the image lighter, you need a mode like "screen", because "multiply" makes it darker.
Ok, so I have this map and I have various sliders on the right. After changing slider values and pressing 'Execute' button, some provinces in the map below should change colour.
However, I don't know how to implement the map below. I have used 33 png drawable for each province. I have set them all to have a same big rectangle dimension so that they'd align themselves.
I am getting an 'Out of memory on byte allocation' error.
I assume this is because of all the large drawables I have.
I'm new to android and I want to ask, is there a way to implement this without the error?
Also the map should always be displayed on the left side of the screen so the images always have to be visible.
I would recommend making a SVG and changing the colors programmatically.
Graphics are hard to scale and are heavy space users, scalable graphics are slim, look great everywhere (device size and dpi) and easy to manage (single file instead of 33).
I am attempting to create a "hole in the fog" effect. I have a background grid image, overlapped onto that I have a "fog" texture that I use to show that certain areas are not in view. I am attempting to cut a chunk out of "fog" that will show the area that is currently in view. I am trying to "mask" a part of the fog off the screen.
I made some images to help explain what I am after:
Background:
"Mask Image" (The full transparency has to be on the inside and not the outer rim for what I am going to use it for):
Fog (Sorry, hard to see.. Mostly Transparent):
What I want as a final Product:
I have tried:
Stencil-Buffer: I got this fully working except for one fact... I wasn't able to figure out how to retain the fading transparency of the "mask" image.
glBlendFunc: I have tried many different version of the parameters and many other methods with it (glColorMask, glBlendEquation, glBlendFuncSeparate) I started by using some parameter that I found on this website: here. I used the "glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);" as this seemed to be what I was looking for but... This is what ended up happening as a result: (Its hard to tell what is happening here but... There is fog covering the grid in the background. Though, the mask is just ending up as an fully opaque black blob when its supposed to be a transparent part in the fog.
Some previous code:
glEnable(GL_BLEND); // This is not really called here... It is called on the init function of the program as it is needed all the way through the rendering cycle.
renderFogTexture(delta, 0.55f); // This renders the fog texture over the background the 0.55f is the transparency of the image.
glBlendFunc(GL_ZERO, GL11.GL_ONE_MINUS_SRC_ALPHA); // This is the one I tried from one of the many website I have been to today.
renderFogCircles(delta); // This just draws one (or more) of the mask images to remove the fog in key places.
(I would have posted more code but after I tried many things I started removing some old code as it was getting very cluttered (I "backed them up" in block comments))
This is doable, provided that you're not doing anything with the alpha of the framebuffer currently.
Step 1: Make sure that the alpha of the framebuffer is cleared to zero. So your glClearColor call needs to set the alpha to zero. Then call glClear as normal.
Step 2: Draw the mask image before you draw the "fog". As Tim said, once you blend with your fog, you can't undo that. So you need the mask data there first.
However, you also need to render the mask specially. You only want the mask to modify the framebuffer's alpha. You don't want it to mess with the RGB color. To do that, use this function: glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE). This turns off writes to the RGB part of the color; thus, only the alpha will be modified.
Your mask texture seems to have zero where it is visible and one where it isn't. However, the algorithm needs the opposite, so you should either fix your texture or use a glTexEnv mode that will effectively flip the alpha.
After this step, your framebuffer should have an alpha of 0 where we want to see the fog, and an alpha of 1 where we don't.
Also, don't forget to undo the glColorMask call after rendering the mask. You need to get those colors back.
Step 3: Render the fog. That's easy enough; to make the masking work, you need a special blend mode. Like this one:
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA, GL_ZERO, GL_ONE);
The separation between the RGB and A blend portions is important. You don't want to change the framebuffer's alpha (just in case you want to render more than one layer of fog).
And you're done.
The approach you're currently taking will not work, as once you draw the fog over the whole screen, there's no way to 'erase' it.
If you're using fixed pipeline:
You can use multitexturing (glTexEnv) with fixed pipeline to combine the fog and circle textures in a single pass. This function is probably kind of confusing if you haven't used it before, you'll probably have to spend some time studying the man page. You'll do something like bind fog to glActiveTexture 0, and mask to glActiveTexture 1, enable multitexturing, and then combine them with glTexEnv. I don't remember exactly the right parameters for this.
If you're using shaders:
Use a multitexturing shader where you multiply the fog alpha with the circle texture (to zero out the alpha in the circle region), and then blend this combined texture into the background in a single pass. This is probably a more conceptually easy approach, but not sure if you're using shaders.
I'm not sure there's a way you can do this where you draw the fog and the mask in separate passes, as they both have their own alpha values, it will be difficult to combine them to get the right color result.
I'm using ImageIcons that I downloaded from a free icon site in my JButtons. Two of them have white backgrounds, and the other one has a black background. I would prefer not to have a background color clash, so I want to make all the backgrounds transparent. I've seen ways to make image backgrounds transparent, but I thought it was kinda roundabout to turn my ImageIcons into Images and back again. Is there a way to make the backgrounds of ImageIcons transparent without converting to Images?
This isn't a Java-solution, but it's a solution I use frequently nonetheless. Download/install Paint.NET and follow this discussion on how to make the background of images transparent. And then use the resulting image for the ImageIcon.
Another non java solution: with photoshop you can select a small white rectangle of the background part, and then menu "Select" > "Similar" if you want to delete all white pixels, or "Grow" if you want to delete all white pixels touching your existing selection.
I am creating a blackberry apllication which pre-dominantly uses ObjectListFields..All i need now is to draw an image as a background for each cell. I know this is quiet possible but i am not getting hold of the procedure. if i draw bitmap in drawlistrow() function the bluehighlight gets into the background and the cell highlight becomes very hard to read......can anybody help me with a code snippet to get through this problem ....thanks...
As far as i know ObjectListFields focus fills the background of the element blue and alters the foreground color (text) to white.
If you really need to draw an image on the background, you should at least change the foreground color to a high contrast or at make the background image transparent.
Check the style of the graphics in drawListRow with
graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)and set different colors for them.