Creating an Icon with a Tranparent Background - java

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.

Related

Background colour of chess pieces

I have downloaded all the eight pieces from Google images for both black and white player. All the images have a white background. I saved the images of the pieces in the drawable folder. I want to place a white Pawn on a black sqaure. Hence, I did the following:
<TextView
android:width="match_parent"
android:height="match_parent"
android:id="#+id/tv70"
android:background="#drawable/white_pawn"
/>
I have left out the unnecessary details regarding the position of the textview. The textview was supposed to be of a black background but the image of the rook makes it a white square(because it has a white background).
If I have to make it on a black background, I have to go and use Paint or Photoshop and change each of the background colour of the pieces to black and save them. (Giving me 20 images of such pieces). It takes alot of memory.
How should I change the background colour of the pieces without having so many images files? Or this there another way of creating the pieces for my chess game?
I'm attaching a picture of my Pawn pieces.
The above image is when I use the image with black and white background separately.
You can use a different colors than black and white for tiles. Otherwise it will break eyes.
P.S. You can use fonticons like https://fontawesome.com/icons?d=gallery&q=chess

How can I design a progress bar in SceneBuilder?

Here a simple question I'd like to ask.
I'm making a videogame (with NO graphics) and for that I'm using SceneBuilder. So here is the state of my HP bar :
HP BAR
Now I want to reshape it in order to obtain a heartshape :
HP BAR wanted
Thus, anyone know if it's possible to do it using SceneBuilder with the settings?
Thank you everyone, have a wonderful day.
One simple way, providing the background of the panel is simple, would be to overlay an ImageView over the top of the progress bar. If you use a PNG with a "hole" of transparency, you'd effectively hide the areas of the square that you're not interested in seeing.
In this example, the black pixels would be the same colour as the background colour (in your case grey) and the white pixels would be fully transparent.
The downside to this is that if the panel changes colour then you'll need to recreate your PNG in the new colour.

Is there anyway to create a 9-patch without distorting the text inside the image?

I'm actually trying to create many images (chat bubbles) with text inside them and obviously on using 9-patch it gets distorted. Is there an alternative way to save the text from distortion and simultaneously enlarging it along with the image(chat bubble)?
The whole idea of 9-patches is to separate text from background. You setup the form of your background bubble and mark the stretchable area and padding. In LibGDX all you have to do is create a Labelstyle that takes that 9-patch bubble as a background and put text in it. The bubble will stretch as your text increases. This however works best for squarish backgrounds but can work for your bubbles with a little tweaking and if you don't stretch them too crazy.

Program adjust transparent image for greenscreen

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.

Java: Is it possible to take a GUI Panel and output it into a picture?

So I have this chart that's a little special. Kind of like an XY plot of points but my boss wanted to look like a bunch of boxes rather than dots connected by lines. And I basically made a chart using gridlayout and a whole bunch of cells that I'll be colouring in black or white depending on the data.
Now he sorta wants it to be outputted to a image file. Is there any way to save a Panel into a picture? He wants to display not only the data but also save a visual representation of the data into an image file.
Is there any way to save a Panel into
a picture?
Screen Image
You can create a Graphics context which paints to an image. This technique is often used with animations to prepare drawings offline and swap them in place to avoid artifacts.
Typically you can use the same paint methos as used to paint your canvas.
Here are more details

Categories

Resources