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


ADVERTISEMENT

Padding Will NOT Work - Adding Spaces?

Apr 22, 2014

Why this will not pad?? It keeps displaying normally, even if i add spaces it will not work.

System.out.printf("%-20s%-20s%-20s%-20s", p.getLastName(),
p.getLastName(), p.getSocialSecurityNumber(),p.getAge());
This is what it is printing:

=================== =================== ====================== ===
lastname, firstname, 123-12-1234, 16

The lastname, firstname, 123-12-1234, 16 should be padded and appear with about 20 spaces between them.

View Replies View Related

TLS / SSL HandshakeException - Invalid Padding Length

Apr 22, 2015

I'm trying to establish an SSL connection (using a self-signed certificate). However, I can't seem to get the handshake to work. At the moment server side, I've created the public/private key + signed certificate and then stored them in a KeyStore. I've also stored this signed certificate in a KeyStore (trustStore) client side, so it can compare.

Keys: RSA, Certificate Sig: SHA256withRSA, cipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA

Client Code

// 34393570706261
SSLContext context = SSLContext.getInstance("TLS");

TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(client_trustStore);
context.init(null, tmf.getTrustManagers(), new SecureRandom());
SSLSocketFactory socketFactory = context.getSocketFactory();
conn = (SSLSocket) socketFactory.createSocket("localhost", port);
String[] suites = new String[]{"TLS_RSA_WITH_AES_128_CBC_SHA"};
conn.setEnabledCipherSuites(suites);

[Code] ....

Errors

Quote

javax.net.ssl.SSLHandshakeException: Invalid Padding length: (number)
WARNING: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
WARNING: javax.net.ssl.SSLException: Connection has been shutdown:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

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

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 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 View Related

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

When Add Second Panel The Result Is All White

May 11, 2014

import javax.swing.*;
import java.awt.*;
public class PRJ04 extends JFrame {
public static void main (String [] args) {
PRJ04 frmApp = new PRJ04();
PanelChart pnlChart = new PanelChart();

[Code] .....

When I comment out the adding and setting of the pnlChart on my main driver, the pnlPopulationInputs shows up fine, and it runs ok. When I add the pnlChart I get errors like crazy and a white screen. My errors:

Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero
at PanelChart.drawChart(PanelChart.java:45)
at PanelChart.paintComponent(PanelChart.java:24)
at javax.swing.JComponent.paint(JComponent.java:1054)

[Code] ....

Once more with this one, I refer back to our in class example. Our programs are set up the same, yet he has no issues with the "/ by zero" exception.

View Replies View Related

Deleting White Spaces In Java Code

Mar 1, 2014

My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use

System.out.print((matrix[i][j] + " ").replaceAll("^s+", ""));

It trims every thing including the spaces I needed for my matrix. So where should I put replaceAll("^s+", "") ?

private static void printMatrix(int[][] matrix) {
System.out.println();
System.out.println("Matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}

View Replies View Related

Laptop Screen Shows White Lines

Apr 28, 2014

When I open applications specially high graphics applications, the screen flashes with whole black display with a number of horizontal white lines then after 2 or 3 flashes it opens the desired program. What is the cause, is it low graphics memory, physically damaged screen or ?

View Replies View Related

Generating Picture - Black And White Sketch

Nov 19, 2014

I'm stuck with a problem. The code below generates a coloured image.

//Setting the size of the graphics window
final int WINDOW_DIMENSION = 200;
final int SIZE_FACTOR = 3;
EasyGraphics generate = new EasyGraphics(WINDOW_DIMENSION*SIZE_FACTOR,WINDOW_DIMENSION*SIZE_FACTOR);
 
//Constructing the arrays
char[][] firstArray = new char[WINDOW_DIMENSION][WINDOW_DIMENSION];
char[] secondArray = scan.toCharArray();
 
[Code] ...

What I would like to do is generate a picture which is mostly white but the colour boundaries of the original picture are in black. I tried using the code below but it doesn't produce what I wanted.

for (int a = 1; a < WINDOW_DIMENSION; a++) {
for (int b = 1; b < WINDOW_DIMENSION; b++) {
generate.setColor(0,0,0);
if(firstArray[a][b]!=firstArray[a-1][b] || firstArray[a][b]!=firstArray[a][b-1])
generate.setColor(255,255,255);
generate.plot(a,b);
}
}

View Replies View Related

JavaFX 2.0 :: Blank White Screen While Starting App?

Jun 24, 2015

This screen appears for a second and after this, it shows up normal app screen. How I can solve this issue? When I open app: after this

View Replies View Related

Pass A Command Line Argument Value With White Space In Between?

Feb 3, 2014

for example, I want to pass 'Hello Word.docx' and 'Winston' (both without quotes) as a command line argument as I execute the main method

Is it possible to pass 'Hello World.docx' as a whole word?

View Replies View Related

Drawing Simple Yellow Rectangle In White Background?

Feb 1, 2014

Here is the code, I just wanted to draw a simple yellow rectangle in white background...

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class NewEmpty extends Jframe {
Rectangle test = new Rectangle(100,100,100,100);
public NewEmpty()

[Code] .....

Errors in the compiler ( i think there's something wrong with that Jframe)

init:
deps-jar:
Compiling 1 source file to C:Users****Gametestbuildclasses
C:UsersMarcoGametestsrcgametestNewEmpty.java :6: error: cannot find symbol
public class NewEmpty extends Jframe {

[Code] .....

5 errors

BUILD FAILED (total time: 0 seconds)

View Replies View Related

Classing White Space As Invalid Name When Close Button Is Pressed

Oct 29, 2014

I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.

if(!writeSuccess)
{
//display output messages in JOptionPane
JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE);
//close the form
me.dispose();
}

If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?

View Replies View Related

JavaFX 2.0 :: Progress Indicator In ListView Has Border And White Background?

Dec 1, 2014

If I "embed" a ProgressIndicator inside a ListView it has an ugly border and a white background. It looks like there's a TextField below the ProgressIndicator.
 
Why does it behave like that and how to solve it so that the progress indicator is transparent.

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.ProgressIndicator;

[Code] .....

View Replies View Related

Unable To Remove White Background Of PNG Image Added In Transparent JPanel

Sep 25, 2014

I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...

import javax.swing.*;
import java.util.*;
import java.awt.*;
public class HomePage
{
JFrame frame;
JPanel pnl1, pnl2, pnl3;
JLabel lbl;

[Code] .....

View Replies View Related

Make Shapes Besides Making Two Lines For X And Oval With White Smaller Oval Inside To Make O

May 8, 2014

We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)

These are our instructions:

Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:

[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);

[code]....

View Replies View Related







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