本文整理汇总了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();
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例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;
}