• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display image on a JLabel from a blob column in Oracle database  RSS feed

 
Victor Godwin
Greenhorn
Posts: 2
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have been struggling for days now trying to figure out how I can display an image on a jLabel from a blob column in oracle database but all efforts seems not sufficient to produce desired results. The problem is that the Label displays a dark colour stuff like background. I've spent so much time googling and also searching here on the stack overflow but, the available resources aren't putting me through Please help me out !. thanks. Below is the code segment I'm working with .....

[code=java][/ private void studentIdItemStateChanged(java.awt.event.ItemEvent evt) {
String id = (String)studentId.getSelectedItem();


try{


con = DriverManager.getConnection("jdbcdbc:test", "SYSTEM", "VICTOR");
stmt = con.createStatement();
result = stmt.executeQuery("select * from STUDENTDBASE.STUDENT where Student_Id = '" + id + "' ");
result = stmt.getResultSet();

while (result.next()){
surname.setText(result.getString("Surname"));
firstName.setText(result.getString("First_Name"));
otherNames.setText(result.getString("Other_Names"));
phoneNumber.setText(result.getString("Mobile_Number"));
dob.setText(result.getString("Date_Of_Birth"));
gender.setText(result.getString("Gender"));
address.setText(result.getString("Address"));
state.setText(result.getString("State"));
lga.setText(result.getString("Lga"));

}
result.close();


PreparedStatement ps;
con = DriverManager.getConnection("jdbcdbc:test", "SYSTEM", "VICTOR");
ps = (PreparedStatement) con.prepareStatement("select Image from STUDENTDBASE.STUDENT_Images where STUDENT_ID = '" + id + "' ");
result2 = ps.executeQuery();

while (result2.next()){


InputStream in = result2.getBinaryStream("Image");


BufferedImage im = ImageIO.read(in);
BufferedImage outimage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = outimage.createGraphics();

float xScale = (float)image.getWidth() / outimage.getWidth();
float yScale = (float)image.getHeight() / outimage.getHeight();
AffineTransform at = AffineTransform.getScaleInstance(xScale,yScale);
g.drawRenderedImage(im,at);
g.dispose();
Image scaledImage = outimage.getScaledInstance(image.getWidth(), image.getHeight(), Image.SCALE_SMOOTH);
ImageIcon icon = new ImageIcon(scaledImage);
image.setIcon(icon);
image.revalidate();
basicDetails.revalidate();
}
result2.close();
con.close();
}
catch(SQLException d){
JOptionPane.showMessageDialog(null, "Error is due to " + d.getMessage(), "Error message from database", JOptionPane.ERROR_MESSAGE);
}
catch(IOException io){
JOptionPane.showMessageDialog(null, "Error is due to " + io.getMessage(), "Error message from database", JOptionPane.ERROR_MESSAGE);
}]
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using TYPE_INT_ARGB instead of TYPE_INT_RGB. The latter does not support transparency.
 
Victor Godwin
Greenhorn
Posts: 2
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rob I have tried that but it doesn't work too. I think it's a general challenge java developers face cause in my course of research, I realised others did had this same issue. Please more help ! thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!