本文整理汇总了Java中javax.imageio.ImageReadParam.setDestinationType方法的典型用法代码示例。如果您正苦于以下问题:Java ImageReadParam.setDestinationType方法的具体用法?Java ImageReadParam.setDestinationType怎么用?Java ImageReadParam.setDestinationType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageReadParam
的用法示例。
在下文中一共展示了ImageReadParam.setDestinationType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readImage
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public static BufferedImage readImage(Object source) throws IOException
{
ImageInputStream stream = ImageIO.createImageInputStream(source);
ImageReader reader = ImageIO.getImageReaders(stream).next();
reader.setInput(stream);
ImageReadParam param =reader.getDefaultReadParam();
ImageTypeSpecifier typeToUse = null;
for (Iterator i = reader.getImageTypes(0);i.hasNext(); )
{
ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
if (type.getColorModel().getColorSpace().isCS_sRGB())
typeToUse = type;
}
if (typeToUse!=null) param.setDestinationType(typeToUse);
BufferedImage b = reader.read(0, param);
reader.dispose();
stream.close();
return b;
}
示例2: readImage
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* Workaround for sRGB color space bug on JRE 1.5
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4705399
*
* @param source (inputstream or File)
* @return fixed buffered image
* @throws IOException
*/
public static BufferedImage readImage(Object source) throws IOException {
ImageInputStream stream = ImageIO.createImageInputStream(source);
ImageReader reader = ImageIO.getImageReaders(stream).next();
reader.setInput(stream);
ImageReadParam param =reader.getDefaultReadParam();
ImageTypeSpecifier typeToUse = null;
for (Iterator i = reader.getImageTypes(0);i.hasNext(); ) {
ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
if (type.getColorModel().getColorSpace().isCS_sRGB())
typeToUse = type;
}
if (typeToUse!=null) param.setDestinationType(typeToUse);
BufferedImage b = reader.read(0, param);
reader.dispose();
stream.close();
return b;
}
示例3: tryLoad
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
private Optional<Image> tryLoad(ImageReader reader, byte[] bytes, int type) {
try {
reader.setInput(new ByteArrayInputStream(bytes), true, true);
ImageReadParam params = reader.getDefaultReadParam();
Iterator<ImageTypeSpecifier> imageTypes = reader.getImageTypes(0);
while (imageTypes.hasNext()) {
ImageTypeSpecifier imageTypeSpecifier = imageTypes.next();
int bufferedImageType = imageTypeSpecifier.getBufferedImageType();
if (bufferedImageType == BufferedImage.TYPE_BYTE_GRAY) {
params.setDestinationType(imageTypeSpecifier);
}
}
BufferedImage bufferedImage = reader.read(0, params);
return Optional.of(Image$.MODULE$.wrapAwt(bufferedImage));
} catch (Exception e) {
return Optional.empty();
}
}
示例4: testType
import javax.imageio.ImageReadParam; //导入方法依赖的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);
}
示例5: copyReadParam
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
protected void copyReadParam(ImageReadParam src, ImageReadParam dst) {
dst.setDestination(src.getDestination());
dst.setSourceRegion(src.getSourceRegion());
dst.setSourceSubsampling(src.getSourceXSubsampling(), src
.getSourceYSubsampling(), src.getSubsamplingXOffset(), src
.getSubsamplingYOffset());
dst.setDestinationOffset(src.getDestinationOffset());
if (ImageReaderFactory.getInstance().needsImageTypeSpecifier(tsuid)) {
dst.setDestinationType(createImageTypeSpecifier());
}
}
示例6: readImage
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param source Description of the Parameter
* @return Description of the Return Value
* @throws IOException Description of the Exception
*/
public static BufferedImage readImage(Object source) throws IOException {
ImageInputStream stream = ImageIO.createImageInputStream(source);
if (stream == null) {
if (source instanceof java.net.URL) {
return ImageIO.read((java.net.URL) source);
} else {
return null;
}
}
Iterator<?> it = ImageIO.getImageReaders(stream);
if (!it.hasNext()) {
// bug with firefox 2
BufferedImage buf = null;
if (source instanceof File) {
buf = ImageIO.read((File) source);
}
return buf;
}
ImageReader reader = (ImageReader) it.next();
reader.setInput(stream);
ImageReadParam param = reader.getDefaultReadParam();
ImageTypeSpecifier typeToUse = null;
boolean looking = true;
for (Iterator<?> i = reader.getImageTypes(0); i.hasNext() && looking; ) {
ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
if (type.getColorModel().getColorSpace().getNumComponents() == 1) {
typeToUse = type;
looking = false;
} else if (type.getColorModel().getColorSpace().isCS_sRGB()) {
typeToUse = type;
looking = false;
}
}
if (typeToUse != null) {
param.setDestinationType(typeToUse);
}
BufferedImage b = null;
try {
b = reader.read(0, param);
} catch (Exception e) {
e.printStackTrace();
}
reader.dispose();
stream.close();
return b;
}
示例7: doTest
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
public void doTest() throws IOException {
/*
* This test verifies that png images with color type RGB or RGBA
* are decoded as buffered image of some standard type.
*
* So we need to be sure that image provided by
* user has required color type - RGB or RGBA
*/
if (!checkImageType()) {
System.out.println("Test IGNORED!");
return;
}
def = reader.read(0);
System.out.println("Default image type: " + def.getType());
if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
throw new RuntimeException("Test FAILED!");
}
raw_type = reader.getRawImageType(0);
ImageReadParam param = reader.getDefaultReadParam();
param.setDestinationType(raw_type);
System.out.println("Reading with raw image type...");
raw = reader.read(0, param);
System.out.println("Type of raw image is " + raw.getType());
compare(def, raw);
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
while (types.hasNext()) {
ImageTypeSpecifier t = types.next();
System.out.println("Test type: " + t);
param.setDestinationType(t);
BufferedImage img = reader.read(0, param);
System.out.println("Result type: " + img.getType());
compare(def, img);
System.out.println("Done.\n");
}
System.out.println("Test PASSED.");
}
示例8: read
import javax.imageio.ImageReadParam; //导入方法依赖的package包/类
/**
* Returns a <code>BufferedImage</code> as the result of decoding a supplied <code>ImageInputStream</code>
* with an <code>ImageReader</code> chosen automatically from among those currently registered. If no
* registered <code>ImageReader</code> claims to be able to read the stream, <code>null</code> is
* returned.
*
* <p>
* Unlike most other methods in this class, this method <em>does</em> close the provided
* <code>ImageInputStream</code> after the read operation has completed, unless <code>null</code> is
* returned, in which case this method <em>does not</em> close the stream.
*
* @param stream
* an <code>ImageInputStream</code> to read from.
*
* @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>
* .
*
* @exception IllegalArgumentException
* if <code>stream</code> is <code>null</code>.
* @exception IOException
* if an error occurs during reading.
*/
public static BufferedImage read(ImageInputStream stream) throws IOException {
if (stream == null) {
throw new IllegalArgumentException("stream == null!");
}
BufferedImage bi = null;
Iterator iter = getImageReaders(stream);
IOException lastException = null;
while (iter.hasNext()) {
ImageReader reader = null;
try {
reader = (ImageReader) iter.next();
ImageReadParam param = reader.getDefaultReadParam();
reader.setInput(stream, true, true);
Iterator<ImageTypeSpecifier> imageTypes = reader.getImageTypes(0);
while (imageTypes.hasNext()) {
ImageTypeSpecifier imageTypeSpecifier = imageTypes.next();
int bufferedImageType = imageTypeSpecifier.getBufferedImageType();
if (bufferedImageType == BufferedImage.TYPE_BYTE_GRAY) {
param.setDestinationType(imageTypeSpecifier);
break;
}
}
bi = reader.read(0, param);
if (null != bi)
break;
} catch (IOException e) {
lastException = e;
} finally {
if (null != reader) {
reader.dispose();
stream.close();
}
}
}
// If you don't have an image at the end of all readers
if (null == bi) {
if (null != lastException) {
throw lastException;
}
}
return bi;
}