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


Java ImageIO.write方法代碼示例

本文整理匯總了Java中javax.imageio.ImageIO.write方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageIO.write方法的具體用法?Java ImageIO.write怎麽用?Java ImageIO.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.imageio.ImageIO的用法示例。


在下文中一共展示了ImageIO.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public void write(OutputStream sos) throws IOException {
	ImageIO.write(buffImg, "png", sos);
	sos.close();
}
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:5,代碼來源:CaptchaUtil.java

示例2: writeFontData

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public void writeFontData(String textureFilename, String descriptionFilename) throws IOException
{
	ImageIO.write(image, "png", new File(textureFilename));
	
	StringBuilder buffer = new StringBuilder();
	
	buffer.append("<?xml version='1.0' encoding='utf-8'?>\n\n");
	buffer.append("<!--  Keep in mind that pixmaps have their origin in the upper left corner! -->\n\n");

	buffer.append("<Font>\n");
	
	for(Character c: texHashMap.keySet())
	{
		CharacterPixmap pixmap = texHashMap.get(c);

		pixmap.toXML("  ", buffer);
	}
	buffer.append("</Font>");
	FileOutputStream fileOut = new FileOutputStream(descriptionFilename, false);
	OutputStreamWriter out = new OutputStreamWriter(fileOut, "UTF-8");
	System.out.println("Writing description file with encoding "+out.getEncoding());
	out.write(buffer.toString());
	out.close();
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:25,代碼來源:Font.java

示例3: exportToImage

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public static void exportToImage(String format, JPanel dPanel, String fileName) {
  BufferedImage bImg = new BufferedImage(dPanel.getWidth(), dPanel.getHeight(), BufferedImage.TYPE_INT_RGB);
  Graphics2D cg = bImg.createGraphics();
  dPanel.paintAll(cg);
  try {
          if (ImageIO.write(bImg, "jpg", new File("./" + fileName + "." + format)))
          {
              System.out.println("image saved succesfully");
          }
  } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
  }
}
 
開發者ID:tslaats,項目名稱:SE2017-Team1,代碼行數:15,代碼來源:TestUtil.java

示例4: writePNG

import javax.imageio.ImageIO; //導入方法依賴的package包/類
/**
 * Writes the image as a PNG file with the given horizontal and vertical
 * dots-per-inch.
 */
public static void writePNG(BufferedImage image, String filename, double dpiX, double dpiY) throws IOException {
	try {
		ImageIO.write(image, "PNG", new File(filename)); // some versions of
															// Java
															// sometimes
															// throws an
															// exception
															// during
															// saving...
		setDPI(filename, dpiX, dpiY);
	} catch (Throwable ex) {
		if (ex instanceof IOException)
			throw (IOException) ex;
		if (ex instanceof StackOverflowError)
			throw new IOException("Out of memory trying to save the PNG file to " + filename);
		if (ex instanceof OutOfMemoryError)
			throw new IOException("Out of memory trying to save the PNG file to " + filename);
		throw new IOException("Error writing the PNG file to " + filename + " (" + ex + ")");
	}
}
 
開發者ID:AlloyTools,項目名稱:org.alloytools.alloy,代碼行數:25,代碼來源:OurPNGWriter.java

示例5: saveAs

import javax.imageio.ImageIO; //導入方法依賴的package包/類
/**
	 * Saves a file by opening a JFileChooser which allows the user to select
	 * the file they would like to save over or create a new file to save onto.
	 *
	 * @return true if the file successfully opened, false otherwise.
	 */

	public boolean saveAs()
	{
 	JFileChooser chooser = new JFileChooser(".");
    int returnVal = chooser.showSaveDialog(null);
    if(returnVal == JFileChooser.APPROVE_OPTION) {
		try{
		ImageIO.write(image, "png",chooser.getSelectedFile());
		}
		catch(Exception e){
			return false;
		}
		return true;
    }
    return false;

}
 
開發者ID:DerekBabb,項目名稱:CyberSecurity,代碼行數:24,代碼來源:PictureEdit.java

示例6: capture

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public void capture() {
    synchronized (memImage) {
        imageUpdate(memImage, -1, 0, 0, rfb.framebufferWidth, rfb.framebufferHeight);
        BufferedImage image = new BufferedImage(rfb.framebufferWidth, rfb.framebufferHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        g2.drawImage(memImage, 0, 0, rfb.framebufferWidth, rfb.framebufferHeight, null);
        g2.dispose();

        try {
            Calendar c = Calendar.getInstance();
            ImageIO.write(image, "jpg", new File(manageScreenPath(ScreenCaptureSetting.getPath()) +
                    manageScreenName(viewer.compname) + "_" + 
                    c.get(Calendar.YEAR) + "-" + 
                    addZeroOnDateTime(c.get(Calendar.MONTH) + 1) + "-" + 
                    addZeroOnDateTime(c.get(Calendar.DATE)) + "_" + 
                    addZeroOnDateTime(c.get(Calendar.HOUR_OF_DAY)) + "-" + 
                    addZeroOnDateTime(c.get(Calendar.MINUTE)) + "-" + 
                    addZeroOnDateTime(c.get(Calendar.SECOND)) + 
                    ".jpg"));
            
            System.out.println("Captured screen: "+ viewer.compname);
        } catch (IOException ex) {
        }
    }
}
 
開發者ID:the-im,項目名稱:enhanced-vnc-thumbnail-viewer,代碼行數:26,代碼來源:VncCanvas.java

示例7: main

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String path = System.getProperty("test.classes") + File.separator + "test.png";

    BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = image.createGraphics();
    graphics2D.setColor(Color.red);
    graphics2D.fillOval(0, 0, IMAGE_SIZE, IMAGE_SIZE);
    graphics2D.dispose();;

    try(FileOutputStream fos = new FileOutputStream(path)) {
        ImageIO.write(image, "png", fos);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:GenerateTestImage.java

示例8: checkBI

import javax.imageio.ImageIO; //導入方法依賴的package包/類
private void checkBI(BufferedImage bi) {
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            if (bi.getRGB(x, y) == Color.blue.getRGB()) {
                try {
                    String fileName = "TransformedPaintTest_res.png";
                    ImageIO.write(bi, "png", new File(fileName));
                    System.err.println("Dumped image to: " + fileName);
                } catch (IOException ex) {}
                throw new RuntimeException("Test failed, blue color found");
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TransformedPaintTest.java

示例9: doGet

import javax.imageio.ImageIO; //導入方法依賴的package包/類
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	int width = 155;
	int height = 50;
	BufferedImage buf = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
	HttpSession session=request.getSession();
	Graphics2D g = buf.createGraphics();    // creating Graphics2D
	GradientPaint gp = new GradientPaint(0,0,Color.orange, 0, height/2, Color.GREEN, true); // mixing of 2 colors
	
	g.setPaint(gp);
	Font f = new Font("Times New Roman", Font.BOLD, 22);
	g.setFont(f);
	g.fillRect(0, 0, width, height);
	g.setColor(new Color(0,153,255));
	
	String data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	String captcha = "";
	String captcha1="";
	char ch[] = data.toCharArray();
	for (int i=0; i<6; i++)
	{
		int j = (int)((Math.random()) * 62);
		captcha = captcha +" "+ch[j];
		captcha1 = captcha1+ch[j];
	}
	session.setAttribute("captcha", captcha1); 	// captcha  is name & captcha1 is value 
	g.drawString(captcha, 10, 35);
	g.dispose();
	response.setContentType("image/png");
	OutputStream os = response.getOutputStream();
	ImageIO.write(buf , "png",os);
	
}
 
開發者ID:nishittated,項目名稱:OnlineElectionVotingSystem,代碼行數:33,代碼來源:CaptchaServlet.java

示例10: build

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public boolean build(){
    String imageType = getFileType(originImage.getName());
    try {
        ImageIO.write(dealedImage,imageType,originImage);
        return true;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:11,代碼來源:ImageUtils.java

示例11: generateImage

import javax.imageio.ImageIO; //導入方法依賴的package包/類
static void generateImage(String name, Color color, float scale) throws Exception {
    File file = new File(name);
    if (file.exists()) {
        return;
    }
    BufferedImage image = new BufferedImage((int) (scale * IMAGE_WIDTH),
            (int) (scale * IMAGE_HEIGHT), BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    g.setColor(color);
    g.fillRect(0, 0, (int) (scale * IMAGE_WIDTH), (int) (scale * IMAGE_HEIGHT));
    ImageIO.write(image, "png", file);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:MultiResolutionSplashTest.java

示例12: encode

import javax.imageio.ImageIO; //導入方法依賴的package包/類
/**
 * Encodes an image in PNG format and writes it to an OutputStream.
 *
 * @param bufferedImage  The image to be encoded.
 * @param outputStream  The OutputStream to write the encoded image to.
 * @throws IOException
 */
public void encode(BufferedImage bufferedImage, OutputStream outputStream) 
    throws IOException {
    if (bufferedImage == null) {
        throw new IllegalArgumentException("Null 'image' argument.");
    }
    if (outputStream == null) {
        throw new IllegalArgumentException("Null 'outputStream' argument.");
    }
    ImageIO.write(bufferedImage, ImageFormat.PNG, outputStream);
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:18,代碼來源:SunPNGEncoderAdapter.java

示例13: encoderQRCode

import javax.imageio.ImageIO; //導入方法依賴的package包/類
/**
 * 生成二維碼(QRCode)圖片
 * @param content 存儲內容
 * @param output 輸出流
 * @param imgType 圖片類型
 * @param size 二維碼尺寸
 */
public void encoderQRCode(String content, OutputStream output, String imgType, int size) {
	try {
		BufferedImage bufImg = this.qRCodeCommon(content, imgType, size);
		// 生成二維碼QRCode圖片
		ImageIO.write(bufImg, imgType, output);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:17,代碼來源:TwoDimensionCode.java

示例14: run

import javax.imageio.ImageIO; //導入方法依賴的package包/類
@Override
public void run() {
    final JMenuBar menubar = new JMenuBar();
    menubar.add(new JMenu(""));
    menubar.add(new JMenu(""));
    final JFrame frame = new JFrame();
    frame.setUndecorated(true);
    frame.setJMenuBar(menubar);
    frame.setSize(W / 3, H / 3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    // draw menu bar using standard order.
    final BufferedImage bi1 = step1(menubar);

    // draw menu border on top of the menu bar, nothing should be changed.
    final BufferedImage bi2 = step2(menubar);
    frame.dispose();

    for (int x = 0; x < W; ++x) {
        for (int y = 0; y < H; ++y) {
            if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) {
                try {
                    ImageIO.write(bi1, "png", new File("image1.png"));
                    ImageIO.write(bi2, "png", new File("image2.png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                throw new RuntimeException("Failed: wrong color");
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:34,代碼來源:MisplacedBorder.java

示例15: createTestFile

import javax.imageio.ImageIO; //導入方法依賴的package包/類
private static void createTestFile() {
    int w = 1280;
    int h = 1024;

    BufferedImage img = new
        BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
        new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    try {
        System.out.println("Create test image " + file.getAbsolutePath());
        boolean b = ImageIO.write(img, "JPEG", file);
        if (!b) {
            throw new RuntimeException("Failed to create test image.");
        }
    } catch (IOException e) {
        throw new RuntimeException("Test failed", e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:ConcurrentReadingTest.java


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