java 加载图片错误,只能加载一部分
importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JScrollPane;impor...
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class MainFrame extends JFrame
{
static int end_X,end_Y,start_X,start_Y;
ImagePanel image;
public MainFrame(){
init();
}
public void init(){
this.setLayout(null);
image=new ImagePanel();
JScrollPane scroll=new JScrollPane(image);
table_scroll.setBounds(0,600,1024,138);
this.getContentPane().add(scroll);
scroll.setBounds(224,0,800,600);
image.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
start_X=e.getX();
start_Y=e.getY();
}
});
image.addMouseMotionListener(new MouseAdapter()
{
public void mouseDragged(MouseEvent e)
{
end_X=image.getX()+e.getX()-start_X;
end_Y=image.getY()+e.getY()-start_Y;
image.setLocation(end_X,end_Y);
}
});
this.setSize(1024,738);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
new MainFrame();
}
}
class ImagePanel extends JPanel
{
private BufferedImage image;
public ImagePanel(){
try{
image=ImageIO.read(new FileInputStream("C:\\0_0.jpg"));
}catch(IOException e){
e.printStackTrace();
}
}
public void paintComponent(Graphics g){
g.drawImage(image,0,0,null);
}
}
我的图片是3344*4480的,为什么加载到滚动面板上就是有一部分了。 展开
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class MainFrame extends JFrame
{
static int end_X,end_Y,start_X,start_Y;
ImagePanel image;
public MainFrame(){
init();
}
public void init(){
this.setLayout(null);
image=new ImagePanel();
JScrollPane scroll=new JScrollPane(image);
table_scroll.setBounds(0,600,1024,138);
this.getContentPane().add(scroll);
scroll.setBounds(224,0,800,600);
image.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
start_X=e.getX();
start_Y=e.getY();
}
});
image.addMouseMotionListener(new MouseAdapter()
{
public void mouseDragged(MouseEvent e)
{
end_X=image.getX()+e.getX()-start_X;
end_Y=image.getY()+e.getY()-start_Y;
image.setLocation(end_X,end_Y);
}
});
this.setSize(1024,738);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
new MainFrame();
}
}
class ImagePanel extends JPanel
{
private BufferedImage image;
public ImagePanel(){
try{
image=ImageIO.read(new FileInputStream("C:\\0_0.jpg"));
}catch(IOException e){
e.printStackTrace();
}
}
public void paintComponent(Graphics g){
g.drawImage(image,0,0,null);
}
}
我的图片是3344*4480的,为什么加载到滚动面板上就是有一部分了。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询