本文整理汇总了Java中com.sun.image.codec.jpeg.JPEGImageEncoder.getDefaultJPEGEncodeParam方法的典型用法代码示例。如果您正苦于以下问题:Java JPEGImageEncoder.getDefaultJPEGEncodeParam方法的具体用法?Java JPEGImageEncoder.getDefaultJPEGEncodeParam怎么用?Java JPEGImageEncoder.getDefaultJPEGEncodeParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.image.codec.jpeg.JPEGImageEncoder
的用法示例。
在下文中一共展示了JPEGImageEncoder.getDefaultJPEGEncodeParam方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: snapImageFile
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
void snapImageFile(String filename, int width, int height) {
BufferedImage bImage = doRender(width, height);
/*
* JAI: RenderedImage fImage = JAI.create("format", bImage,
* DataBuffer.TYPE_BYTE); JAI.create("filestore", fImage, filename +
* ".tif", "tiff", null);
*/
/* No JAI: */
try {
FileOutputStream fos = new FileOutputStream(filename + ".jpg");
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder jie = JPEGCodec.createJPEGEncoder(bos);
JPEGEncodeParam param = jie.getDefaultJPEGEncodeParam(bImage);
param.setQuality(1.0f, true);
jie.setJPEGEncodeParam(param);
jie.encode(bImage);
bos.flush();
fos.close();
} catch (Exception e) {
System.out.println(e);
}
}
示例2: saveToPicture
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
/**
* ��һ��JPanel����Ϊ��fileָ����ͼƬ��
* @param file
* @param panel
*/
@SuppressWarnings("restriction")
public static void saveToPicture(File file, JComponent panel){
BufferedImage image = new BufferedImage(Page.PAGE_WIDTH, Page.PAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
panel.paint(g);
image.flush();
try {
FileOutputStream fos = new FileOutputStream(file);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
param.setQuality(1.0f, true);
encoder.encode(image, param);
javax.imageio.ImageIO.write(image, "jpeg", fos);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: writeImage
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
/**
* @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, org.apache.flex.forks.batik.ext.awt.image.spi.ImageWriterParams)
*/
public void writeImage(RenderedImage image, OutputStream out,
ImageWriterParams params) throws IOException {
BufferedImage bi;
if (image instanceof BufferedImage) {
bi = (BufferedImage)image;
} else {
//TODO Is this the right way?
bi = GraphicsUtil.makeLinearBufferedImage(
image.getWidth(), image.getHeight(), false);
}
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
if (params != null) {
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
if (params.getJPEGQuality() != null) {
param.setQuality(
params.getJPEGQuality().floatValue(),
params.getJPEGForceBaseline().booleanValue());
}
encoder.encode(bi, param);
} else {
encoder.encode(bi);
}
}
示例4: encode
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
/**
* Encodes an image in JPEG 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.");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bufferedImage);
param.setQuality(this.quality, true);
encoder.encode(bufferedImage, param);
}
示例5: createMark
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
public static boolean createMark(String filePath, String printPath,
String markContent) {
ImageIcon imgIcon = new ImageIcon(filePath);
Image theImg = imgIcon.getImage();
int width = theImg.getWidth(null);
int height = theImg.getHeight(null);
BufferedImage bimage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimage.createGraphics();
g.setColor(Color.red);
g.drawImage(theImg, 0, 0, null);
Font font = new Font(markContent, Font.BOLD, 200);
g.setFont(font);
g.setComposite(AlphaComposite
.getInstance(AlphaComposite.SRC_OVER, 0.5f));// 10%��
g.rotate(0.3f); // ���ֵ���ת�Ƕ�
g.drawString(markContent, width / 3, height / 3);// ����ˮӡ��λ��
g.dispose();
try {
FileOutputStream out = new FileOutputStream(printPath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
param.setQuality(100f, true);
encoder.encode(bimage, param);
out.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
示例6: writeJPEGFile
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
/** Writes the current view in a <code>Canvas3D</code> object to an JPG file */
public static void writeJPEGFile(String fName, Canvas3D canvas){
GraphicsContext3D ctx = canvas.getGraphicsContext3D();
// The raster components need all be set!
Raster ras = new Raster(
new Point3f(-1.0f,-1.0f,-1.0f),
Raster.RASTER_COLOR,
0,0,
canvas.getWidth(),canvas.getHeight(),
new ImageComponent2D( ImageComponent.FORMAT_RGB, new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_RGB)),
null);
ctx.readRaster(ras);
// Now strip out the image info
BufferedImage img = ras.getImage().getImage();
// write that to disk....
try {
FileOutputStream out = new FileOutputStream(fName);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(img);
param.setQuality(0.95f,false); // 75% quality for the JPEG
encoder.setJPEGEncodeParam(param);
encoder.encode(img);
out.close();
} catch ( IOException e ) {
e.printStackTrace();
}
}
示例7: writeJPG
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
/**
* 输出为JPG文件
*
* @param o 图像
* @param output 输出文件
* @throws IOException
*/
public static void writeJPG(BufferedImage o,File output) throws IOException{
FileOutputStream out = new FileOutputStream(output);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(o);
param.setQuality(1f,false);
encoder.setJPEGEncodeParam(param);
encoder.encode(o);
out.close();
}
示例8: createThumbnail
import com.sun.image.codec.jpeg.JPEGImageEncoder; //导入方法依赖的package包/类
private void createThumbnail(String pathImage, String pathThumbnail){
final int PREVIEW_WIDTH = 125;
final int PREVIEW_HEIGHT = 125;
File srcImage = new File(pathImage);
ImageIcon imageIcon = null;
if (srcImage != null) {
// Test if need to be loaded with JAI libraries (different
// format than JPG, PNG and GIF)
if (TFileUtils.isJAIRequired(srcImage)) {
// Load it with JAI class
RenderedOp src_aux = JAI.create("fileload", srcImage.getAbsolutePath());
BufferedImage bufferedImage = src_aux.getAsBufferedImage();
imageIcon = new ImageIcon(bufferedImage);
} else {
// Create it as usual
imageIcon = new ImageIcon(srcImage.getAbsolutePath());
}
}
File thum = new File (pathThumbnail);
if (!thum.exists()){
try{
int thumbWidth = PREVIEW_WIDTH;
int thumbHeight = PREVIEW_HEIGHT;
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = imageIcon.getIconWidth();
int imageHeight = imageIcon.getIconHeight();
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio) {
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
}
BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(imageIcon.getImage(), 0, 0, thumbWidth, thumbHeight, null);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pathThumbnail));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
int quality = 100;
quality = Math.max(0, Math.min(quality, 100));
param.setQuality((float)quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
} catch (Exception ex) {
System.out.println("Error creating THUMBNAIL");
System.out.println(ex.toString());
}
}
}