本文整理汇总了Java中javax.imageio.ImageReader类的典型用法代码示例。如果您正苦于以下问题:Java ImageReader类的具体用法?Java ImageReader怎么用?Java ImageReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageReader类属于javax.imageio包,在下文中一共展示了ImageReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImageExtension
import javax.imageio.ImageReader; //导入依赖的package包/类
public File addImageExtension(File incoming) throws IOException {
String format = null;
ImageInputStream iis = ImageIO.createImageInputStream(incoming);
Iterator<ImageReader> imageReaders = ImageIO.getImageReaders(iis);
while (imageReaders.hasNext()) {
ImageReader reader = (ImageReader) imageReaders.next();
format = reader.getFormatName().toLowerCase();
log.debug("filetype is: " + format);
File newfile = new File("imageimage." + format);
if (newfile.exists()) {
newfile.delete();
}
Files.copy(incoming.toPath(), newfile.toPath());
incoming.delete();
return newfile;
}
return null;
}
示例2: run
import javax.imageio.ImageReader; //导入依赖的package包/类
/**
* Gets the size of an image.
*
* @param name the image name
* @param in the input stream
* @return the size of the image
*
* @throws BrokenImageException if the image is faulty
* @throws UnrecognizedImageTypeException if the image type is unknown
* @throws IOException if reading the image goes wrong
*/
public Dimension run(String name, InputStream in) throws IOException {
final ImageInputStream stream = new MemoryCacheImageInputStream(in);
final Iterator<ImageReader> i = ImageIO.getImageReaders(stream);
if (!i.hasNext()) throw new UnrecognizedImageTypeException(name);
final ImageReader reader = i.next();
try {
reader.setInput(stream);
return new Dimension(reader.getWidth(0), reader.getHeight(0));
}
finally {
reader.dispose();
}
}
示例3: runTest
import javax.imageio.ImageReader; //导入依赖的package包/类
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context)ctx;
final ImageReader reader = ictx.reader;
final boolean seekForwardOnly = ictx.seekForwardOnly;
final boolean ignoreMetadata = ictx.ignoreMetadata;
do {
try {
ImageInputStream iis = ictx.createImageInputStream();
reader.setInput(iis, seekForwardOnly, ignoreMetadata);
reader.read(0);
reader.reset();
iis.close();
ictx.closeOriginalStream();
} catch (IOException e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
示例4: F2IR
import javax.imageio.ImageReader; //导入依赖的package包/类
public static ImageReader F2IR(String input) throws IOException {
final File file = new File(input);
// ��ȡͼƬ��ʽ
final String formatname = GetPostfix.fromFilepath(input);
Iterator<ImageReader> readers;
ImageReader reader;
ImageInputStream iis;
readers = ImageIO.getImageReadersByFormatName(formatname);
reader = readers.next();
iis = ImageIO.createImageInputStream(file);
reader.setInput(iis, false);
return reader;
}
示例5: getJPEGTablesReader
import javax.imageio.ImageReader; //导入依赖的package包/类
/**
* Retrieves a JPEG reader which supports native JPEG stream metadata.
*/
private static ImageReader getJPEGTablesReader() {
ImageReader jpegReader = null;
try {
IIORegistry registry = IIORegistry.getDefaultInstance();
Iterator<?> readerSPIs =
registry.getServiceProviders(ImageReaderSpi.class,
new JPEGSPIFilter(),
true);
if(readerSPIs.hasNext()) {
ImageReaderSpi jpegReaderSPI =
(ImageReaderSpi)readerSPIs.next();
jpegReader = jpegReaderSPI.createReaderInstance();
}
} catch(Exception e) {
// Ignore it ...
}
return jpegReader;
}
示例6: newData
import javax.imageio.ImageReader; //导入依赖的package包/类
@Override
public void newData(byte[] bytes) {
if(Dashboard.visionInitialized()){
Mat m = CvProcessing.byteArray2Mat(bytes);
Dashboard.setForVision(m);
}
if(mode == DisplayMode.Normal){
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
Iterator<?> readers = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader reader = (ImageReader) readers.next();
Object source = bis;
try {
ImageInputStream iis = ImageIO.createImageInputStream(source);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
BufferedImage image = reader.read(0, param);
setImage(image);
} catch (IOException e) {
}
}
}
示例7: testType
import javax.imageio.ImageReader; //导入依赖的package包/类
private static void testType(ImageReader reader,
ImageTypeSpecifier t,
BufferedImage src)
throws IOException
{
ImageReadParam p = reader.getDefaultReadParam();
p.setDestinationType(t);
BufferedImage dst = reader.read(0, p);
verify(src, dst, t);
}
示例8: readTestImage
import javax.imageio.ImageReader; //导入依赖的package包/类
public static BufferedImage readTestImage(String fileName,
BufferedImage dest,
Rectangle srcROI)
{
BufferedImage bi = null;
try {
FileImageInputStream is =
new FileImageInputStream(new File(fileName));
ImageReader reader =
(ImageReader)ImageIO.getImageReaders(is).next();
ImageReadParam param = reader.getDefaultReadParam();
if (dest != null) {
param.setDestination(dest);
}
if (srcROI != null) {
param.setSourceRegion(srcROI);
}
reader.setInput(is);
bi = reader.read(0, param);
} catch (IOException e) {
System.err.println("Error " + e +
" when reading file: " + fileName);
throw new RuntimeException(e);
}
return bi;
}
示例9: TIFF
import javax.imageio.ImageReader; //导入依赖的package包/类
/**
*
* @param imageFile
* @param band form files with multiple band
*/
public TIFF(File imageFile,int band) {
this.imageFile=imageFile;
try {
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("tiff");
boolean worked=false;
while(readers.hasNext()&&!worked){
Object obj=readers.next();
if( obj instanceof TIFFImageReader){
reader = (TIFFImageReader)obj;
iis=ImageIO.createImageInputStream(imageFile);
reader.setInput(iis);
try{
xSize=reader.getWidth(band);
ySize=reader.getHeight(band);
bounds=new Rectangle(0,0,xSize,ySize);
}catch(Exception e){
bounds=null;
logger.warn("Problem reading size information");
}
worked=true;
}else{
}
}
if(!worked){
logger.warn("No reader avalaible for this image");
}
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
}
示例10: DestTypeTest
import javax.imageio.ImageReader; //导入依赖的package包/类
public DestTypeTest() {
w = (ImageWriter)
ImageIO.getImageWritersByFormatName("jpeg").next();
w.addIIOWriteWarningListener(this);
r = (ImageReader)
ImageIO.getImageReadersByFormatName("jpeg").next();
r.addIIOReadWarningListener(this);
}
示例11: testUpdateIcon
import javax.imageio.ImageReader; //导入依赖的package包/类
@Test
public void testUpdateIcon() throws IOException {
final LinkedMultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
multipartData.add("icon", new InputStreamResource(getClass().getResourceAsStream("test-image.png")));
final ResponseEntity<Connector> updated = post("/api/v1/connectors/twitter/icon",
multipartData, Connector.class, tokenRule.validToken(), HttpStatus.OK,
multipartHeaders());
assertThat(updated.getBody().getId()).isPresent();
assertThat(updated.getBody().getIcon()).isNotBlank().startsWith("db:");
final ResponseEntity<ByteArrayResource> got = get("/api/v1/connectors/twitter/icon", ByteArrayResource.class);
assertThat(got.getHeaders().getFirst("Content-Type")).isEqualTo("image/png");
try (ImageInputStream iis = ImageIO.createImageInputStream(got.getBody().getInputStream());) {
final Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
if (readers.hasNext()) {
final ImageReader reader = readers.next();
try {
reader.setInput(iis);
final Dimension dimensions = new Dimension(reader.getWidth(0), reader.getHeight(0));
assertThat(dimensions.getHeight()).isEqualTo(106d).as("Wrong image height");
assertThat(dimensions.getWidth()).isEqualTo(106d).as("Wrong image width");
} finally {
reader.dispose();
}
}
}
}
示例12: IS2IR
import javax.imageio.ImageReader; //导入依赖的package包/类
public static ImageReader IS2IR(ImageInputStream input, String formatname) throws IOException {
Iterator<ImageReader> readers;
ImageReader reader;
readers = ImageIO.getImageReadersByFormatName(formatname);
reader = readers.next();
reader.setInput(input, false);
return reader;
}
示例13: read
import javax.imageio.ImageReader; //导入依赖的package包/类
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
ImageInputStream imageInputStream = null;
ImageReader imageReader = null;
try {
imageInputStream = createImageInputStream(inputMessage.getBody());
MediaType contentType = inputMessage.getHeaders().getContentType();
Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
if (imageReaders.hasNext()) {
imageReader = imageReaders.next();
ImageReadParam irp = imageReader.getDefaultReadParam();
process(irp);
imageReader.setInput(imageInputStream, true);
return imageReader.read(0, irp);
}
else {
throw new HttpMessageNotReadableException(
"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
}
}
finally {
if (imageReader != null) {
imageReader.dispose();
}
if (imageInputStream != null) {
try {
imageInputStream.close();
}
catch (IOException ex) {
// ignore
}
}
}
}
示例14: doTest
import javax.imageio.ImageReader; //导入依赖的package包/类
protected void doTest() throws IOException {
BufferedImage biSrc = getSrc();
ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
writer.setOutput(ios);
ImageWriteParam writeParam = writer.getDefaultWriteParam();
IIOMetadata imageMetadata =
writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);
IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);
IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
writer.write(streamMetadata, iioImg, writeParam);
ios.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
ImageReader reader = ImageIO.getImageReader(writer);
reader.setInput(iis);
BufferedImage dst = reader.read(0);
// do test
int x = dx / 2;
int y = height / 2;
for (int i = 0; i < usedColors.length; i++) {
int dstRgb = dst.getRGB(x, y);
System.out.println("dstColor: " + Integer.toHexString(dstRgb));
int srcRgb = usedColors[i].getRGB();
System.out.println("srcColor: " + Integer.toHexString(srcRgb));
if (dstRgb != srcRgb) {
throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
}
x += dx;
}
}
示例15: init
import javax.imageio.ImageReader; //导入依赖的package包/类
private static void init() {
Iterator i = ImageIO.getImageWritersByFormatName(format);
if (!i.hasNext()) {
throw new RuntimeException("No available ImageWrites for "+format+" format!");
}
iw = (ImageWriter)i.next();
i = ImageIO.getImageReadersByFormatName(format);
if (!i.hasNext()) {
throw new RuntimeException("No available ImageReaders for " +format+" format!");
}
ir = (ImageReader)i.next();
}