• 大小: 2KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: Java
  • 标签: java  

资源简介

使用J2SE 对jpeg格式的图片进行操控,并实现一定的绘图功能

资源截图

代码片段和文件信息

import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;
class Point
{int xy;
 Point(int xint y)
 {this.x=x;this.y=y;
 }
}
public class MakeJPEG extends Canvas implements MouseMotionListenerMouseListenerActionListener
{  
   int x=-1y=-1橡皮擦通知=0清除通知=0;
   Vector v=null;int n=1;
   Graphics2D  ggg ;                                             
   BufferedImage image;                                          
   frame window;
   Button 保存调色板橡皮清除画笔获取屏幕绘制图形;
   Color 画笔颜色;
   Panel pCenterpSouthpNorth;
  
 public MakeJPEG()
 { 
    保存=new Button(“将绘制的图形或屏幕保存为JPG文件“);
    获取屏幕=new Button(“获取屏幕“);
    绘制图形=new Button(“绘制图形“);
    调色板=new Button(“打开调色板“);
    画笔=new Button(“画笔“);
    橡皮=new Button(“橡皮“);
    清除=new Button(“清除“);
    调色板.addActionListener(this);
    绘制图形.addActionListener(this);
    保存.addActionListener(this);
    画笔.addActionListener(this);
    橡皮.addActionListener(this);
    清除.addActionListener(this);
    获取屏幕.addActionListener(this);
    画笔颜色=new Color(000);
    addMouseMotionListener(this); 
    addMouseListener(this);
    v=new Vector(); 
    setBackground(Color.white);                                 
    image=new BufferedImage(200200BufferedImage.TYPE_INT_RGB);
    ggg=image.createGraphics();                                 
    Rectangle2D rect=new Rectangle2D.Double(00200200);      
    ggg.setColor(getBackground());
    ggg.fill(rect);                                             
    window=new frame(“JPEG图像生成器“);
    pCenter=new Panel();
    pCenter.setLayout(null);
    pCenter.add(this);
    pCenter.setBackground(Color.gray);
    this.setBounds(8030210210);                              
    window.add(pCenterBorderLayout.CENTER);
    pNorth=new Panel();
    pNorth.add(保存);
    pNorth.add(绘制图形);
    pNorth.add(获取屏幕);
    window.add(pNorthBorderLayout.NORTH);
    pSouth=new Panel();
    pSouth.add(调色板);
    pSouth.add(橡皮);
    pSouth.add(清除);
    pSouth.add(画笔);
    window.add(pSouthBorderLayout.SOUTH);
    window.setVisible(true);
    window.addWindowListener(new WindowAdapter()
                   { 
                     public void windowClosing(WindowEvent e)
                     { 
                        System.exit(0);
                    }
                  });
    window.setBounds(10080390380);
    window.validate();                                         
 }
 public void paint(Graphics g)                                 
 {
    if(x!=-1&&y!=-1&&橡皮擦通知==0&&清除通知==0)
     {  
        g.setColor(画笔颜色);
        n=v.size();
        for(int i=0;i         {
           Point p1=(Point)v.elementAt(i); 
           Point p2=(Point)v.elementAt(i+1); 
           g.drawLine(p1.xp1.yp2.xp2.y);                     
           ggg.setColor(g.getColor());
           ggg.draw

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       6992  2003-12-09 08:54  MakeJPEG.java

----------- ---------  ---------- -----  ----

                 6992                    1


评论

共有 条评论