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


Java JPEGImageWriteParam類代碼示例

本文整理匯總了Java中javax.imageio.plugins.jpeg.JPEGImageWriteParam的典型用法代碼示例。如果您正苦於以下問題:Java JPEGImageWriteParam類的具體用法?Java JPEGImageWriteParam怎麽用?Java JPEGImageWriteParam使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: writeJPG

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
public static void writeJPG( BufferedImage rendered, float quality, File f ) {

		try {
			JPEGImageWriteParam jpegParams = new JPEGImageWriteParam( null );
			jpegParams.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
			jpegParams.setCompressionQuality( 1f );

			ImageWriter writer = ImageIO.getImageWritersByFormatName( "jpeg" ).next();
			ImageWriteParam param = writer.getDefaultWriteParam();
			param.setCompressionMode( ImageWriteParam.MODE_EXPLICIT ); // Needed see javadoc
			param.setCompressionQuality( quality ); // Highest quality
			writer.setOutput( new FileImageOutputStream( f ) );
			writer.write( null, new IIOImage( rendered, null, null ), jpegParams );
		} catch ( Throwable th ) {
			th.printStackTrace();
		}
	}
 
開發者ID:twak,項目名稱:chordatlas,代碼行數:18,代碼來源:Imagez.java

示例2: store

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
/**
 * Save a JPEG image to file
 *
 * @param img the image to be saved
 * @param fileName file name to use
 * @throws IOException
 */
private void store(BufferedImage img, String fileName) throws IOException {
    File file = File.createTempFile(fileName, JPEG_EXTENSION);
    fileName += JPEG_EXTENSION;
    file.deleteOnExit();

    ImageWriter writer = null;
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(JPEG);
    if (iter.hasNext()) {
        writer = iter.next();
    }

    ImageOutputStream ios = ImageIO.createImageOutputStream(file);
    writer.setOutput(ios);
    ImageWriteParam param = new JPEGImageWriteParam(java.util.Locale.getDefault());
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionQuality(0.98f);
    writer.write(null, new IIOImage(img, null, null), param);

    // Save the image to S3 and DynamoDB
    awsHelper.saveImageToAWS(fileName, file, sessionId, index);
}
 
開發者ID:shirubio,項目名稱:game-of-life,代碼行數:29,代碼來源:BoardImageGenerator.java

示例3: downloadImage

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
public static void downloadImage(String imgURL, InputStream postInStr) 
		throws IOException {
	BufferedImage image = ImageIO.read(postInStr);

	String[] URLparts = imgURL.split("/");
	File outputFile = new File(saveFolderName + "/" + URLparts[URLparts.length - 1]);

	JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
	jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
	jpegParams.setCompressionQuality(1f);

	final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
	writer.setOutput(new FileImageOutputStream(outputFile));
	writer.write(null, new IIOImage(image, null, null), jpegParams);

	System.out.println("Got " + outputFile + " from " + imgURL);
}
 
開發者ID:nevesnunes,項目名稱:mid,代碼行數:18,代碼來源:Requester.java

示例4: getDefaultWriteParam

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
/** {@inheritDoc} */
@Override
protected ImageWriteParam getDefaultWriteParam(
        ImageWriter iiowriter, RenderedImage image,
        ImageWriterParams params) {
    JPEGImageWriteParam param = new JPEGImageWriteParam(iiowriter.getLocale());
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionQuality(params.getJPEGQuality());
    if (params.getCompressionMethod() != null
            && !"JPEG".equals(params.getCompressionMethod())) {
        throw new IllegalArgumentException(
                "No compression method other than JPEG is supported for JPEG output!");
    }
    if (params.getJPEGForceBaseline()) {
        param.setProgressiveMode(JPEGImageWriteParam.MODE_DISABLED);
    }
    return param;
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:19,代碼來源:ImageIOJPEGImageWriter.java

示例5: writeJpegImage

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
private static void writeJpegImage(ImageHolder image, OutputStream os) throws OpenStegoException {
    try {
        JPEGImageWriteParam jpegParams = new JPEGImageWriteParam(null);
        jpegParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        Float qual = UserPreferences.getFloat("image.writer.jpeg.quality");
        if (qual == null) {
            qual = 0.75f;
        }
        jpegParams.setCompressionQuality(qual);

        ImageWriter writer = ImageIO.getImageWritersByFormatName("jpg").next();
        writer.setOutput(ImageIO.createImageOutputStream(os));
        writer.write(null, new IIOImage(image.getImage(), null, image.getMetadata()), jpegParams);
    } catch (IOException e) {
        throw new OpenStegoException(e);
    }
}
 
開發者ID:syvaidya,項目名稱:openstego,代碼行數:18,代碼來源:ImageUtil.java

示例6: getImageWriteParam

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
private static ImageWriteParam getImageWriteParam(BufferedImage im, ImageWriter writer, float quality, String srcFormat, String trgFormat) {
	ImageWriteParam iwp;
	if("jpg".equalsIgnoreCase(srcFormat)) {
   		ColorModel cm = im.getColorModel();
   		if(cm.hasAlpha())im=jpgImage(im);
   		JPEGImageWriteParam jiwp = new JPEGImageWriteParam(Locale.getDefault());
   		jiwp.setOptimizeHuffmanTables(true);
   		iwp = jiwp;
   	}
	else
		iwp = writer.getDefaultWriteParam();
   	
   	setCompressionModeEL(iwp,ImageWriteParam.MODE_EXPLICIT);
   	setCompressionQualityEL(iwp,quality);
   	
   	return iwp;
}
 
開發者ID:lucee,項目名稱:Lucee,代碼行數:18,代碼來源:Image.java

示例7: getDefaultWriteParam

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
/**
 * @see ImageIOImageWriter#getDefaultWriteParam(javax.imageio.ImageWriter, java.awt.image.RenderedImage, ImageWriterParams)
 */
protected ImageWriteParam getDefaultWriteParam(
        ImageWriter iiowriter, RenderedImage image,
        ImageWriterParams params) {
    JPEGImageWriteParam param = new JPEGImageWriteParam(iiowriter.getLocale());
    //ImageTypeSpecifier type = ImageTypeSpecifier.createFromRenderedImage(image);
    /*
    ImageTypeSpecifier type = new ImageTypeSpecifier(
            image.getColorModel(), image.getSampleModel());
            */
    /* didn't work as expected...
    ImageTypeSpecifier type = ImageTypeSpecifier.createFromBufferedImageType(
            BufferedImage.TYPE_INT_RGB);
    param.setDestinationType(type);
    param.setSourceBands(new int[] {0, 1, 2});
    */
    return param;
}
 
開發者ID:BowlerHatLLC,項目名稱:feathers-sdk,代碼行數:21,代碼來源:ImageIOJPEGImageWriter.java

示例8: writeHighQualityJpeg

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
public static void writeHighQualityJpeg( BufferedImage img, File f ) throws IOException
{
    // Find a jpeg writer
    ImageWriter writer = null;
    Iterator iter = ImageIO.getImageWritersByFormatName( "jpg" );
    if ( iter.hasNext() )
    {
        writer = ( ImageWriter ) iter.next();
    }
    // Prepare output file
    ImageOutputStream ios = ImageIO.createImageOutputStream( f );
    writer.setOutput( ios );

    ImageWriteParam iwparam = new JPEGImageWriteParam( Locale.getDefault() );
    iwparam.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
    // according to compression quality is between 0 and 1 (lowest to
    // highest quality)
    iwparam.setCompressionQuality( 1 );

    writer.write( null, new IIOImage( img, null, null ), iwparam );

    // Cleanup
    ios.flush();
    writer.dispose();
    ios.close();
}
 
開發者ID:Comcast,項目名稱:cats,代碼行數:27,代碼來源:ImageFunctions.java

示例9: convertPdf

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
public static byte[] convertPdf(byte[] pdf) {
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(pdf);
        BufferedImage bi = process(bais);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageWriter converter = ImageIO.getImageWritersByMIMEType("image/jpeg").next();

        IIOImage image = new IIOImage(bi, null, null);
        ImageOutputStream output = ImageIO.createImageOutputStream(baos);
        converter.setOutput(output);

        ImageWriteParam jpegParams = converter.getDefaultWriteParam();
        jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT);
        jpegParams.setCompressionQuality(0.3f);

        converter.write(null, image, jpegParams);
        converter.dispose();

        return baos.toByteArray();
    } catch (Exception ex) {
        throw new RuntimeException("Exception in converting pdf", ex);
    }
}
 
開發者ID:faramir,項目名稱:ZawodyWeb,代碼行數:25,代碼來源:PdfToImage.java

示例10: saveToFile

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
private static void saveToFile(BufferedImage img, File file) throws IOException {
    ImageWriter writer = null;
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg");
    if (!iter.hasNext())
        return;
    writer = (ImageWriter) iter.next();

    ImageOutputStream ios = ImageIO.createImageOutputStream(file);
    if (ios == null) throw new IOException("cannot create stream for image to " + file);
    try {
        writer.setOutput(ios);
        ImageWriteParam param = new JPEGImageWriteParam(Locale.getDefault());
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(JPEG_QUALITY);
        writer.write(null, new IIOImage(img, null, null), param);
    } finally {
        writer.dispose();
        ios.close();
    }
}
 
開發者ID:Orange-OpenSource,項目名稱:matos-tool,代碼行數:21,代碼來源:StatisticTool.java

示例11: exportAsJPG

import javax.imageio.plugins.jpeg.JPEGImageWriteParam; //導入依賴的package包/類
/**
 * Exports the drawing as a JPG picture.
 * @param file The targeted location.
 * @return true if the picture was well created.
 */
protected boolean exportAsJPG(final File file) {
	final RenderedImage rendImage = createRenderedImage();

	try {
		final ImageWriteParam iwparam 	= new JPEGImageWriteParam(Locale.getDefault());
		final ImageWriter iw 			= ImageIO.getImageWritersByFormatName("jpg").next();//$NON-NLS-1$
		try(final ImageOutputStream ios = ImageIO.createImageOutputStream(file);){
			iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
			iwparam.setCompressionQuality(dialogueBox.getCompressionRate()/100f);
			iw.setOutput(ios);
			iw.write(null, new IIOImage(rendImage, null, null), iwparam);
			iw.dispose();
			return true;
		}
    }
	catch(IOException e) { BadaboomCollector.INSTANCE.add(e); }
	return false;
}
 
開發者ID:arnobl,項目名稱:latexdraw-mutants,代碼行數:24,代碼來源:Export.java


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