I have a program where a user submits a picture and then it display with the character. However, there is a problem if the user submits a big picture file.
Does anyone know how I can make the picture a (200,200) image when it is submitted? Or would you do the resizing when you make the imageicon? If so, how would I go about doing it?
Here is part of the code, may be use to anyone that helps or maybe it is not even the right spot....
This is what I have, other than the innitial entering file stuff
public CharViewDialog(Main parent, boolean modal, VideoCharacter v, Connection connection) {
super(parent, modal);
try {
initComponents();
String html = "<html>" + "<table>" + "<tr>" + "<th>Name</th><td>" + v.getName() + "</td>" + "</tr> <tr>" + "<th>Height</th><td>" + v.getHeight() + "</td>" + "</tr> <tr>" + "<th>Weight</th><td>" + v.getWeight() + "</td>" + "</tr> <tr>" + "<th>Alignment</th><td>" + v.getAlignmemt() + "</td>" + "</tr> <tr>" + "<th>Species</th><td>" + v.getSpeciesID() + "</td>" + "</tr> <tr>" + "<th>Date Created</th><td>" + v.getCreated() + "</td>" + "</tr> <tr>" + "<th>Gender</th><td>" + v.getGender() + "</td>" + "</tr> <tr>" + "<th>Bio</th><td>" + v.getBio() + "</td>" + "</tr> <tr>" + "<th>Level</th><td>" + v.getLevel() + "</td>" + "</tr> <tr>" + "<th>AI</th><td>" + v.isAI() + "</td>" + "</tr>" + "</table>" + "</html>";
ArrayList<Byte> imageData = new ArrayList<Byte>();
PreparedStatement psmnt = connection.prepareStatement("SELECT IMAGE FROM character where id=?");
psmnt.setInt(1, v.getId());
ResultSet rs = psmnt.executeQuery();
if (rs.next()) {
InputStream fis1;
fis1 = rs.getBinaryStream("image");
int c;
while ((c = fis1.read()) != -1) {
imageData.add((byte) c);
}
fis1.close();
}
rs.close();
psmnt.close();
if (imageData.size() > 0) {
byte x[] = new byte[imageData.size()];
for (int i = 0; i < imageData.size(); i++) {
x = imageData.get(i);
}
ImageIcon ic = new ImageIcon(x);
lblMe.setIcon(ic);
}
lblMe.setText(html);
this.pack();
} catch (IOException ex) {
Logger.getLogger(CharViewDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(CharViewDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
Does anyone know how I can make the picture a (200,200) image when it is submitted? Or would you do the resizing when you make the imageicon? If so, how would I go about doing it?
Here is part of the code, may be use to anyone that helps or maybe it is not even the right spot....
This is what I have, other than the innitial entering file stuff
public CharViewDialog(Main parent, boolean modal, VideoCharacter v, Connection connection) {
super(parent, modal);
try {
initComponents();
String html = "<html>" + "<table>" + "<tr>" + "<th>Name</th><td>" + v.getName() + "</td>" + "</tr> <tr>" + "<th>Height</th><td>" + v.getHeight() + "</td>" + "</tr> <tr>" + "<th>Weight</th><td>" + v.getWeight() + "</td>" + "</tr> <tr>" + "<th>Alignment</th><td>" + v.getAlignmemt() + "</td>" + "</tr> <tr>" + "<th>Species</th><td>" + v.getSpeciesID() + "</td>" + "</tr> <tr>" + "<th>Date Created</th><td>" + v.getCreated() + "</td>" + "</tr> <tr>" + "<th>Gender</th><td>" + v.getGender() + "</td>" + "</tr> <tr>" + "<th>Bio</th><td>" + v.getBio() + "</td>" + "</tr> <tr>" + "<th>Level</th><td>" + v.getLevel() + "</td>" + "</tr> <tr>" + "<th>AI</th><td>" + v.isAI() + "</td>" + "</tr>" + "</table>" + "</html>";
ArrayList<Byte> imageData = new ArrayList<Byte>();
PreparedStatement psmnt = connection.prepareStatement("SELECT IMAGE FROM character where id=?");
psmnt.setInt(1, v.getId());
ResultSet rs = psmnt.executeQuery();
if (rs.next()) {
InputStream fis1;
fis1 = rs.getBinaryStream("image");
int c;
while ((c = fis1.read()) != -1) {
imageData.add((byte) c);
}
fis1.close();
}
rs.close();
psmnt.close();
if (imageData.size() > 0) {
byte x[] = new byte[imageData.size()];
for (int i = 0; i < imageData.size(); i++) {
x = imageData.get(i);
}
ImageIcon ic = new ImageIcon(x);
lblMe.setIcon(ic);
}
lblMe.setText(html);
this.pack();
} catch (IOException ex) {
Logger.getLogger(CharViewDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(CharViewDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}