本文整理匯總了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;
}