本文整理汇总了Java中javax.imageio.ImageIO类的典型用法代码示例。如果您正苦于以下问题:Java ImageIO类的具体用法?Java ImageIO怎么用?Java ImageIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageIO类属于javax.imageio包,在下文中一共展示了ImageIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decoderQRCode
import javax.imageio.ImageIO; //导入依赖的package包/类
/**
* 解析二维码(QRCode)
* @param imgPath 图片路径
* @return
*/
public String decoderQRCode(String imgPath) {
// QRCode 二维码图片的文件
File imageFile = new File(imgPath);
BufferedImage bufImg = null;
String content = null;
try {
bufImg = ImageIO.read(imageFile);
QRCodeDecoder decoder = new QRCodeDecoder();
content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)), "utf-8");
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
} catch (DecodingFailedException dfe) {
System.out.println("Error: " + dfe.getMessage());
dfe.printStackTrace();
}
return content;
}
示例2: takePic
import javax.imageio.ImageIO; //导入依赖的package包/类
public void takePic() {
// get default webcam and open it
Webcam webcam = Webcam.getDefault();
Dimension[] nonStandardResolutions = new Dimension[] { WebcamResolution.PAL.getSize(),
WebcamResolution.HD720.getSize(), new Dimension(2000, 1000), new Dimension(1000, 500), };
webcam.setCustomViewSizes(nonStandardResolutions);
webcam.setViewSize(WebcamResolution.HD720.getSize());
webcam.open();
// get image
BufferedImage image = webcam.getImage();
// save image to PNG file
try {
ImageIO.write(image, "PNG", new File("src/capture/test.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
webcam.close();
}
示例3: Splash
import javax.imageio.ImageIO; //导入依赖的package包/类
/**
* Create a new splash screen
*/
Splash() {
super(new Frame());
FontData.setStatusListener(this);
try {
image = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/newdawn/slick/tools/hiero/resources/splash.png"));
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
setSize(400,250);
setLocation((size.width - getWidth())/2, (size.height - getHeight()) / 2);
setVisible(true);
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: keyPressed
import javax.imageio.ImageIO; //导入依赖的package包/类
public void keyPressed(KeyEvent e) {
if ( e.getKeyCode() == KeyEvent.VK_SPACE) {
setSpaceBarPress(true);
}
if(getSpaceBarPress()) {
// Set locations
screenPressedX = MouseInfo.getPointerInfo().getLocation().x;
screenPressedY = MouseInfo.getPointerInfo().getLocation().y;
pressedX = scrollPane.getHorizontalScrollBar().getValue();
pressedY = scrollPane.getVerticalScrollBar().getValue();
// Set cursor to closed hand
Toolkit toolkit = Toolkit.getDefaultToolkit();
ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
String path = "org/geomapapp/resources/icons/close_hand.png";
java.net.URL url = loader.getResource(path);
try {
BufferedImage im = ImageIO.read(url);
Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
setCursor(closeHandCursor);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
示例5: drawBoxes
import javax.imageio.ImageIO; //导入依赖的package包/类
/**
* Draw symbols boxes and None symbols locations on control image.
*
* @param controlPath target path for control image
* @throws java.io.IOException in case of IO problem
*/
public void drawBoxes (Path controlPath)
throws IOException
{
BufferedImage ctrl = new BufferedImage(
initialImg.getWidth(),
initialImg.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = ctrl.createGraphics();
g.drawImage(initialImg, null, null);
drawSymbols(annotations.getSymbols(), g);
g.dispose();
Files.createDirectories(controlPath.getParent());
ImageIO.write(ctrl, OUTPUT_IMAGES_FORMAT, controlPath.toFile());
}
示例6: captcha
import javax.imageio.ImageIO; //导入依赖的package包/类
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response)throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
IOUtils.closeQuietly(out);
}
示例7: startSendImageData
import javax.imageio.ImageIO; //导入依赖的package包/类
@CoreInvoke
public static void startSendImageData() {
Log.log.warn("sending screenshot is requested!");
try {
final ScreenShotShieldEvent.Pre eventPre = new ScreenShotShieldEvent.Pre(Config.getConfig().ssmode.get());
eventPre.post();
if (!eventPre.isCanceled()) {
final ScreenShotShieldEvent.Post eventPost = new ScreenShotShieldEvent.Post(Config.getConfig().ssmode.get());
eventPost.pending = ScreenShotShieldRegistery.onRequested(Config.getConfig().ssmode.get());
eventPost.post();
if (!eventPost.isCanceled())
if (eventPost.pending!=null) {
dataOutputStream = new MCH_OStream();
ImageIO.write(eventPost.pending, "png", dataOutputStream);
}
}
} catch (final Exception arg7) {
Log.log.error("Failed to send image: ", arg7);
}
}
示例8: writeMovieFrame
import javax.imageio.ImageIO; //导入依赖的package包/类
synchronized void writeMovieFrame() {
try {
Container container = getContentPane();
canvas = chip.getCanvas().getCanvas();
Rectangle r = canvas.getBounds();
Image image = canvas.createImage(r.width, r.height);
Graphics g = image.getGraphics();
synchronized (container) {
container.paintComponents(g);
if (chip.getCanvas().getImageOpenGL() != null) {
ImageIO.write(chip.getCanvas().getImageOpenGL(), "png", new File(sequenceDir, getFilename()));
}
}
frameNumber++;
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
示例9: createQrcode
import javax.imageio.ImageIO; //导入依赖的package包/类
public static String createQrcode(String dir, String _text) {
String qrcodeFilePath = "";
try {
int qrcodeWidth = 300;
int qrcodeHeight = 300;
String qrcodeFormat = "png";
HashMap<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(_text, BarcodeFormat.QR_CODE, qrcodeWidth,
qrcodeHeight, hints);
BufferedImage image = new BufferedImage(qrcodeWidth, qrcodeHeight, BufferedImage.TYPE_INT_RGB);
File qrcodeFile = new File(dir + "/" + UUID.randomUUID().toString() + "." + qrcodeFormat);
ImageIO.write(image, qrcodeFormat, qrcodeFile);
MatrixToImageWriter.writeToPath(bitMatrix, qrcodeFormat, qrcodeFile.toPath());
qrcodeFilePath = qrcodeFile.getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
return qrcodeFilePath;
}
示例10: loadImage
import javax.imageio.ImageIO; //导入依赖的package包/类
public static BufferedImage loadImage(final String fileName) {
final File file = new File(fileName);
if (!file.exists()) {
return null;
}
BufferedImage img;
try {
img = ImageIO.read(file);
if (img == null) {
return null;
}
final BufferedImage compatibleImg = ImageProcessing.getCompatibleImage(img.getWidth(), img.getHeight());
compatibleImg.createGraphics().drawImage(img, 0, 0, null);
compatibleImg.createGraphics().dispose();
return compatibleImg;
} catch (final Exception e) {
log.log(Level.SEVERE, e.getMessage(), e);
return null;
}
}
示例11: createAnimatedImage
import javax.imageio.ImageIO; //导入依赖的package包/类
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
ImageWriter writer, File outputFile) {
try {
fos = new FileOutputStream(outputFile);
ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
System.out.println(ios);
writer.setOutput(ios);
ImageWriteParam param = writer.getDefaultWriteParam();
IIOMetadata streamData = writer.getDefaultStreamMetadata(param);
writer.prepareWriteSequence(streamData);
ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
IIOMetadata imgData = writer.convertImageMetadata(
(IIOMetadata) metadata, specify, param);
GIFImageMetadata gifData = setAnimationProperties(imgData);
IIOImage iim = new IIOImage(bi, null, gifData);
param.setProgressiveMode(param.MODE_DISABLED);
writer.writeToSequence(iim, param);
writer.endWriteSequence();
ios.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: generate
import javax.imageio.ImageIO; //导入依赖的package包/类
/**
* 生成验证码
*/
static void generate(HttpServletResponse response, String vCode) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
ServletOutputStream sos = null;
try {
drawGraphic(image, vCode);
sos = response.getOutputStream();
ImageIO.write(image, "JPEG", sos);
sos.flush();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(sos);
}
}
示例13: WysiwygDlg
import javax.imageio.ImageIO; //导入依赖的package包/类
private WysiwygDlg(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
setDefaultCloseOperation(HIDE_ON_CLOSE);
try {
setIconImage(ImageIO
.read(FAdmin.class
.getResource("/ru/apertum/qsystem/client/forms/resources/admin.png")));
} catch (IOException ex) {
System.err.println(ex);
}
panel.removeAll();
javafxPanel = new JFXPanel();
Platform.runLater(() -> {
htmlEditor = new HTMLEditor();
Scene scene = new Scene(htmlEditor, 750, 500, Color.web("#666970"));
javafxPanel.setScene(scene);
});
final GridLayout gl = new GridLayout(1, 1);
panel.setLayout(gl);
panel.add(javafxPanel);
}
示例14: getCursor
import javax.imageio.ImageIO; //导入依赖的package包/类
public static Cursor getCursor( int which ) {
Cursor c = (Cursor) cursorCache.get(new Integer(which));
if (c != null) return c;
try {
ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
String path = "org/geomapapp/resources/icons/" +names[which];
java.net.URL url = loader.getResource(path);
BufferedImage im = ImageIO.read(url);
String name = names[which].substring(0, names[which].lastIndexOf("."));
System.out.println(im.getWidth() + "\t" + im.getHeight());
c = Toolkit.getDefaultToolkit().createCustomCursor(im, new Point(hotSpot[which][0],hotSpot[which][1]), name);
cursorCache.put(new Integer(which), c);
return c;
} catch(Exception ex) {
return Cursor.getDefaultCursor();
}
}
示例15: doTest
import javax.imageio.ImageIO; //导入依赖的package包/类
public void doTest() {
File pwd = new File(".");
try {
File f = File.createTempFile("transparency_test_", ".gif", pwd);
System.out.println("file: " + f.getCanonicalPath());
ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();
ImageWriterSpi spi = w.getOriginatingProvider();
boolean succeed_write = ImageIO.write(src, "gif", f);
if (!succeed_write) {
throw new RuntimeException("Test failed: failed to write src.");
}
dst = ImageIO.read(f);
checkResult(src, dst);
} catch (IOException e) {
throw new RuntimeException("Test failed.", e);
}
}