Results 1 to 4 of 4
Thread: ImageIcon and size
- 12-20-2008, 08:16 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
ImageIcon and size
Hi guys,
I have problem,I´want change size at ImageIcon,but I can´t it.This is my code:
Can you help me??Java Code:package dalsik; import java.awt.*; import javax.swing.*; import java.net.*; public class Main extends JFrame{ public Main() throws Exception{ super("None"); setSize(400,400); Container c=getContentPane(); FlowLayout layout=new FlowLayout(); c.setLayout(layout); ImageIcon vv=new ImageIcon("C:\\image.jpg"); // I want resize this picture (image.jpg) JLabel jl=new JLabel("",vv,JLabel.LEFT); c.add(jl); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); } public static void main(String[] args) throws Exception{ Main m=new Main();m.setVisible(true); } }
Thanks for your answers.
-
So, rather than reply to morgalr's reply to your original post in the Sun Java forums here: Java 2D - ImageIcon and size
You have decided to waste someone else's time by cross-posting this same question here. That's not very considerate of you.
- 12-21-2008, 12:08 AM #3
Java Code:import java.awt.*; import java.awt.image.BufferedImage; import java.net.URL; import javax.swing.*; public class MainResize extends JFrame { public MainResize() { super("None"); // setSize(400,400); Container c=getContentPane(); c.setLayout(new GridLayout(1,0)); // I want resize this picture (image.jpg) String path = //"images/bison.jpg"; "C:/image.jpg"; URL url = getClass().getResource(path); System.out.println("url = " + url); ImageIcon vv=new ImageIcon(url); JLabel jl=new JLabel("",vv,JLabel.LEFT); c.add(jl); c.add(new JLabel(scale(vv.getImage(), 0.75))); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); setVisible(true); } private ImageIcon scale(Image src, double scale) { int w = (int)(scale*src.getWidth(this)); int h = (int)(scale*src.getHeight(this)); int type = BufferedImage.TYPE_INT_RGB; BufferedImage dst = new BufferedImage(w, h, type); Graphics2D g2 = dst.createGraphics(); g2.drawImage(src, 0, 0, w, h, this); g2.dispose(); return new ImageIcon(dst); } public static void main(String[] args) { new MainResize(); } }
- 12-21-2008, 08:47 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
String max size
By eva in forum New To JavaReplies: 0Last Post: 01-31-2008, 02:29 PM -
Detect loading of ImageIcon from URL?
By barkster in forum Java AppletsReplies: 1Last Post: 01-29-2008, 07:04 PM -
File size
By eva in forum New To JavaReplies: 2Last Post: 12-19-2007, 09:27 AM -
Object size
By kavithas in forum New To JavaReplies: 0Last Post: 11-30-2007, 12:00 PM -
copy image/imageicon into a file on disk
By archanajathan in forum Advanced JavaReplies: 2Last Post: 11-22-2007, 06:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks