本文整理汇总了Java中com.sun.media.jai.codec.ImageEncoder类的典型用法代码示例。如果您正苦于以下问题:Java ImageEncoder类的具体用法?Java ImageEncoder怎么用?Java ImageEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageEncoder类属于com.sun.media.jai.codec包,在下文中一共展示了ImageEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createSingleTiff
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
public void createSingleTiff(File singleTifFile) {
// jai approach
try {
OutputStream out = new FileOutputStream(singleTifFile);
// ByteArrayOutputStream out = new ByteArrayOutputStream();
TIFFEncodeParam param = new TIFFEncodeParam();
Vector<RenderedImage> vector = new Vector<RenderedImage>();
logger.debug("NbrOfImages {}", imageList.size());
for (int i = 1; i < imageList.size(); i++) {
vector.add(imageList.get(i));
}
param.setExtraImages(vector.iterator());
ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", out,
param);
encoder.encode(imageList.get(0));
// tempByteArray = out.toByteArray();
out.close();
logger.info("Single page tiff created");
} catch (Exception e) {
logger.error("Error creating single page tiff", e);
}
}
开发者ID:xenit-eu,项目名称:move2alf,代码行数:26,代码来源:Tiff2Pdf.java
示例2: saveImage
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
/**
* Saves a BufferedImage stream in PNG format.
*
* @param image the buffered image to save to disk
* @param filePath the file to save the image file in
* @throws IOException
*/
public static void saveImage(BufferedImage image, String filePath) throws IOException {
BufferedOutputStream out = null;
ImageEncoder encoder;
try {
out = new BufferedOutputStream(new FileOutputStream(filePath));
encoder = ImageCodec.createImageEncoder("PNG", out, null);
encoder.encode(image);
} catch (IOException e) {
throw e;
} finally {
if (out != null) {
out.close();
}
}
}
开发者ID:appliedtopology,项目名称:javaplex,代码行数:23,代码来源:FileIOUtility.java
示例3: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
try {
final PNGEncodeParam param = PNGEncodeParam.getDefaultEncodeParam(image);
return com.sun.media.jai.codec.ImageCodec.createImageEncoder("PNG", out, param); //$NON-NLS-1$
} catch (final RuntimeException exception) {
throw exception;
}
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:10,代码来源:PngEncoder.java
示例4: convertToPNG
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
/**
* Save buffered image to PNG, with optional scaling/DPI setting
*
* @param pOut
* @throws IOException
*/
public void convertToPNG(OutputStream pOut)
throws IOException {
//Set up DPI settings
int lDotsPerMetre = (int)(mDPI / 0.0254);
PNGEncodeParam params = PNGEncodeParam.getDefaultEncodeParam(this);
params.setPhysicalDimension(lDotsPerMetre, lDotsPerMetre, 1);
//Encode to PNG
ImageEncoder encoder = ImageCodec.createImageEncoder("PNG", pOut, params);
encoder.encode(this);
pOut.close();
}
开发者ID:Fivium,项目名称:FOXopen,代码行数:20,代码来源:XBufferedImage.java
示例5: doInBackground
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
protected Object doInBackground(ProgressMonitor pm) throws Exception {
try {
final String message = String.format("Saving image as %s...", file.getPath());
pm.beginTask(message, view.isRGB() ? 4 : 3);
snapApp.setStatusBarMessage(message);
snapApp.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
final Dimension dimension = new Dimension(view.getProduct().getSceneRasterWidth(),
view.getProduct().getSceneRasterHeight());
RenderedImage image = ExportImageAction.createImage(view, true, dimension, true, true);
pm.worked(1);
try (ZipOutputStream outStream = new ZipOutputStream(new FileOutputStream(file))) {
outStream.putNextEntry(new ZipEntry(OVERLAY_KML));
final String kmlContent = formatKML(view, OVERLAY_PNG);
outStream.write(kmlContent.getBytes());
pm.worked(1);
outStream.putNextEntry(new ZipEntry(OVERLAY_PNG));
ImageEncoder encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null);
encoder.encode(image);
pm.worked(1);
if (!view.isRGB()) {
outStream.putNextEntry(new ZipEntry(LEGEND_PNG));
encoder = ImageCodec.createImageEncoder(IMAGE_TYPE, outStream, null);
encoder.encode(createImageLegend(view.getRaster()));
pm.worked(1);
}
}
} catch (OutOfMemoryError ignored) {
Dialogs.showOutOfMemoryError("The image could not be exported."); /*I18N*/
} catch (Throwable e) {
snapApp.handleError("The image could not be exported", e);
} finally {
snapApp.getMainFrame().setCursor(Cursor.getDefaultCursor());
snapApp.setStatusBarMessage("");
pm.done();
}
return null;
}
开发者ID:senbox-org,项目名称:snap-desktop,代码行数:41,代码来源:ExportKmzFileAction.java
示例6: writeToFile
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
public void writeToFile(BufferedImage object, String path) throws IOException {
BufferedOutputStream out = null;
ImageEncoder encoder;
try {
out = new BufferedOutputStream(new FileOutputStream(path));
encoder = ImageCodec.createImageEncoder(encoderFormat, out, null);
encoder.encode(object);
} catch (IOException e) {
throw e;
} finally {
if (out != null) {
out.close();
}
}
}
开发者ID:appliedtopology,项目名称:javaplex,代码行数:16,代码来源:BufferedImageWriter.java
示例7: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
final TIFFEncodeParam param = new TIFFEncodeParam();
return com.sun.media.jai.codec.ImageCodec.createImageEncoder("TIFF", out, param); //$NON-NLS-1$
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:6,代码来源:TiffEncoder.java
示例8: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
return com.sun.media.jai.codec.ImageCodec.createImageEncoder("GIF", out, null); //$NON-NLS-1$
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:5,代码来源:GifEncoder.java
示例9: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
protected ImageEncoder getEncoder(final RenderedImage image, final OutputStream out) {
final BMPEncodeParam param = new BMPEncodeParam();
return com.sun.media.jai.codec.ImageCodec.createImageEncoder("BMP", out, param); //$NON-NLS-1$
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:6,代码来源:BmpEncoder.java
示例10: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的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$
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:7,代码来源:JpegEncoder.java
示例11: encode
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
@Override
public void encode(final BufferedImage image, final OutputStream out) throws IOException {
final ImageEncoder encoder = getEncoder(image, out);
encoder.encode(image);
}
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:6,代码来源:AbstractEncoder.java
示例12: getSelectedTiffFile
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
/**
* The <code>getSelectedTiffFile</code> method is used to limit the file
* to the page limit given.
*
* @param tiffFile {@link File} tiff file from which limit has to be applied
* @param pageLimit int
* @throws IOException if file is not found
*/
public static void getSelectedTiffFile(final File tiffFile, final int pageLimit) throws IOException {
OutputStream out = null;
File newTiffFile = null;
if (null != tiffFile && getTIFFPageCount(tiffFile.getAbsolutePath()) > pageLimit) {
try {
final List<BufferedImage> imageList = new ArrayList<BufferedImage>();
final SeekableStream seekableStream = new FileSeekableStream(tiffFile);
final ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", seekableStream, null);
for (int i = 1; i < pageLimit; i++) {
final PlanarImage planarImage = new NullOpImage(decoder.decodeAsRenderedImage(i), null, null, OpImage.OP_IO_BOUND);
imageList.add(planarImage.getAsBufferedImage());
}
seekableStream.close();
final TIFFEncodeParam params = new TIFFEncodeParam();
params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
String name = tiffFile.getName();
final int indexOf = name.lastIndexOf(IUtilCommonConstants.DOT);
name = name.substring(0, indexOf);
final String finalPath = tiffFile.getParent() + File.separator + name
+ System.currentTimeMillis() + IUtilCommonConstants.EXTENSION_TIF;
newTiffFile = new File(finalPath);
out = new FileOutputStream(finalPath);
final ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", out, params);
params.setExtraImages(imageList.iterator());
encoder.encode(imageList.get(0));
} finally {
if (null != out) {
out.flush();
out.close();
}
}
if (tiffFile.delete() && null != newTiffFile) {
newTiffFile.renameTo(tiffFile);
} else {
if (null != newTiffFile) {
newTiffFile.delete();
}
}
}
}
开发者ID:kuzavas,项目名称:ephesoft,代码行数:49,代码来源:TIFFUtil.java
示例13: convertPdfToImage
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的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();
}
}
}
开发者ID:joaquinaimar,项目名称:wizard,代码行数:46,代码来源:ImageCodeUtil.java
示例14: drawJAIImage
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
private void drawJAIImage(String sCodec, InputStream imgSrc, OutputStream outStr, int iThumbWidth, int iThumbHeight, float fQuality)
throws IOException, InterruptedException, NullPointerException, IllegalArgumentException {
RenderedImage oRenderedImg;
PlanarImage oPlI;
RenderedOp oScI;
ParameterBlock oBlk;
ImageEncoder oImgEnc;
ImageDecoder oDecoder;
Log.out.debug("Begin Picture.drawJAIImage("+sCodec+","+String.valueOf(iThumbWidth)+","+String.valueOf(iThumbHeight)+")");
oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(sCodec, imgSrc, null);
oRenderedImg = oDecoder.decodeAsRenderedImage();
if (sCodec.equals("gif")) {
// Increase color depth to 16M RGB
try {
javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();
ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
new int[] {8,8,8}, false, false,
Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
layout.setColorModel(cm);
layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
ParameterBlockJAI pb = new ParameterBlockJAI( "format" );
pb.addSource( oRenderedImg );
oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
} catch (IllegalArgumentException iae) {
}
// End increase color depth
} // gif
oPlI = PlanarImage.wrapRenderedImage(oRenderedImg);
int iImageWidth = oPlI.getWidth();
int iImageHeight = oPlI.getHeight();
float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);
float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);
if (thumbRatio < imageRatio)
iThumbHeight = (int)(iThumbWidth / imageRatio);
else
iThumbWidth = (int)(iThumbHeight * imageRatio);
float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);
float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);
oBlk = new ParameterBlock();
oBlk.addSource(oPlI);
oBlk.add(scaleW);
oBlk.add(scaleH);
oBlk.add(0.0f);
oBlk.add(0.0f);
oBlk.add(new javax.media.jai.InterpolationBilinear());
oScI = JAI.create("scale", oBlk, null); // scale image NOW !
oImgEnc = ImageCodec.createImageEncoder( "jpeg", outStr, null );
if (null==oImgEnc) {
throw new NullPointerException("Cannot create ImageEncoder for jpeg");
}
else {
oImgEnc.encode( oScI ); // write encoded data to given output stream
oImgEnc =null;
}
Log.out.debug("End Picture.drawJAIImage()");
}
开发者ID:sergiomt,项目名称:zesped,代码行数:79,代码来源:Picture.java
示例15: getEncoder
import com.sun.media.jai.codec.ImageEncoder; //导入依赖的package包/类
protected abstract ImageEncoder getEncoder(RenderedImage image, OutputStream out);
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:2,代码来源:AbstractEncoder.java
注:本文中的com.sun.media.jai.codec.ImageEncoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论