📄 screenshot.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import com.sun.image.codec.jpeg.*;
import org.compiere.util.*;
/**
* JPEG File Utility
*
* @author Jorg Janke
* @version $Id: ScreenShot.java,v 1.2 2002/09/21 04:01:26 jjanke Exp $
*/
public class ScreenShot
{
/**
* Create JPEG file from window
* @param window window
* @param fileName optional file name
* @return true if created
*/
public static boolean createJPEG (Window window, String fileName)
{
if (window == null || fileName == null)
new IllegalArgumentException("ScreenShot.createJPEG Window os NULL");
// Get File
File file = getJPGFile (window);
if (file == null)
return false;
Log.trace(Log.l3_Util, "ScreenShot.createJPEG", "File=" + file);
if (file.exists())
file.delete();
// Get Writer
Iterator writers = ImageIO.getImageWritersByFormatName("jpg");
ImageWriter writer = (ImageWriter)writers.next();
if (writer == null)
{
Log.error("ScreenShot.createJPEG - no ImageWriter");
return false;
}
// Get Image
BufferedImage bi = getImage(window);
// Write Image
try
{
ImageOutputStream ios = ImageIO.createImageOutputStream (file);
writer.setOutput(ios);
writer.write(bi);
ios.flush();
ios.close();
}
catch (IOException ex)
{
Log.error("ScreenShot.createJPEG", ex);
return false;
}
return true;
} // createJPEG
/**
* Get JPEG File
* @param parent parent
* @return file
*/
protected static File getJPGFile (Component parent)
{
JFileChooser fc = new JFileChooser();
fc.addChoosableFileFilter(new ExtensionFileFilter("jpg", "JPEG"));
if (fc.showSaveDialog(parent) != JFileChooser.APPROVE_OPTION)
return null;
File file = fc.getSelectedFile();
if (file == null)
return null;
String fileName = file.getAbsolutePath();
if (!(fileName.toUpperCase().equals(".JPG") || fileName.toUpperCase().equals(".JPEG")))
fileName += ".jpg";
return new File (fileName);
} // getFile
/**
* Get Image of Window
* @param window window
* @return image
*/
protected static BufferedImage getImage (Window window)
{
BufferedImage bi = new BufferedImage (window.getWidth(), window.getHeight(),
BufferedImage.TYPE_INT_RGB); // TYPE_INT_ARGB is tinted red
window.paintAll(bi.createGraphics());
return bi;
} // getImage
} // ScreenShot
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -