Rendering Images Of Type BufferedImage - Pixels Are Not Consistent In Size

Jun 26, 2014

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];

[Code] ....

So, how do I make the pixels equally small?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Double Drawing Pixels When Manipulating DataBuffer Of BufferedImage

Feb 9, 2014

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.

Original tilesheet:As rendered:

Game.java:
package igg.engine.game;
import igg.engine.game.gfx.Screen;
import igg.engine.game.gfx.SpriteSheet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;

[Code] ....

View Replies View Related

Java 1.8 - Rendering Images To Printer / Result Is Not Good

Feb 10, 2015

I have some troubles rendering images to the printer, any resolution does not work, even 72 in PDF printer does not work, the image is crappy.

I use the following code but the result is not good. I mean the image quality is not acceptable.

img=new ImageIcon("c:\test\m.jpg").getImage();
scale=72/300d;
g.scale(scale,scale);
g.drawImage(img, 0, 0, (int) (img.getWidth(null)/scale), (int) (img.getHeight(null)/scale), null);

I've also tried :

img=new ImageIcon("c:\test\m.jpg").getImage();
AffineTransform aft=g.getTransform();
double scale=aft.getScaleX();
g.scale(scale,scale);
g.drawImage(img, 0, 0, (int) (img.getWidth(null)/scale), (int) (img.getHeight(null)/scale), null);

The result is the same even if I change the image, very poor and unacceptable!

View Replies View Related

Size Of Java Boolean Type In Memory

Jun 13, 2013

I searched everywhere but i didn't found anything about the real size of primitive boolean type used by java.

View Replies View Related

Putting Images In GUI / Images In Source File Don't Seem To Be Recognized

Jun 7, 2014

This is my class with the GUI:

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JPasswordField;

[code]....

Eclipse error message:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at GUI.<init>(GUI.java:26)
at Apples.main(Apples.java:7)

i think the problem is to do with my images not being recognised. I put them in my source in User>...>workspace>src which is correct as far as i know. From what i know the images should show up if i look at my src file in eclipse but they dont. I tried changing the file type from .png to .jpg but it makes no difference.

View Replies View Related

Changing The Required Pixels Color?

Nov 15, 2014

I would like to draw a rectangle around a certain part of an image.

So I wrote this:

Pixel[] pixels = scene.getPixels();
for( Pixel pixel : pixels)
{
if(pixel >= point.getX() && pixel <= (point.getX()+p2.getWidth())
{
pixel.setGreen(150);
}
}

But the error is giving me incompatible types. I would like to set all the pixels at a certain point up to the dimensions of my rectangle and so on. How would I do that?

View Replies View Related

GUI Bars - Increment Height By About 10 Pixels

Nov 12, 2014

So I'm trying to make a bar graph, each bar will increment the height by about 10 pixels. To do this, I'm making an array of bars. For some reason, using fillrect I cannot not increase the size more than 10 by 10, if I do, it will only show the 10 by 10. I want the bars to increase in height by 10 each time.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame

[Code] .....

View Replies View Related

Image Processing - Array Of Pixels

Feb 13, 2015

I am trying to process an array of pixels, checking each within a 5*5 mask. Ive declared my mask as a 2d array and get the pixel values within a nested for loop. Im getting an ArrayIndexOutOfBoundsException at the line:

mask[0][4] = dsIm.red[i-1][j+3];

Have I declared my mask wrong for a 5*5 mask. Is my logic wrong?

I won't give all the code, but basically Im trying to check all 25 pixel values within the mask:

int [][] mask = new int[5][5];
System.out.println("We are in the method just written");
//loop one loop
for(int i = 1; i <= h-2; i++)
{
for(int j = 1; j<=w-2; j++)

[Code] .....

View Replies View Related

BufferedImage Has White Padding On Top?

Jul 27, 2014

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 ?

View Replies View Related

BufferedImage Or Pixel Arrays

Jun 30, 2014

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.

View Replies View Related

IndexColorModel 255 Colors To BufferedImage

Apr 4, 2014

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?

View Replies View Related

BufferedImage Auto Rotate JPG

Apr 11, 2015

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);
}

View Replies View Related

JavaFX 2.0 :: BufferedImage To Mat - OpenCV

Mar 16, 2015

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)
 
[Code] ....
 
Can't figure out why this doesn't work. -.-

View Replies View Related

2 Dimensional Array That Represents Color Pixels

Nov 25, 2014

I have this 2 dimensional array that represents color pixels

RGBColor[][] rgbArray1 = new RGBColor[rows][columns] - so each elemnt in this array is a pixel - (red, green, blue)

I wrote a class named RGBImage. represents an image. the constructor of this class takes RGBColor[][] rgbArray1 as an argument and print the image.

My problem is when i try to rotate the image 90 degrees. because the dimentions are changeing. i'm getting ArrayIndexOutOfBounce Exception.

I know i can to this by create a bigger 2 dimensional array and copy the original , but for this assignment i cant do this .

I must use the original one . now i will show the main method that will get things clearer if i didnt explained well enough.

System.out.println("Constructor with RGBColor[][] Array Parameter:");
RGBColor[][] rgbArray1 = new RGBColor[3][4];
for (int i=0; i<rgbArray1.length;i++)
for (int j=0; j<rgbArray1[0].length;j++)
rgbArray1[i][j] = new RGBColor(i,i,i);

[Code] ....

output:

(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(1,1,1) (1,1,1) (1,1,1) (1,1,1)
(2,2,2) (2,2,2) (2,2,2) (2,2,2)

(2,2,2) (1,1,1) (0,0,0)
(2,2,2) (1,1,1) (0,0,0)
(2,2,2) (1,1,1) (0,0,0)
(2,2,2) (1,1,1) (0,0,0)

This outputs are what i need to accomplish.

View Replies View Related

Comparing Bitmap Pixel Data To BufferedImage?

Mar 21, 2015

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.

View Replies View Related

Rendering Actions In A Combo Box?

Feb 2, 2014

When I add an array of action-objects (the class extends AbstractAction)

to a combo box, I do receive the action performed events, great!

But the combo box items show the long string of the action object, of course!

How to render that string in a way that only the Action.NAME appears?

I was experimenting a little, but could not make it to work:

Java Code: private class ComboRenderer2 extends BasicComboBoxRenderer {
@Override
public Component getListCellRendererComponent(JList list,

[Code]....

View Replies View Related

Rendering The Cells Of JComboBox In Java?

Aug 27, 2014

I have a student class with fields names and Gender. Now, I have a students' array. such that I can create multiple students' classes: student a, student b, student c e.t.c and store them into the students' array. Now, I store this students' array in a JComboBox and want to only display the names of these students in the array. Such that the JComboBox lists only the names of student a, student b and student c. . When a user clicks on a selected Item on the JComboBox, even though, it was a student's name that was selected, I want the selectedItem to be a object of the Student class. This, I have learnt works with JList by writing your own custom JList models and then DefaultListCellRenderer. Is there anyway, one could also do this with JComboBox?

//Main Method
import StudentList;
import Student;
import ViewGui;
import Controller;
public class SwingMainMethod {

[code]....

View Replies View Related

JSF :: CDI With Primefaces Charts Not Rendering Properly

Jun 3, 2014

I have 4 Primefaces bar charts which sometimes renders, sometimes not. In one of them, I inject a http user session attribute and use it to render the chart (the idea is to show only the data that corresponds to the (logged in) user department).

There are 4 session beans which I'm using the javax.enterprise.context.RequestScoped. Sometimes, the Glassfish destroys the instance as expected, but sometimes not.Based on Exception below, how can I resolve it?

The xhtml below shows the main code for only 2 of the 4 bar charts:

<p:tab title="Horas de Treinamento (por Funci)" closable="true" >
<p:barChart id="horasBars" value="#{chartHorasFunci.modelHoras}"
legendPosition="ne"
orientation="horizontal"
seriesColors="AA5555, 00438F"
xaxisLabel="Horas" yaxisLabel="Funcis"
title="34 Horas de Treinamento (Orçado/Realizado) por Funci"

[Code] .....

The Exception:

SEVERE: Error Rendering View[/capacitacao/capacitacao/index.xhtml]
javax.el.ELException: /WEB-INF/include/capacitacao/capacitacao/List.xhtml @145,38 value="#{chartHorasFunci.modelHoras}": org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke private void br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci.initialize() on br.com.bb.upb.diage.atb.capacitacao.beans.ChartHorasFunci@3e9c727c
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)

[Code] .....

View Replies View Related

JSF :: Element Is Not Rendering / Parsing While Migrating

Jan 24, 2014

I m trying to migrate JSF 1.2 project with myfaces to JSF 2.0 with myfaces 2.0 jars on weblogic10.3 server. Found some problem related build and publishing after resolving them when i hitting my application all JSF html tags are coming in browser as it is they are parsed to html tags. all h: tages are coming as it is on my browser they are not converted to html tags for browser display.

View Replies View Related

JTree Branch Icon Rendering

Nov 12, 2014

I have a problem I must solve and could not find an answer after a couple weeks of research, so here I am. I have created a custom Table Cell Renderer than extends DefaultTreeCellRenderer. The mission of this renderer is to set the branch icons depending on conditional statements. There are 3 conditions, and each one should render a different icon. These conditions must be tested against all branches in the tree. This means that using something like setOpenIcon() and setClosedIcon() will not work since it seems as though these methods set all branches to a specific icon (I could be wrong about that though). Below is the code for my custom. I made comments so it is easier to understand what I want to happen and what is not happening.

/**Custom Cell Render that will set the icons for the tree branches and the leafs*/
private TreeIconCellRenderer extends DefaultTreeCellRenderer{
public Component.getTreeCellRendererComponent(JTree tree, Object value,boolean selected,boolean expanded, boolean leaf, boolean row, boolean hasFocus){
//Get defaults in case there is no need to renderer

[Code] ...

What I really need to know is why the renderer is not differentiating between the leaves and branches. The logging statements I have added confirm that the branch block of code does not execute.

View Replies View Related

JavaFX 2.0 :: Rendering Text Along A Curve

Nov 8, 2014

I'm currently working on a project which requires to have text displayed along a curve. If found this entry a good starting point. It works fine for me on my develompment machine, however the customer on his machine noticed some issues.

The basic idea is to define a path for the text, explode the text into the separate characters and animate them along the path the fraction of the character of the whole lenght. So with a animation duration of 10 seconds and a label of ten characters, the first character would be animated along 1 second, the second 2, and so forth.

This is done by jumping to the designated time in the animation, start the animation and stop it immediately.

Now the problem as I see it, for stopping the animation a separate timer is used, so it can happen that at the time the animation is actually stopped, the animation moved further than the first frame. The effect is that the last characters of the text appear in front (wrapped around).

As I have no evidence to prove or disprove my theory, what do you think is this plausable? I can see a workaround for this issue by defining a path for each character and then let the animation run to the end. While I can set the duration of the animation to 1 ms which should not be visible to the human eye, I'm not able to make the characters invisible and turn the visiblity on when the animation finishes, they always become visible at the start.

Or create my own animation/transition for placing the characters.

View Replies View Related

JavaFX 2.0 :: TreeItem And Custom Rendering

May 31, 2014

I am fairly new to FX but well experienced with Swing. Since I am familiar with the Swing concept of rendering a let's say JTree I got problems with the FX model of - in this case - TreeView.
 
I read several documentations about FX. From the API doc of TreeItem I adapted the file browser example to create an own class like this :
 
public class PathTreeItem extends TreeItem<PathTreeItem> implements
        Comparable<PathTreeItem> {
    private boolean firstVisit = true;
    private boolean readable;
    private boolean dir;
    private boolean symlink;

[Code] ...
 
But this did not change anything. I try to override toString() in both classes but even this did not change anything.
 
What I wonder so far:
 
Why is item in PathNodeTreeCell always null?What is the difference between the item I get in the updateItem method and the one I get from getItem() (line 10)How can I connect the PathTreeItem class to the PathNodeTreeCell classShould I always call super() in the constructors? (I delved a little bit in the sources of TreeItem and TreeCell and I found some setup code there )Is it ok to extend TreeItem in the way I does for my custom PathTreeItem class? ( I wonder if this is a cyclic dependency when I extends TreeItem in this way )How can I sort the nodes? I added the Comparable interface but this not change the sorting of the nodesAre ther some tutorials of TreeItem/TreeCell with no trivial objects like String ? 

I want to adapt an well running Swing application to FX. In the Swing app I used a mechanism to load the child path's of a directory in a separate thread to avoid freezing if the UI if there are much child elements. I guess in FX I should use the Properties pattern to achieve this should I?

View Replies View Related

JavaFX 2.0 :: Triangle Mesh Rendering

Aug 7, 2014

I'm new to JavaFX and I'm exploring its 3D capabilities, and in particular the TriangleMesh visualisation.
 
I have developed a very basic application, based on the Molecule Sample Application provided in the examples, that read a mesh file generated by an external tool (Gmsh) and displays it. Pretty basic.
 
My problem is that the rendering is not what I expected (see attachement)
  
My guess is that I got something wrong with the texture coordinates or the triangles orientation.

- I don't what to have textures attached to my meshes. These are 3D meshes used for scientific simulation purposes. I thus have set all texCoords to 0.
- I don't control the orientation of my triangles, they are generated by Gmsh. Their orientation is also not interesting for my end users so I would like to display all triangles the same way. I used the meshView.setCullFace(CullFace.NONE); method.

View Replies View Related

JSF :: Rendering A Page Using EJBs Between Separate Applications

Oct 16, 2014

I would like users in an application to be able to access and edit their user profiles (Application A). The problem is that the user objects (entities, dao, beans) are handled in a separate application (Application B) which is specifically for managing user accounts. Importing the java sources for App B into App A could be messy and might need configuration of the persistence unit and connection. I'm thinking it would be better to inject an EJB from App B to App A to query the user DB and return the results so a user profile form is rendered in App A.

I know how to inject EJBs within the same application, but I'm not so sure about how it's done across different applications or even if that's the most advisable way to achieve what I want. it's better practice to inject an external EJB into App A or simply import the classes from App B and use those.

@Stateless
public class UsersDaoImpl implements UsersDAO {
@PersistenceContext
private EntityManager em;

[code]....

View Replies View Related

JavaFX 2.0 :: HTML Rendering With Webview Component

Nov 14, 2014

I have a big issue to render this html page with the webview component :
 
<html><head lang="en">  <meta charset="UTF-8">  <title>Pb Rotate</title>  <style type="text/css">   #myDivRotate {
color: purple;   background-color: #d8da3d;   height: 200px;   width: 300px;   margin-top: 20px;   margin-left:20px;   -webkit-transform:perspective(400px) rotateX(30deg);   -webkit-backface-visibility: visible;   }
   </style></head><body>  <div id="myDivRotate">   Coucou
   </div></body></html>

The problem is from "perspective" in -webkit-transform. Without it's ok. But with this one, the result is different from a standard browser like chrome or safari.

View Replies View Related

Rendering Multiple Image Objects From Array In Location

Jan 11, 2015

Untitled.jpg I have been working over this game lately, and i have managed to render multiple images from an array. in this fashion. I created a Main() class with the following in it:

public Main() {
for (int i = 0; i < fuel.length; i++) {
Random r = new Random(); 
changef = r.nextBoolean();
y = (-600 * i) + r.nextInt(300);
if (changef)
fx = 325;
else

[Code]...

Also, this is the Fuel image class and Obstacle image class:

public void tick(Player2 p2) {
y += dy;
Random r = new Random();
if(x >= p2.getH()) {
y = -40 - r.nextInt(700);

[Code]...

(Fuel and obstacle class are identical but separate for better accessibility) I even have player class with an image listening to key events and also a scrolling background. The problem is when i run the game, the images of obstacles render themselves as i want, except for that they overlap each other, i need to prevent over lapping of this images. The fuel is read and obs is black. Heres a glance of how it looks.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved