So what I do normally is draw the bottom layer of grass, and when I draw the second layer with trees, the tree layer has a shadow, that shadow doesn't go ontop of the grass layer, but instead it overwrites the grass layer aswell and I've checked the color codes, the shadow has combined with white, not the first layer.
it's obvious that that's not how alpha works then, how do I do it?
for (int w=0;w<bi.getWidth();w++) { for (int h=0;h<bi.getHeight();h++) { int color = bi.getRGB(w, h); color = color << 5; bi.setRGB(w, h, color); } }
I am using a solid green image so
11111111000000001111111100000000
I just wanted to see how it looked so bumped it over 5 places (obviously changing the color). To my surprise, there was no added transparency. I mean moving it to the left would make the alpha:
11100000
I am thinking that setRGB() doesn't effect alpha. Is this accurate?Tested it and in fact setRGB has no effect on the alpha bits. So now the question is how can I gain access to them. I am going to look into the writable Raster API. Perhaps, I can also use a modified awt to access directly OS data.
I'm not even sure if I'm trying to place it in the correct area in the code. However I like to perform this prior to the receipt being displayed so if there a issue the user can correct this before the final receipt has been sent .......
How would I go about erasing the first buffered image before displaying the second one and eventually a third and fourth so that it appears the image is moving across the screen?
I am trying to read an image I have in the location of my project, So I do this:
When I read it in the try/catch like: BufferedImage image = ImageIO.read(new file(""));
And try to access it after the try/catch, it does not know that image exists, so I need to declare it as a global variable for that class first, and then it works.
public class Gui extends JFrame { private BufferedImage image1; public Gui() { super("MyApp"); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); initUI();
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage newImage = new BufferedImage(width, height, img.getType()); Graphics2D g2 = newImage.createGraphics(); g2.rotate(Math.toRadians(90), w/2, h/2); g2.drawImage(img,null,0,0); return newImage; }
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
I am writing a java program that takes a FROM image, a TO image, and a ratio (this is a slide bar in the GUI). Here's my code: Java Code:
public static BufferedImage rollUp (BufferedImage from, BufferedImage to, double ratio) { BufferedImage finalBufferedImage = new BufferedImage(from.getWidth(), from.getHeight(), from.getType()); int packedColor = 0; for (int r = 0; r < from.getHeight(); ++r) { for (int c = 0; c < from.getWidth() ; ++c) {
[code]...
So from 0 to 1 (ratio is a double between 0 and 1) the image will "roll up". The effect works completely in the GUI, but the console freaks out at about 0.33 ratio.. This program runs for testing in a class Main and uses a class Splittinimage.. this method is in class TwixPix. When the main class is run, a box pops up with a combo box and a slider. You pick an effect (in this case, roll up) and then slide the slider to set the ratio. The image below those two things performs the effect that was selected. Imagine a PowerPoint presentation slide effect.
private void createTextBox() { Graphics g = Game.getG(); Font font = new Font(fontName, fontStyle, fontSize); g.setFont(font); height = BORDER_WIDTH*2 + g.getFontMetrics().getHeight(); int stringWidth = g.getFontMetrics().stringWidth(dialog); width = BORDER_WIDTH*2 + stringWidth;
[Code] .....
This gets called when ever I want to create my Textbox object however what gets created is a purple box (i know that I have set the array elements to purple to begin with) however when I try to use the drawstring method to "draw a string" I get an image which looks like the gif below. I have changed the text size to various sizes but without success. The string is supposed to say "This is a test" but obviously it doesn't.
How can I write a BufferredImage to an 8-bit .bmp using indexed colors stored in a <String,Color> Hashtable?
I've never used Hashtables before, and I didn't know color indexing existed until now, but I can do most other things in java fairly well.
I'm not looking for code, just the concept, as I really don't know how Hashtables work (although I could figure it out), and how color indexing does. I know how to write image files, just not indexed or with a specific number of bits. I am using Hashtables generated from GIMP.
EDIT: I mainly want to know how to save a BufferedImage as an indexed .bmp.
I am trying to make a java Simon game but I cannot figure out how to make the GUI work. I have this so far, but now it just keeps saying I lose and it isn't functioning. It seems the only way I can make it work is having the action listeners in the do loop, but then once a button is clicked, the code errors out.
I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?
/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses. */
import java.util.Scanner; import java.io.*; public class hangman{ public static void main (String[] args) throws FileNotFoundException{ Scanner kb = new Scanner(System.in); String guess;
I am having trouble making my image move to a certain position in a certain amount of time which is set inside a text file. I was wondering what I'm doing wrong and what I'm missing.
import java.io.*; import java.util.*; import java.io.FileReader; public class Animator { EZImage HP;
I would like to learn how to add an image background to a window in java that I can put controls like buttons, textboxes, and checkboxes in front of. I already tried using a JLabel with an ImageIcon but I cannot overlay controls over the JLabel. From what I understand there are multiple ways to do this. What is the best way and how can I do it?
I'm trying to add an image on an undecorated JFrame and make it translucent by adjusting its opacity. The problem is that my Image also becomes translucent.
Here is my code:
package Loading; import javax.swing.*; import java.awt.*; public class TransparentFrame extends JFrame{ public TransparentFrame(){ createAndShowGUI();
[Code] .....
How can i make my image opaque but the frame behind it completely invisible. Why I'm getting serialize class warning in this code? that is:
"The serializable class TransparentFrame does not declare a static final serialVersionUID field of type long"
I have to make an application called miles to meters that converts miles to meters that asks for user input through joption pane and the output can be eather system.out.println or joption pane, I found the code i need but it uses buffered reader for input not joption pane. Here is the source code
import java.io.*; import java.util.*; class MetersToMiles{ public static void main (String[] args)throws Exception{ // 1 meters = 0.00062137119 miles;
I've got a .csv file with some text and numeric data. I've used BufferedReader to successfully print the data to the console. Now I need to perform mathematical operations on the numerical data. How do I access the data from the BufferedReader in my calculation methods?
What I would like to be able to do is create some loops to calculate totals for some of the elements, but I'm not sure how to access the data from other methods (and potentially classes?).
I am reading each line of the input one line at a time and incrementally storing four char positions into an array, so i am able to hold a vertical representation of each column. I.e. column 1 will be stored in array[0].
The problem with my code is that is does not read the last line of the input, it reads all the other inputs before it but just refuses to read the last line and execute the procedure of storing the characters.
Code:
public void defuseBomb(){ try { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); String asciiLine = reader.readLine()+ " "; int digit = (asciiLine.length())/4;
I have a text and I am reading each line in the text with the simple while loop:
BufferedReader br = new BufferedReader(new FileReader(new File(a.txt))); string line = new String(); while((line = br.readLine())!=null){ if(line.equals("john")) //skip to next line else{ //continue something else.. } }
My question is how do I skip to the next line ? Using apache.commons.io.FileUtils; one could easily have done something like this:
LineIterator it = FileUtils.lineIterator(file, "UTF-8"); String line = it.nextLine(); //this goes to the next line..
public static String readBuffer(Reader reader, int limit) throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < limit; i++) { int c = reader.read(); if (c == -1) { return ((sb.length() > 0) ? sb.toString() : null);
[Code] ....
I am particularly confused with the below lines -
if (((char) c == ' ') || ((char) c == ' ')) { break; }
This is how I am calling this code from my application -