本文整理汇总了Java中com.sun.imageio.plugins.jpeg.JPEGImageReader类的典型用法代码示例。如果您正苦于以下问题:Java JPEGImageReader类的具体用法?Java JPEGImageReader怎么用?Java JPEGImageReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JPEGImageReader类属于com.sun.imageio.plugins.jpeg包,在下文中一共展示了JPEGImageReader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readHeader
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
/** Reads the image header.
* Does nothing if the header has already been loaded.
*/
private void readHeader() throws IOException {
if (image == null) {
ImageReader r = new JPEGImageReader(getOriginatingProvider());
Object in = getInput();
if (in instanceof Buffer) {
Buffer buffer = (Buffer) in;
in=buffer.getData();
}
if (in instanceof byte[]) {
r.setInput(new MemoryCacheImageInputStream(AVIBMPDIB.prependDHTSeg((byte[]) in)));
} else if (in instanceof ImageInputStream) {
r.setInput(AVIBMPDIB.prependDHTSeg((ImageInputStream) in));
} else {
r.setInput(AVIBMPDIB.prependDHTSeg((InputStream) in));
}
image = r.read(0);
}
}
示例2: createNativeJPEGReader
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
private static ImageReader createNativeJPEGReader() {
return new JPEGImageReader(new CMYKJPEGImageReaderSpi());
/*
for (Iterator<ImageReader> i =
ImageIO.getImageReadersByFormatName("jpeg"); i.hasNext();) {
ImageReader r = i.next();
if (!(r instanceof CMYKJPEGImageReader)
&& !r.getClass().getName().contains("CMYKJPEGImageReader")) {
return r;
}
}
return null;
*
*/
}
示例3: readHeader
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
/** Reads the image header.
* Does nothing if the header has already been loaded.
*/
private void readHeader() throws IOException {
if (image == null) {
ImageReader r = new JPEGImageReader(getOriginatingProvider());
Object in = getInput();
/*if (in instanceof Buffer) {
Buffer buffer = (Buffer) in;
in=buffer.getData();
}*/
if (in instanceof byte[]) {
r.setInput(new MemoryCacheImageInputStream(AVIBMPDIB.prependDHTSeg((byte[]) in)));
} else if (in instanceof ImageInputStream) {
r.setInput(AVIBMPDIB.prependDHTSeg((ImageInputStream) in));
} else {
r.setInput(AVIBMPDIB.prependDHTSeg((InputStream) in));
}
image = r.read(0);
}
}
示例4: getFormatName
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
/**
* 获取图片文件格式
*
* @param imageFile
* 图片文件
*
* @return 图片文件格式
*/
public static String getFormatName(File imageFile) {
if (imageFile == null || imageFile.length() == 0) {
return null;
}
try {
String formatName = null;
ImageInputStream imageInputStream = ImageIO.createImageInputStream(imageFile);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(imageInputStream);
if (!iterator.hasNext()) {
return null;
}
ImageReader imageReader = iterator.next();
if (imageReader instanceof JPEGImageReader) {
formatName = JPEG_FORMAT_NAME;
} else if (imageReader instanceof GIFImageReader) {
formatName = GIF_FORMAT_NAME;
} else if (imageReader instanceof BMPImageReader) {
formatName = BMP_FORMAT_NAME;
} else if (imageReader instanceof PNGImageReader) {
formatName = PNG_FORMAT_NAME;
}
imageInputStream.close();
return formatName;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
示例5: main
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
ImageReader gifReader = new GIFImageReader(null);
ImageReader jpegReader = new JPEGImageReader(null);
ImageReader pngReader = new PNGImageReader(null);
test(gifReader, "GIF");
test(jpegReader, "JPEG");
test(pngReader, "PNG");
}
示例6: decode
import com.sun.imageio.plugins.jpeg.JPEGImageReader; //导入依赖的package包/类
public static DecodeResult decode(byte[] i_src) throws IOException
{
JPEGImageReader jr=(JPEGImageReader)ImageIO.getImageReadersBySuffix("jpeg").next();
jr.setInput(new MemoryCacheImageInputStream(new ByteArrayInputStream(i_src)));
IIOMetadata data = jr.getImageMetadata(0);
Element tree = (Element)data.getAsTree("javax_imageio_jpeg_image_1.0");
Element jfif = (Element)tree.getElementsByTagName("app0JFIF").item(0);
int xd=Integer.parseInt(jfif.getAttribute("Xdensity"));
int yd=Integer.parseInt(jfif.getAttribute("Ydensity"));
int unit=Integer.parseInt(jfif.getAttribute("resUnits"));
BufferedImage b=jr.read(0);
jr.dispose();//dispose
//カラーモデルの分析
SampleModel sp=b.getSampleModel();
if(sp instanceof PixelInterleavedSampleModel){
PixelInterleavedSampleModel ssp=(PixelInterleavedSampleModel)sp;
int data_type=ssp.getDataType();
int scan_stride=ssp.getScanlineStride();
if(data_type==DataBuffer.TYPE_BYTE && scan_stride==b.getWidth()){
DataBufferByte bb=(DataBufferByte)b.getData().getDataBuffer();
return new DecodeResult(xd,yd,bb.getData(),b.getWidth(),b.getHeight(),unit);
}else{
//nothing todo
}
}else{
//nothing todo
}
throw new NyARRuntimeException();
}