java能不能把图片做出圆角来? RT,现在有张图片,我想用JAVA图形编程把图片处理下,做个圆角效果,不知道怎么做,希望牛人指点! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用一个圆角矩形设置个path!然后画图!!!应该就行 !!只是个思路!!晚上回来做下!! import java.awt.event.ActionListener;import java.awt.geom.GeneralPath;//import java.awt.geom.Rectangle2D;import java.awt.geom.RoundRectangle2D;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.swing.JFileChooser;import javax.swing.JFrame;//import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;//import javax.swing.JTextArea;//import javax.swing.JTextPane;import javax.swing.filechooser.FileNameExtensionFilter;public class GeneralPathRect { /** * @param args */ public static void main(String[] args) { new GeneralPathRectFrame(); }}class GeneralPathRectFrame extends JFrame{ private static final long serialVersionUID = 1L; private GeneralPath path=new GeneralPath(); BufferedImage image; JFileChooser chooser=new JFileChooser(); JMenuBar bar=new JMenuBar(); JPanel panel=new drawPanel(); public GeneralPathRectFrame() { setSize(400,400); JMenu file=new JMenu("file"); JMenuItem openItem=new JMenuItem("导入图片"); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub chooser.setCurrentDirectory(new File(".")); String []suffiex=ImageIO.getReaderFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image file",suffiex)); int ans=chooser.showOpenDialog(GeneralPathRectFrame.this); if(ans==JFileChooser.APPROVE_OPTION) { try { image=ImageIO.read(chooser.getSelectedFile()); repaint(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }}); file.add(openItem); //pane.insertComponent(area); add(panel); bar.add(file); setJMenuBar(bar); setVisible(true); } class drawPanel extends JPanel { private static final long serialVersionUID = 1L; public void paint(Graphics g) { Graphics2D g2=(Graphics2D)g; if(image!=null) { int width=image.getWidth(),height=image.getHeight(); RoundRectangle2D rect=new RoundRectangle2D.Double(0,0,width,height,20,20); path.append(rect,false); g2.setClip(path); g2.drawImage(image,0,0,null); } else g.drawString("nihoa",0,0); } } } java insert 帮看下这段代码是怎么实现的 HashMap这样删除一条记录 为什么会报错? 【急问】哪位高手愿意给出Struts关于多模块应用的简单的比较完整的开发实例,不要简单的说用SwitchAction等,高分相送!谢谢! 请问一个将字符串转换为long的程序 菜鸟请教一个关于appletviewer问题 有关API各位帮帮吧 this---->java的单步运行?? 1394接口编程 我写的应用程序MAIN FRAME都很长,怎样才能让结构合理,大家提提意见,都有分。 如何让这段代码每隔一小时执行一次,不用crontab。 急~~求高手帮我解决一个字符串哈希算法的问题!!
import java.awt.event.ActionListener;
import java.awt.geom.GeneralPath;
//import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
//import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
//import javax.swing.JTextArea;
//import javax.swing.JTextPane;
import javax.swing.filechooser.FileNameExtensionFilter;
public class GeneralPathRect
{ /**
* @param args
*/
public static void main(String[] args)
{
new GeneralPathRectFrame(); }}
class GeneralPathRectFrame extends JFrame
{
private static final long serialVersionUID = 1L;
private GeneralPath path=new GeneralPath();
BufferedImage image;
JFileChooser chooser=new JFileChooser();
JMenuBar bar=new JMenuBar();
JPanel panel=new drawPanel();
public GeneralPathRectFrame()
{
setSize(400,400);
JMenu file=new JMenu("file");
JMenuItem openItem=new JMenuItem("导入图片");
openItem.addActionListener(new ActionListener()
{ @Override
public void actionPerformed(ActionEvent arg0)
{
// TODO Auto-generated method stub
chooser.setCurrentDirectory(new File("."));
String []suffiex=ImageIO.getReaderFileSuffixes();
chooser.setFileFilter(new FileNameExtensionFilter("Image file",suffiex));
int ans=chooser.showOpenDialog(GeneralPathRectFrame.this);
if(ans==JFileChooser.APPROVE_OPTION)
{
try
{
image=ImageIO.read(chooser.getSelectedFile());
repaint();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}});
file.add(openItem);
//pane.insertComponent(area);
add(panel);
bar.add(file);
setJMenuBar(bar);
setVisible(true);
}
class drawPanel extends JPanel
{
private static final long serialVersionUID = 1L; public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
if(image!=null)
{
int width=image.getWidth(),height=image.getHeight();
RoundRectangle2D rect=new RoundRectangle2D.Double(0,0,width,height,20,20);
path.append(rect,false);
g2.setClip(path);
g2.drawImage(image,0,0,null);
}
else g.drawString("nihoa",0,0);
}
}
}