当前位置: 首页>>代码示例>>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;未经允许,请勿转载。