Jump to content

Como redimensionar imagem dentro de uma jlabel?


Reinilton
 Share

Recommended Posts

Bom dia,

private Image getScaledImage(Image srcImg, int w, int h){
   BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g2 = resizedImg.createGraphics();
   g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
   g2.drawImage(srcImg, 0, 0, w, h, null);
   g2.dispose();
   return resizedImg;
}

Creio que isto resolve o problema.

Cordiais cumprimentos,

Apocsantos

"A paciência é uma das coisas que se aprendeu na era do 48k" O respeito é como a escrita de código, uma vez perdido, dificilmente se retoma o habito"

Link to comment
Share on other sites

Fiz isso aqui mas não consegui colocar o trecho que você colocou

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Image;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.border.LineBorder;

public class AlbumDeFotos extends JFrame{

JLabel jlabel;

JButton botao;

ImageIcon imageIcon;

Image imagem;

Dimension dimensao;

public AlbumDeFotos() {

super("Minha Janela");

setSize(800,600);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setLayout(null);

setVisible(true);

}

public void distribui(){

jlabel = new JLabel();

jlabel.setBounds(10, 10, 100, 100);

jlabel.setBackground(Color.red);

jlabel.setBorder(LineBorder.createBlackLineBorder());

jlabel.setVisible(true);

add(jlabel);

imageIcon = new ImageIcon(getClass().getResource("imagens//imagem1.jpg"));

jlabel.setIcon(imageIcon);

}

public static void main(String[] args) {

new AlbumDeFotos().distribui();

}

}

Edited by Reinilton
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.