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.
How to find coordinates of transparent area in the image. I working on .png image which has transparent background and transparent area in the middle of the image. The transparent area in the middle look a like ellipse, so i want to find coordinate of top, bottom, left, and right of that area. I am using opencv.
I have tried to find pixels and from result that i got, i understand that pixel with rgb that equal to 255.0 255.0 255.0 is transparent. what i have in my mind is, if rgb with value that equal to 255 255 255 detected, i will put 1 into arraylist named transparent, and if it not equal to 255 255 255 i will put 0 into the list. So when i look into the list, if there is 1 0 or 0 1 it means that border between transparent area and colored area or vice versa. But, how to know if that border is between transparent area in the middle of image and the image, and not between background and the image. Am i doing this correctly?
Here snippet of code.
Mat imgMask = Highgui.imread(imgfile); double[] pixels = new double[3]; System.out.println("channel " + imgMask); for(int x = 0; x < imgMask.cols(); x++) { for(int y = 0; y < imgMask.rows(); y++) { pixels = imgMask.get(y, x);
The code is used to find coordinates of an image and i cannot understand how it works.
for (int y = 0; y < height; y += 2) { for (int x = 0; x < width; x += 2) { int px1 = secureRandom.nextInt(4); int px2 = secureRandom.nextInt(4); while (px1 == px2) px2 = secureRandom.nextInt(4);
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.
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 avoid an out of bounds error for my heap array by checking to see if the current values left and right child are greater than the size of the array and then ending the execution of the code. However, I am still getting an out of bounds error even with that condition.
public void trickleDown(){ System.out.println("TRICKLE DOWN"); boolean repeating = true; int temp, leftChild, rightChild, leftIndex, rightIndex, parent = 0; while(repeating){
I am trying to print out all of the values of an array and the average. I am getting part of the printout but I am also getting an array out of bound error message. what I am doing wrong?
int [][] points = new int [2] [3]; points [0][0]= 3; points [0][1]= 2; points [0][2]= 4; points [1][0]= 2; points [1][1]= 2; points [1][2]= 2; int totalPoints = 0; int totalShots = 0;
I have been working on this program for a while and now i seem to be stump it throws an outof Bound array exception error, this program is a matrix multiplication program and spits out the resulting matrix using multithreading. i have a running one and result is
2 -1 0 1 0 3 -1 1 3
but this program's result is:
2 0 0 1 0 0 -1 0 0
it reads a txt document as an commandline arguement the text file reads just like this below:
3 2 2 3 1 0 0 1 -1 1 2 -1 0 1 0 3
the following is my code:
import java.util.*; import java.io.*; public class P3 { public static int matrix1[][]; public static int matrix2[][];
I have two codes of needed to run but after processing, the said above error is preventing it from getting the general output of the code.I can't seem to find my errors or I don't have any clue at all, if perhaps you know, here's the codes:
Error : PHP Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at simpleOutput.main(simpleOutput.java:13) public class simpleOutput { public static void main(String args[]){ int n = Integer.parseInt(args[0]); for(int i = 1; i <= n; i++){ } for(int i = 1; n <= i; n++){ System.out.print((i*n)+" ");
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?
I'd like to draw an overlay on an image. The overlay is also an image with a black background and a white foreground. Now the white pixels should be drawn on the image in red. This is possible with the code I posted below. However, the problem arises when rotating the stencil (overlay). I get some interpolation errors from the rotation on the boundaries. I tried to clip them with setClip(), but this turns the background from transparent to white. How to remove those spots? Or maybe a completely other idea of achieving an overlay on the image? I'm aware of the pixelreader and iterating through the stencils pixels and draw the respective pixels as rectangles on a Canvas' graphicContext. However, this was extremely slow, compared to the code I posted below (although it doesn't work with rotations).
I am planning a race simulator car and I have a problem to get the x and y coordinates from the graph (or circuit). I explain the problem better. If I for example, drawing an arc using the library DRAW2D how do I get all the points in x and y coordinates of that arc?
A triangle is defined by the x- and y- coordinates of its three corner points. Compute the following the following properties of a given triangle: the lengths of all sides, the angles at all corners, the perimeter and the area. The program must prompt a user for the point coordinates. I have created a class Triangle and a class TriangleSimulator, I am stuck and can't figure out why my program won't run correctly.
import java.util.Scanner; public class Triangle { Scanner in = new Scanner(System.in); private int x1; private int x2; private int x3;
I'm working on a project right now in JavaFX, and got stuck. I am drawing a path consisting of CubicCurveTo's and I wonder if there's any way to get the X and Y coordinates from certain parts of that path.
Imagine following a curve (path) with a pencil slowly, and every second you take note the X and Y coordinate. I mean I'm not interested in the control points or start and end points, but the points "in between", preferably at a certain interval.
I've searched for many things online, but have trouble knowing exactly which words to search for. "Paths" often bring up file paths, traversing, coordinates etc. all fail to give me any good results.
I tried to be as specific I could, and I don't think my current code is of any interest in this matter.
(The point of it all is that the path should simulate the path a person walks, and I will store the coordinates in a database for every second).
What are the x- and y-coordinates of the Points referred to as p1, p2, and p3 after the following code executes? Give your answer as an x-y pair such as (0, 0). Recall that Points and other objects use reference semantics.
PHP Code:
Point p1 = new Point(); p1.x = 17; p1.y = 9; Point p2 = new Point(); p2.x = 4; p2.y = -1; Point p3 = p2; p1.translate(3, 1); p2.x = 50; p3.translate(-4, 5); mh_sh_highlight_all('php');
I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.
how to create coordinates in a two-dimensional grid, in the end it shall look like A5, F6 and so on. The aim is to place 3 DotComs in this grid by coincidence. To do this one uses two arrays. One array represents one DotCom, the other represents the grid's size, in this case 49 (7x7).The code ends like this:
ArrayList<String> alphaCells = new ArrayList<String>(); ... int x = 0; int row = 0; int column = 0; while (x<comSize) { grid[coords[x]] = 1; // mark master grid points as used row = (int)(coords[x] / gridLength); column = coords[x] % gridLength; temp = String.valueOf(alphabet.charAt(column)); alphaCells.add(temp.concat(Integer.toString(row)); x++; } return alphaCells; }
why row and column are calculated like this. Furthermore I don't understand why the column is used to generate a character, because columns are marked with numbers and rows are marked with characters.
//Design/write a class named MyPoint to represent a point with x and y coordinates. The class should contain:
//->Two variables, x and y, that represent the coordinates //->A no-arg constructor that creates a point (0,0) //->A constructor that constructs a point with specified coordinates //->Two getter (accessor) methods for the variables x and y //-> A method named distance that returns the distance from a point to another point of the MyPoint type //-> A method named distance that returns the distance from a point to another point with specified x and y coordinates. //Draw the UML Diagram for the class. Implement the class. Write a test program that creates two points (0,0) and (10, 30.5) and displays the distance between them.
I have written the program but not I have to do it with user input ....
class MyPoint { private double x; private double y; public double getx() { return x; } public double gety()
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;