I need to write an image to a .png with a 255-color indexed color model. I know usually do it like this: Java Code: BufferedImage img=new BufferedImage(width,height,BufferedImage.TYPE_BYTE_INDEXED,model); mh_sh_highlight_all('java'); but that doesn't work with models with 255 colors (as opposed to 256 colors). I'm fairly sure it is the BufferedImage creation that is the problem, as when I call model.getMapSize(), it returns the correct size.
The extra color added to the image's index is 15,15,15.
Should I be something other than a BufferedImage to write the image, or should I be using a different constructor for BufferedImage, or am I doing something else wrong?
What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.
Java Code:
public ImageIcon getBackImage(){ before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB); int w = before.getWidth(); int h = before.getHeight(); try{ URL url = getClass().getResource("/Blue_Back.png"); before = ImageIO.read(url);
[Code] ......
The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?
I am making a 2d game engine and i was wonder is it better to use BufferedImages and subImages to store/render sprites from sprite sheets or use BufferedImages and store it in a pixel array and then manipulate the pixel array to do what you want.
Basically is loading in BufferedImage and getting the tile of the sprite sheet with subImages better than loading in a BufferedImage and then putting the data in a pixel array and making a new array with the part of the BufferedImage you want.what i have been told the BufferedImage and subImage use more of the graphics card and the pixel array method uses more of the processor.
I need my Java program (I'm working in Eclipse if it matters) to detect if an image is a portrait or a landscape, but since i am directly downloading them from my camera they only have it written somewhere in metadata, the image width and height is the same for landscape and portrait. I have the rotation code and the rest of the program working, but I need to somehow get a variable (for example integer one) to tell me if it is a portrait or a landscape image. I tried getting to the metadata but my Eclipse decided that import com.drew.metadata.Metadata; cannot be resolved.
BufferedImage image = ImageIO.read(new File(imagePath, imageName)); and after I get the variable "orientation" it looks like this
int orientation = ???; BufferedImage newImage = oldImage; if (orientation>1){ newImage = rotate(oldImage); }
I am new to JavaFX and OpenCV. The Problem is, that JavaFX can't handle Mat objects. First I load an image as a BufferedImage. Then i have to convert this to Mat. Do my image Processing with OpenCV and again convert the result image to a BufferedImage to display in on my UI. Here are the methods for converting Buff to Mat and Mat to Buff I found on the internet:
public static Mat img2Mat(BufferedImage image) { byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3); mat.put(0, 0, data); return mat;
[Code] ....
Next I do some OpenCV stuff:
public static BufferedImage hello(BufferedImage img) { Mat source = img2Mat(img); //Convert Buff to Mat BufferedImage outImg = null; try{ System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
[Code] ....
Finally I call the hello method in my controller:
void menuItemTestFired(ActionEvent event) { try { result = ImageProc.hallo(bImage);//bImage is an image I've loaded before. imageView.setImage(SwingFXUtils.toFXImage(result, null));
[Code] .....
Unfortunately I get a lot of errors. Here are the first one:
Caused by: java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.<init>(Mat.java:471)
I'm working on a project based on Roger Alsing's Mona Lisa evolution.
My problem seems to be that when I compare the RGB values of the target image and the randomly generated image, I don't get a representative result of how "close" the two images are.
I load the target image (a 24-bit bitmap) using:
img = ImageIO.read(new File(filePath));
I draw onto a BufferedImage with:
for(int i = 0; i < numPolys*12; i += 12){ p[(int)(i/12)].addPoint(gene[i], gene[i+1]); p[(int)(i/12)].addPoint(gene[i+2], gene[i+3]); p[(int)(i/12)].addPoint(gene[i+4], gene[i+5]); p[(int)(i/12)].addPoint(gene[i+6], gene[i+7]); Color mycol = new Color(gene[i+8], gene[i+9], gene[i+10], gene[i+11]); gf.setColor(mycol); gf.fillPolygon(p[(int)(i/12)]); }
And I compare the BufferedImage with the target image using:
for(int x = 0; x < inGene.x; ++x){ for(int y = 0; y < inGene.y; ++y){ Color mycol1 = new Color(exp.getRGB(x, y)); Color mycol2 = new Color(inImage.getRGB(x, y)); int delta = mycol1.getRed() - mycol2.getRed(); score += (delta * delta); delta = mycol1.getGreen() - mycol2.getGreen(); score += (delta * delta); delta = mycol1.getBlue() - mycol2.getBlue(); score += (delta * delta); } }
My problem is that my code runs to a certain point, where it seems no matter what happens to the image, it doesn't seem to get any closer to the target image.
As implied by the title, when I am rendering images of the type "BufferedImage" unto a Swing application, the images' pixels are not consistent in size. Some might be larger than other, and some might be smaller than other.
Here is a screenshot of what I am talking about (you might need to zoom in a bit because the image is so small): [URL] ....
And here is also some code for you. The images are actually from a sprite sheet, which I first load in its entirety and then split up in an array.
Java Code:
public static BufferedImage sprites[]; ... public void loadSprites(){ try{ BufferedImage bigImage = ImageIO.read(new File("SOURCE/BLA/BLA/THIS/IS/ACTUALLY/NOT/THE/REAL/SOURCE/IN/CASE/YOU'RE/WONDERING/I/JUST/DON'T/WANT/YOU/TO/FIND/ME/AND/RAPE/ME")); sprites = new BufferedImage[16 * 16];
I've been working my way through a tutorial to build a simple 2D tile-based engine that also allows the code to manipulate the colour of pixels on the screen based on a monochrome map read from a file. I've got the code right line for line, but I seem to have a bug when it comes to draw to the screen! At regular intervals, despite what is held in the pixel array of ints (which I have confirmed to be correct when debugging), I get the same row of pixels being draw twice in a row. I figured there was some loop issue somewhere, but after attempting to debug this for some time, I haven't come up with the answer.
So i was thinking about colors in java and was wondering what kinda colors are regonised by java..found this java.awt.color.. which goes very indepth with transparancy(alpha) and other formats of colors..
Question:
I wanne make a programm in java that breaks up a picture(pixels) and put it together again..Storing values of the colors and so forth..Which format of colors would be easy to start with if taking about java programming? RGB?
My assignment is for a game where there is a board of colors and each player draws a color and moves to that position on the board. It will then output how many cards total in the game it took whichever player to win. If no winner it outputs the number of cards that none won by going through. I attached the file that corresponds with my code.
This is the desired output:
Player 1 won after 7 cards. Player 2 won after 8 cards. No player won after 8 cards. Player 2 won after 4 cards. No player won after 6 cards. Player 2 won after 8 cards. Player 1 won after 4 cards. Player 2 won after 8 cards. Player 1 won after 1 cards. No player won after 200 cards. Player 4 won after 100 cards.
import java.io.*; import java.util.Scanner; public class ProgrammingAssignment1 { /** * @param args the command line arguments */ public static int players; public static int cards; public static int boardlength; public static String board;
[Code] .....
The output that I get is:
Player 1 won after 3 cards. Player 2 won after 8 cards. No player won after 8 cards. Player 1 won after 3 cards. No player won after 6 cards. Player 2 won after 8 cards. Player 1 won after 3 cards. Player 2 won after 8 cards. Player 1 won after 1 cards. No player won after 200 cards. Player 4 won after 100 cards.I guess I'm supposed to set the playerPos[] to -1, but I'm unsure how.
I have a program I wrote long ago. I change colors of buttons at times. Here is the code:
for(int Player=0; Player < 8; Player++){ //make them all background dealerLabels[Player].setBackground(new java.awt.Color(212,208,200)); } //Now make the new dealer green dealerLabels[dl].setBackground(new java.awt.Color(51, 255, 0));
The color of the buttons has always changed under XP but when I run the program on Windows 8 only the edges of the buttons change.
I have a question about JTextArea colors. When i set the color to blue and then write something on the JTextArea (JTextArea.append) and then set it back to black everything will be black. How can i solve that? Like in Notepad++ or Eclipse when you write keywords in a JTextArea (where you write your code) only some words change color.
This is my code:
// All the imports public class whatever extends JFrame { JTextArea a = new JTextArea(); public whatever() { super("Title"); add(a);
After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.
I have a 30 X 10 JTable which i would like to put a border around some cells and change Background colors on others.For example i would like to put a border around cells 1,1 to 15,1 I would like to change background colours on several individual total cells.What the shortest way to color individual cells and add a border?
After generating a. JAR with Netbeans Java, when I play I see the colors of the components, the design and formatting is lost and the form gets a very basic formatting, for example, if I set a button with the color [0, 40.255] and build the. JAR after this, when I run the. JAR this button turns gray, and it happens with all the layout of the form.
so i'm supposed to create a jframe with only 1 button. each time you push the button it is supposed to go from red to green to blue to gray and back to red starting over. i can get is the background to change on the first click, then the button is useless for eternity. here is my code:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Exercise2_59 extends JFrame implements ActionListener { JButton change;
I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.
import java.util.Random; import java.util.Scanner; public class Final1 { String colorInput, computerColor; int computerNum, right, wrong;
[Code] ....
This repeats 10x but the color never changes from the initial random chosen.
I have a jtable , a customtablemodel and a customcellrenderer with the NetBeans IDE. I want to have different colors for different rows. But anytime I run the application , the rows are not painted as expected. The code snippets are provided below.
public class CustomTableCellRenderer2 extends DefaultTableCellRenderer{ @Override public Component getTableCellRendererComponent (JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { Component cell = super.getTableCellRendererComponent( table, obj, isSelected, hasFocus, row, column);
[Code]...
This is from the Table Model.
public class DuesTableModel extends AbstractTableModel implements TableModelListener { private List<List<Object>> dataList = new ArrayList<>(); private String[] header = { "ID"," PAYMENT YEAR" , "AMOUNT"}; // Payment year is a date datatype private int minRowCount = 5;
I am making a quiz in Java. I need to be able to add images and colours into my quiz, to make the GUI look more appealing. At the moment, the JOptionPane that I am using looks very plain and boring. I want to be able to have my quiz running the same as it is at the moment, but I want to be able to import the images, add colours, and add Here is a copy of my quiz code:
I created a GUI with NetBeans. When I run the program in XP and the program changes the button colors, the whole button changes color. In this case, from "background" to "Green".When I run the program under Windows 8 only the border of the button becomes green.
NetBeans seems to use the Look and Feel "nimbus". I single stepped through the program on both computers and it looks like a request for nimbus does not cause an exception on either computer.
I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:
Java Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JDemo { //Global Variables static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue . static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .
[Code] ....
The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.
We have developed a theme called default.css that is extending of the default caspian.css. What we want to do is offer users the ability to override values from default.css to change colors etc. How can that be done?
I am trying to write a TreeMap that can hold a max of 20 colors and a minimum of 8. I have a while loop using pollLastEntry to limit the max but I can't figure out how to set the minimum. The hex number is the map's key and the color name is the value. I tried to use entrySet() and iterator to just double the size of the map but map can't have multiple keys with the same value. It also seems that to set a minimum would require some kind of further input(which I'm trying to avoid) of colors and their hex numbers.
//Method to hard code the colors into the map public TreeMap<String, String> cm() { //Color Map <Hex number, Color name> //Uses a TreeMap to keep all the colors organized by key TreeMap<String, String> cMap = new TreeMap<String, String>(); cMap.put("FFFF00", " Yellow");
Simple gui task. it meant to draw pie chart with different colors. i can't seem to find a mistake in it. It works if i put in g2g.draw(arc) i know arcs overlaps a bit due int conversion, but that's ok.