本文整理汇总了Java中org.monte.media.jpeg.CMYKJPEGImageReader类的典型用法代码示例。如果您正苦于以下问题:Java CMYKJPEGImageReader类的具体用法?Java CMYKJPEGImageReader怎么用?Java CMYKJPEGImageReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CMYKJPEGImageReader类属于org.monte.media.jpeg包,在下文中一共展示了CMYKJPEGImageReader类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import org.monte.media.jpeg.CMYKJPEGImageReader; //导入依赖的package包/类
@Override
public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
readHeader();
ImageInputStream in = (ImageInputStream) getInput();
SubImageInputStream sin = new SubImageInputStream(in, imageOffsets[imageIndex], imageLengths[imageIndex]);
sin.seek(0);
ImageReader ir = new CMYKJPEGImageReader(getOriginatingProvider());
ir.setInput(sin);
BufferedImage img = ir.read(0);
ir.dispose();
return img;
}
示例2: read
import org.monte.media.jpeg.CMYKJPEGImageReader; //导入依赖的package包/类
public static BufferedImage read(InputStream input) throws IOException {
BufferedImage in;
byte[] data = Helper.readStream(input);
try (ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(data))) {
CMYKJPEGImageReader r = new CMYKJPEGImageReader(new CMYKJPEGImageReaderSpi());
r.setInput(iis);
in = r.read(0);
} catch (IOException | ArrayIndexOutOfBoundsException ex) {
try {
in = ImageIO.read(ImageIO.createImageInputStream(new ByteArrayInputStream(data)));
} catch (IOException ex1) {
return null;
}
}
int type = in.getType();
if (type != BufferedImage.TYPE_INT_ARGB_PRE && type != BufferedImage.TYPE_INT_RGB) {
// convert to ARGB
int width = in.getWidth();
int height = in.getHeight();
int[] imgData = in.getRGB(0, 0, width, height, null, 0, width);
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
newImage.getRaster().setDataElements(0, 0, width, height, imgData);
return newImage;
}
return in;
}
示例3: setFile
import org.monte.media.jpeg.CMYKJPEGImageReader; //导入依赖的package包/类
/**
* This method asynchronously loads an image file.
*/
public void setFile(final File file) {
imageLabel.setIcon(null);
imageLabel.setText("Loading image...");
new SwingWorker<BufferedImage, BufferedImage>() {
@Override
protected BufferedImage doInBackground() throws Exception {
// Loads a JPEG image using the Java ImageIO API
// ---------------------------------------------
// The ImageIO API may provide many ImageReaders which
// claim to be able to read the file. We try them all
// out until we succeed.
BufferedImage img = null;
ImageInputStream iis = new FileImageInputStream(file);
try {
CMYKJPEGImageReader r = new CMYKJPEGImageReader(new CMYKJPEGImageReaderSpi());
r.setInput(iis);
img = r.read(0);
} finally {
iis.close();
}
return img;
}
@Override
protected void done() {
// Show the image or apologize in case of failure
// -----------------------------------------------
try {
BufferedImage image = get();
if (image == null) {
imageLabel.setText("Sorry. Couldn't load image.");
infoLabel.setText(null);
} else {
imageLabel.setIcon(new ImageIcon(image));
imageLabel.setText(null);
infoLabel.setText("<html>Image Dimension: "+image.getWidth()+" x "+image.getHeight()
+"<br>Color Model: "+image.getColorModel()
+"<br>has alpha: "+image.getColorModel().hasAlpha()+" is alpha premultiplied:"+image.getColorModel().isAlphaPremultiplied()
);
}
} catch (Exception ex) {
imageLabel.setText("Sorry. Couldn't load image.");
ex.printStackTrace();
}
super.done();
}
}.execute();
}