如题
  要求可以用鼠标拖动截图区大小和显示截图区预览
鼠标双击后截取图片存储到指定文件夹

解决方案 »

  1.   

    首先用js来确定截取的图片的范围,给整个图片和截取范围信息传递给jsp程序,通过Java来截取
    js确定截取图片的代码:http://topic.csdn.net/u/20080806/02/B295D4E4-C98F-4621-9835-B7D915B4952D.html
    然后通过java来截取对应的图片即可完成楼主的功能!
      

  2.   


     呵
     太谢谢了
      不过用java怎么截取图片还是不知道哦 `
        拜托了
      
      

  3.   

    java截图
    import java.awt.Dimension;   
    import java.awt.Rectangle;   
    import java.awt.Robot;   
    import java.awt.Toolkit;   
    import java.awt.image.BufferedImage;   
    import java.io.File;   
      
    import javax.imageio.ImageIO;   
      
    /*******************************************************************************  
     * 该JavaBean可以直接在其他Java应用程序中调用,实现屏幕的"拍照" This JavaBean is used to snapshot the  
     * GUI in a Java application! You can embeded it in to your java application  
     * source code, and us it to snapshot the right GUI of the application  
     *   
     * @see javax.ImageIO  
     * @author liluqun ([email protected])  
     * @version 1.0  
     *   
     ******************************************************************************/  
      
    class GuiCamera   
    {   
        private String fileName; // 文件的前缀   
      
        private String defaultName = "GuiCamera";   
      
        static int serialNum = 0;   
      
        private String imageFormat; // 图像文件的格式   
      
        private String defaultImageFormat = "png";   
      
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();   
      
        /***********************************************************************  
         * 默认的文件前缀为GuiCamera,文件格式为PNG格式 The default construct will use the  
         * default Image file surname "GuiCamera", and default image format  
         * "png"  
         **********************************************************************/  
        public GuiCamera()   
        {   
        fileName = defaultName;   
        imageFormat = defaultImageFormat;   
        }   
      
        /***********************************************************************  
         * @param s  
         *                the surname of the snapshot file  
         * @param format  
         *                the format of the image file, it can be "jpg" or "png"  
         *                本构造支持JPG和PNG文件的存储  
         **********************************************************************/  
        public GuiCamera(String s, String format)   
        {   
        fileName = s;   
        imageFormat = format;   
        }   
      
        /***********************************************************************  
         * 对屏幕进行拍照 snapShot the Gui once  
         **********************************************************************/  
        public void snapShot()   
        {   
        try  
        {   
            // 拷贝屏幕到一个BufferedImage对象screenshot
           //这里 createScreenCapture中的4个参数就是需要截取的图形的2个顶点,也就是通过js确定的2个点
            BufferedImage screenshot = (new Robot())   
                .createScreenCapture(new Rectangle(0, 0,   
                    (int) d.getWidth(), (int) d.getHeight()));   
            serialNum++;   
            // 根据文件前缀变量和文件格式变量,自动生成文件名   
            String name = fileName + String.valueOf(serialNum) + "."  
                + imageFormat;   
            File f = new File(name);   
            System.out.print("Save File " + name);   
            // 将screenshot对象写入图像文件   
            ImageIO.write(screenshot, imageFormat, f);   
            System.out.print("..Finished! ");   
        } catch (Exception ex)   
        {   
            System.out.println(ex);   
        }   
        }   
      
        public static void main(String[] args)   
        {   
        GuiCamera cam = new GuiCamera("Test", "png");   
        cam.snapShot();   
        }   
    }
      

  4.   

    ProvidenceZY 
     太感谢了
     o(∩_∩)o...
      

  5.   

    楼主,你试过了吗?能成功吗?
    java是运行在服务器端的语言。而javascript运行在客户端。按照你所传的参数所截取的应该是服务器的屏幕而不是客户端!!!!
      

  6.   

    找一下关于gis的开源代码里面,就有这个功能
      

  7.   

    这是不可能的,除非在客户端做一个Applet
      

  8.   

    可以在叶面发送尺寸指令,服务器上AJAX调用一个exe来截,不过限于登陆信息不需要或者可以用url参数模拟的情况下。
      

  9.   

    操作跟qq一样。
    要不就装qq把,先按ctrl+alt+a打开截图功能,然后按照楼主的那种操作就可以截图了。
      

  10.   

    js确定范围,applet抓图
    但是applet有个安全问题,默认是不能访问客户端资源的,需要签名!
      

  11.   

    用这段java程序保存图片的路径在哪里?我运行后怎么找不到图片
      

  12.   

    值得学习,我是刚学jsp的,也是刚想踏入程序员行列的学生,希望大家多多关照啊
      

  13.   

    目前,貌似只能通过activex控件或applet来实现,js是运行在客户端的,如果执行服务器端java代码,
    截取的是服务器端的截屏,是截不到客户的截屏的。
      

  14.   

    首先用js来确定截取的图片的范围,给整个图片和截取范围信息传递给jsp程序,通过Java来截取
      

  15.   

    顶!!!!!!11
    第一次进来,里面人气不够 
    我是有一个问题想问大家,希望 能得到帮助,
    谢谢!
    设计并实现一个简单的输入程序
    程序要求:
          1. 要求输入学号、姓名、班级、课程名称、成绩,并保存到数据库中;
          2. 请尽量美化界面;
          3. 课程名称和班级名称要以下拉选择的方式输入;
          4. 采用相应的数据库管理系统直接打开数据库,察看数据输入是否正确。
    数据库设计要求:起码要有课程表、班级表、学生名单表、成绩表等四个表,字段的属性要求正确设置。
    基础数据处理:先用相应的数据库管理系统,直接输入2个以上班级、2门以上课程、3个以上学生的基本情况。
    可采用任何语言和任何数据库管理系统,C/S或B/S模式,实现本功能。
      

  16.   

    只用JS也只有一点挑战而已..除非客户端组件也不能用..比如不能用FSO保存文件..那才有挑战了
      

  17.   


    package test_img;import java.awt.*;   
    import java.awt.image.BufferedImage;   
    import java.io.ByteArrayOutputStream;
    import java.io.File;   
      
    import javax.imageio.ImageIO;   import com.sun.image.codec.jpeg.JPEGImageEncoder;import sun.awt.image.ToolkitImage;
      class GuiCamera   
    {   
        private String fileName; // 文件的前缀   
      
        private String defaultName = "GuiCamera";   
      
        static int serialNum = 0;   
      
        private String imageFormat; // 图像文件的格式   
      
        private String defaultImageFormat = "jpg";   
      
    //    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();   
      
         
        public GuiCamera()   
        {   
        fileName = defaultName;   
        imageFormat = defaultImageFormat;   
        }   
      
        public GuiCamera(String s, String format)   
        {   
        fileName = s;   
        imageFormat = format;   
        }   
      
     
        public void snapShot(String resource,int x,int y,int width,int height)   
        {   
        try  
        {   
           
         Image img = ImageIO.read(GuiCamera.class.getClassLoader().getResource(resource)); 
         BufferedImage screenshot = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_3BYTE_BGR);
         Graphics g = screenshot.getGraphics();
         g.drawImage(img, 0,0, null);
         g.drawString("cut image", 50, 50);
         screenshot = screenshot.getSubimage(x, y, width, height);
         g.dispose();
         screenshot.flush();
         serialNum++;   
            // 根据文件前缀变量和文件格式变量,自动生成文件名   
            String name = fileName + String.valueOf(serialNum) + "."  
                + imageFormat;   
            File f = new File(name);   
            System.out.print("Save File " + name);   
            // 将screenshot对象写入图像文件   
            ImageIO.write(screenshot, imageFormat, f);   
            
            System.out.print("..Finished! ");   
        } catch (Exception ex)   
        {   
            System.out.println(ex);   
        }   
        }   
        
        public static void main(String[] args)   
        {   
        GuiCamera cam = new GuiCamera("Test", "jpg");   
        cam.snapShot("img/demo1.jpg",20,20,200,100);   
        }   
    }
      

  18.   

    截取图片中的一部分可以,但是你要截网页Div,Table的图,就囧了。
      

  19.   

    java思想真多啊!
         变来变去的!
      

  20.   


    下面代码中用到的sourceImage是一个已经存在的Image对象  图像剪切  对于一个已经存在的Image对象,要得到它的一个局部图像,可以使用下面的步骤://import java.awt.*;
    //import java.awt.image.*;
    Image croppedImage;
    ImageFilter cropFilter;
    CropFilter =new CropImageFilter(25,30,75,75);//四个参数分别为图像起点坐标和宽高,即CropImageFilter(int x,int y,int width,int height),详细情况请参考API
    CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));
    //如果是在Component的子类中使用,可以将上面的Toolkit.getDefaultToolkit().去掉。
    //FilteredImageSource是一个ImageProducer对象。   图像缩放  对于一个已经存在的Image对象,得到它的一个缩放的Image对象可以使用Image的getScaledInstance方法:Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT);//得到一个100X100的图像
    Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT);//得到一个放大两倍的图像,这个程序一般在一个swing的组件中使用,而类Jcomponent实现了图像观察者接口ImageObserver,所有可以使用this。
    //其它情况请参考API。   灰度变换  下面的程序使用三种方法对一个彩色图像进行灰度变换,变换的效果都不一样。一般而言,灰度变换的算法是将象素的三个颜色分量使用R*0.3+G*0.59+B*0.11得到灰度值,然后将之赋值给红绿蓝,这样颜色取得的效果就是灰度的。另一种就是取红绿蓝三色中的最大值作为灰度值。java核心包也有一种算法,但是没有看源代码,不知道具体算法是什么样的,效果和上述不同。/* GrayFilter.java*/
    /*@author:cherami */
    /*email:[email protected]*/
    import java.awt.image.*;public class GrayFilter extends RGBImageFilter {
    int modelStyle;
    public GrayFilter() {
    modelStyle=GrayModel.CS_MAX;
    canFilterIndexColorModel=true;
    }
    public GrayFilter(int style) {
    modelStyle=style;
    canFilterIndexColorModel=true;
    }
    public void setColorModel(ColorModel cm) {
    if (modelStyle==GrayModel.CS_MAX) {
    substituteColorModel(cm,new GrayModel(cm));
    }
    else if (modelStyle==GrayModel.CS_FLOAT) {
    substituteColorModel(cm,new GrayModel(cm,modelStyle));
    }
    }
    public int filterRGB(int x,int y,int pixel) {
    return pixel;
    }
    }/* GrayModel.java*/
    /*@author:cherami */
    /*email:[email protected]*/import java.awt.image.*;public class GrayModel extends ColorModel {
    public static final int CS_MAX=0;
    public static final int CS_FLOAT=1;
    ColorModel sourceModel;
    int modelStyle;
    public GrayModel(ColorModel sourceModel) {
    super(sourceModel.getPixelSize());
    this.sourceModel=sourceModel;
    modelStyle=0;
    }
    public GrayModel(ColorModel sourceModel,int style) {
    super(sourceModel.getPixelSize());
    this.sourceModel=sourceModel;
    modelStyle=style; 
    }
    public void setGrayStyle(int style) {
    modelStyle=style;
    }
    protected int getGrayLevel(int pixel) {
    if (modelStyle==CS_MAX) {
    return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));
    }
    else if (modelStyle==CS_FLOAT){
    return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);
    }
    else {
    return 0;
    }
    }
    public int getAlpha(int pixel) {
    return sourceModel.getAlpha(pixel);
    }
    public int getRed(int pixel) {
    return getGrayLevel(pixel);
    }
    public int getGreen(int pixel) {
    return getGrayLevel(pixel);
    }
    public int getBlue(int pixel) {
    return getGrayLevel(pixel);
    }
    public int getRGB(int pixel) {
    int gray=getGrayLevel(pixel);
    return (getAlpha(pixel)<<24)+(gray<<16)+(gray<<8)+gray;
    }
    }   如果你有自己的算法或者想取得特殊的效果,你可以修改类GrayModel的方法getGrayLevel()。
      色彩变换  根据上面的原理,我们也可以实现色彩变换,这样的效果就很多了。下面是一个反转变换的例子:/* ReverseColorModel.java*/
    /*@author:cherami */
    /*email:[email protected]*/
    import java.awt.image.*;public class ReverseColorModel extends ColorModel {
    ColorModel sourceModel;
    public ReverseColorModel(ColorModel sourceModel) {
    super(sourceModel.getPixelSize());
    this.sourceModel=sourceModel;
    }
    public int getAlpha(int pixel) {
    return sourceModel.getAlpha(pixel);
    }
    public int getRed(int pixel) {
    return ~sourceModel.getRed(pixel);
    }
    public int getGreen(int pixel) {
    return ~sourceModel.getGreen(pixel);
    }
    public int getBlue(int pixel) {
    return ~sourceModel.getBlue(pixel);
    }
    public int getRGB(int pixel) {
    return (getAlpha(pixel)<<24)+(getRed(pixel)<<16)+(getGreen(pixel)<<8)+getBlue(pixel);
    }
    }
    /* ReverseColorModel.java*/
    /*@author:cherami */
    /*email:[email protected]*/import java.awt.image.*;public class ReverseFilter extends RGBImageFilter {
    public ReverseFilter() {
    canFilterIndexColorModel=true;
    }
    public void setColorModel(ColorModel cm) {
    substituteColorModel(cm,new ReverseColorModel(cm));
    }
    public int filterRGB(int x,int y,int pixel) {
    return pixel;
    }
    }   要想取得自己的效果,需要修改ReverseColorModel.java中的三个方法,getRed、getGreen、getBlue。
    下面是上面的效果的一个总的演示程序。/*GrayImage.java*/
    /*@author:cherami */
    /*email:[email protected]*/
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.awt.color.*;public class GrayImage extends JFrame{
    Image source,gray,gray3,clip,bigimg;
    BufferedImage bimg,gray2;
    GrayFilter filter,filter2;
    ImageIcon ii;
    ImageFilter cropFilter;
    int iw,ih;
    public GrayImage() {
    ii=new ImageIcon("images/11.gif");
    source=ii.getImage();
    iw=source.getWidth(this);
    ih=source.getHeight(this);
    filter=new GrayFilter();
    filter2=new GrayFilter(GrayModel.CS_FLOAT);
    gray=createImage(new FilteredImageSource(source.getSource(),filter));
    gray3=createImage(new FilteredImageSource(source.getSource(),filter2));
    cropFilter=new CropImageFilter(5,5,iw-5,ih-5);
    clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));
    bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);
    MediaTracker mt=new MediaTracker(this);
    mt.addImage(gray,0);
    try {
    mt.waitForAll();
    } catch (Exception e) {
    }
    }
    public void paint(Graphics g) {
    Graphics2D g2=(Graphics2D)g;
    bimg=new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    Graphics2D srcG = bimg.createGraphics();
    RenderingHints rhs = g2.getRenderingHints();
    srcG.setRenderingHints(rhs);
    srcG.drawImage(source, 0, 0, null);
    ColorSpace graySpace=ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorConvertOp op=new ColorConvertOp(graySpace,rhs);
    gray2=new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    op.filter(bimg,gray2);
    g2.drawImage(source,40,40,this);
    g2.drawImage(gray,80,40,this);
    g2.drawImage(gray2,120,40,this);
    g2.drawImage(gray3,160,40,this);
    g2.drawImage(clip,40,80,this);
    g2.drawImage(bigimg,80,80,this);
    }
    public void update(Graphics g) {
    paint(g);
    }
    public static void main(String args[]) {
    GrayImage m=new GrayImage();
    m.setSize(400,400);
    m.setVisible(true);
    }

      

  21.   

    突然有个想法:java 里面执行cmd命令打开 一个截图工具.exe