本文整理汇总了Java中com.sun.media.jai.codec.JPEGEncodeParam类的典型用法代码示例。如果您正苦于以下问题:Java JPEGEncodeParam类的具体用法?Java JPEGEncodeParam怎么用?Java JPEGEncodeParam使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JPEGEncodeParam类属于com.sun.media.jai.codec包,在下文中一共展示了JPEGEncodeParam类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveToDisk
import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public void saveToDisk(TiledImage ti, String fn) throws IOException {
BufferedImage buffImg = new BufferedImage(ti.getWidth(), ti.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g2d = buffImg.getGraphics();
g2d.drawImage(ti.getAsBufferedImage(), 0, 0, null);
buffImg.flush();
JPEGEncodeParam jpgParam = new JPEGEncodeParam();
jpgParam.setQuality(0.85f);
JAI.create("filestore", buffImg, fn, "JPEG", jpgParam);
}
示例2: getEncoder
import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
final JPEGEncodeParam param = new JPEGEncodeParam();
param.setQuality(1f);
return com.sun.media.jai.codec.ImageCodec.createImageEncoder("JPEG", out, param); //$NON-NLS-1$
}
示例3: saveCurrentView
import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
/**
* stores the current viewport as an image file. Executes a fileChooser for choosing the file and
* displays a JOptionPane if successful.
*/
public void saveCurrentView() {
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.jpg", "jpg");
fc.setFileFilter(filter);
String snapShotFileName = recognitionFrame.getPicName();
snapShotFileName = snapShotFileName.replaceAll(RawUtilsCommon.getExtension(snapShotFileName, false), "snapshot.jpg");
fc.setSelectedFile(new File(snapShotFileName));
int returnVal = fc.showSaveDialog(this);
String fn = null;
if (returnVal == JFileChooser.APPROVE_OPTION) {
fn = fc.getSelectedFile().getAbsolutePath();
if (!fn.toLowerCase().endsWith(".jpg")) fn += ".jpg";
}
fc = null;
this.repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if (fn != null) {
BufferedImage bi;
Robot robot;
try {
Rectangle r = recognitionFrame.getBounds();
r.x += recognitionFrame.getLocationOnScreen().x;
r.y += recognitionFrame.getLocationOnScreen().y;
robot = new Robot();
bi = robot.createScreenCapture(r);
JPEGEncodeParam jpgParam = new JPEGEncodeParam();
jpgParam.setQuality(0.85f);
JAI.create("filestore", bi, fn, "JPEG", jpgParam);
System.gc(); // forces JAI to close the filehandle
logger.debug("finished writing");
JOptionPane.showMessageDialog(this, "Screenshot successfully saved to " + fn, "Screenshot saved", JOptionPane.INFORMATION_MESSAGE);
} catch (AWTException e) {
logger.error("error saving screenshot", e);
}
}
}
示例4: makeImageSnapshot
import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public void makeImageSnapshot() {
if (((long) bimg.getWidth() * bimg.getHeight()) > (8000L * 8000L)) {
JOptionPane.showMessageDialog(this, "In the current version this feature can only be used for images where width*height <= 8000*8000.\nHowever, you can use the Orbit Agent to download the file.", "Image too large", JOptionPane.ERROR_MESSAGE);
return;
}
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("*.tif", "tif");
fc.setFileFilter(filter);
String snapShotFileName = getPicName();
snapShotFileName = snapShotFileName.replaceAll(RawUtilsCommon.getExtension(snapShotFileName, false), "tif");
fc.setSelectedFile(new File(snapShotFileName));
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
logger.debug("begin making image snapshot");
String fn = fc.getSelectedFile().getAbsolutePath();
if (!fn.toLowerCase().endsWith(".tif")) fn += ".tif";
Dimension2D oldVPSize = viewPortSize;
Point2D oldVPOffs = getViewPortOffset();
double sc = getScale();
setScale(100d);
setViewPortOffset(new Point(0, 0));
viewPortSize = new Dimension(bimg.getWidth(), bimg.getHeight());
/*
ColorModel colorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[]{8,8,8}, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
SampleModel sampleModel = colorModel.createCompatibleSampleModel(256, 256);
DiskMemImage tiledImage = new DiskMemImage(0, 0, bimg.getWidth(), bimg.getHeight(), 0, 0, sampleModel, colorModel);
Graphics2D g2d = (Graphics2D)tiledImage.createGraphics();
((DiskMemImageGraphics)g2d).overwriteRenderingHint((((Graphics2D)getGraphics()).getRenderingHints()));
*/
// Update 1.7.2010: Fallback to normal bufferedImage (only up to 30kx30k pixel!)
// due to rendering problems with class image (only first tile problem)
BufferedImage buffImg = new BufferedImage(bimg.getWidth(), bimg.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = buffImg.createGraphics();
buffImg.flush();
paint(g2d);
setScale(sc);
setViewPortOffset(oldVPOffs);
viewPortSize = oldVPSize;
logger.info("finished painting");
TIFFEncodeParam param = new TIFFEncodeParam();
param.setTileSize(128, 128);
param.setWriteTiled(true);
param.setCompression(TIFFEncodeParam.COMPRESSION_JPEG_TTN2);
JPEGEncodeParam jpgParam = new JPEGEncodeParam();
jpgParam.setQuality(0.85f);
param.setJPEGEncodeParam(jpgParam);
// TODO: extraImages (Iterator where .next() returns further (low-res) RenderedImages
//param.setExtraImages(extraImages)
JAI.create("filestore", /*tiledImage*/buffImg, fn, "TIFF", param);
logger.info("finished writing");
JOptionPane.showMessageDialog(null, "Image successfully saved to " + fn, "Image saved", JOptionPane.INFORMATION_MESSAGE);
//tiledImage = null;
//DiskMemImage.getCommonTileCache().flush();
Runtime.getRuntime().gc();
Runtime.getRuntime().gc();
Runtime.getRuntime().gc();
logger.debug("cleaning up finished");
}
}
示例5: convertPdfToImage
import com.sun.media.jai.codec.JPEGEncodeParam; //导入依赖的package包/类
public static void convertPdfToImage(File file, String createPath, int type)
throws Exception {
@SuppressWarnings("resource")
FileChannel channel = new RandomAccessFile(file, "r").getChannel();
MappedByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0,
channel.size());
PDFFile pdffile = new PDFFile(buf);
for (int i = 1; i <= pdffile.getNumPages(); i++) {
PDFPage page = pdffile.getPage(i);
Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()
.getWidth(), (int) page.getBBox().getHeight());
Image img = page.getImage(rect.width, rect.height, rect, null,
true, true);
BufferedImage tag = new BufferedImage(rect.width, rect.height,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,
null);
String fileName = createPath
+ "\\"
+ file.getName().substring(0,
file.getName().lastIndexOf('.'));
FileOutputStream out = null;
ImageEncoder enc = null;
switch (type) {
case ImageType.TYPE_JPEG:
out = new FileOutputStream(fileName + i + ".jpg");
enc = ImageCodec.createImageEncoder("jpeg", out,
new JPEGEncodeParam());
break;
case ImageType.TYPE_TIFF:
out = new FileOutputStream(fileName + i + ".tif");
enc = ImageCodec.createImageEncoder("tiff", out,
new TIFFEncodeParam());
break;
}
if (null != out && null != enc) {
enc.encode(tag);
out.close();
}
}
}