當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageIO類代碼示例

本文整理匯總了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;
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:24,代碼來源:TwoDimensionCode.java

示例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();
}
 
開發者ID:badarshahzad,項目名稱:SudoTimer,代碼行數:23,代碼來源:MainViewController.java

示例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();
	}
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:19,代碼來源:Splash.java

示例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();
		}
	}
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:27,代碼來源:XMap.java

示例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());
}
 
開發者ID:Audiveris,項目名稱:omr-dataset-tools,代碼行數:23,代碼來源:SheetProcessor.java

示例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);
}
 
開發者ID:zhaoqicheng,項目名稱:renren-fast,代碼行數:17,代碼來源:SysLoginController.java

示例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);
	}

}
 
開發者ID:Team-Fruit,項目名稱:McHeliPrivacyShield,代碼行數:22,代碼來源:MCH_MultiplayClient.java

示例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();
    }
}
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:19,代碼來源:MotionViewer.java

示例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;
}
 
開發者ID:guokezheng,項目名稱:automat,代碼行數:22,代碼來源:QrcodeUtil.java

示例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;
  }
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:24,代碼來源:ImageSerializer.java

示例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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:OpaquePNGToGIFTest.java

示例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);
	}
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:23,代碼來源:CaptchaUtils.java

示例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);
}
 
開發者ID:bcgov,項目名稱:sbc-qsystem,代碼行數:24,代碼來源:WysiwygDlg.java

示例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();
	}
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:20,代碼來源:Cursors.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:GifTransparencyTest.java


注:本文中的javax.imageio.ImageIO類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。