本文整理汇总了Java中javax.imageio.ImageIO.read方法的典型用法代码示例。如果您正苦于以下问题:Java ImageIO.read方法的具体用法?Java ImageIO.read怎么用?Java ImageIO.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageIO
的用法示例。
在下文中一共展示了ImageIO.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertStringToBufferedImage
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private BufferedImage convertStringToBufferedImage(String image) {
if (image != null) {
final byte[] imageInByte = Base64.decodeBase64(image.getBytes());
final InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = null;
try {
bImageFromConvert = ImageIO.read(in);
return bImageFromConvert;
} catch (IOException e) {
JOptionPane.showMessageDialog(modalFrame, "Image conversation error!\nPlease reopen this window.",
JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "Image cannot be null!",
JOptionPane.MESSAGE_PROPERTY, JOptionPane.WARNING_MESSAGE);
}
return null;
}
示例2: createThumbnail
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Async
public String createThumbnail(UserFile userFile) {
String path = userFile.getPath();
Path originalImagePath = Paths.get(properties.getUploadFileRootPath(), path);
try {
BufferedImage originalImage = ImageIO.read(originalImagePath.toFile());
if (originalImage != null) {
BufferedImage thumbnailImage = this.createThumbnailImage(originalImage, 300, 200);
String ext = path.substring(path.lastIndexOf(".") + 1);
Path thumbNailPath = Paths.get(properties.getUploadFileRootPath(), userFile.getThumbnailPath());
ImageIO.write(thumbnailImage, ext, Files.newOutputStream(thumbNailPath));
return thumbNailPath.toString();
}
} catch (IOException e) {
logger.error("Failed to create thumbnail of '{}'", path);
}
return "";
}
示例3: visitArmy
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Override
public void visitArmy(Army army) {
BufferedImage texture = null;
if (!army.hasBattleGroup()){
return;
}
try {
texture = ImageIO.read(new File("src/application/images/units/BlueArmy.png"));
} catch (IOException e) {
try {
texture = ImageIO.read(new File("../src/application/images/units/BlueArmy.png"));
} catch (IOException e2) {
e2.printStackTrace();
} }
texture = resizeImage(texture);
addToPriorityQueue(ARMY, texture);
}
示例4: iconFromFileName
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private NbImageIcon iconFromFileName(String fileName) {
File file = new File(fileName);
if (file.exists()) {
try {
try {
Image image = ImageIO.read(file);
if (image != null) {
return new NbImageIcon(TYPE_FILE, fileName, new ImageIcon(image));
}
} catch (IllegalArgumentException iaex) { // Issue 178906
Logger.getLogger(IconEditor.class.getName()).log(Level.INFO, null, iaex);
return new NbImageIcon(TYPE_FILE, fileName, new ImageIcon(fileName));
}
} catch (IOException ex) {
Logger.getLogger(IconEditor.class.getName()).log(Level.INFO, null, ex);
}
}
return null;
}
示例5: TextureCompassFX
import javax.imageio.ImageIO; //导入方法依赖的package包/类
public TextureCompassFX(Minecraft minecraft)
{
super(Item.compass.getIconFromDamage(0));
isCustom = true;
mc = minecraft;
res = (Integer)mc.renderEngine.textureSizeIdMap.get(mc.renderEngine.getTexture("/gui/items.png"))/16;
compassIconImageData = new int[res*res];
imageData = new byte[res*res*4];
tileImage = 1;
try
{
BufferedImage bufferedimage = ImageIO.read(mc.texturePackList.selectedTexturePack.getResourceAsStream("/gui/items.png"));
int i = (iconIndex % 16) * res;
int j = (iconIndex / 16) * res;
bufferedimage.getRGB(i, j, res, res, compassIconImageData, 0, res);
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}
示例6: scaleImageByWidth
import javax.imageio.ImageIO; //导入方法依赖的package包/类
/**
* 灏嗗浘鐗囦互width涓哄噯杩涜绛夋瘮缂╂斁
*
* @param imageBytes
* @param width
* @param imageFormatName
* @return
*/
public static byte[] scaleImageByWidth(byte[] imageBytes, int width,
String imageFormatName) {
Image img = null;
int height = 0;
try {
img = ImageIO.read(new ByteArrayInputStream(imageBytes));
int old_w = img.getWidth(null);
int old_h = img.getHeight(null);
if (old_h > 0 && old_w > 0) {
// 浠ュ搴︿负鍑嗭紝璁$畻楂樺害 绛夋瘮缂╂斁
height = (int) ((float) width / old_w * old_h);
}
} catch (Exception e) {
logger.error("scaleImageByWidth faild!", e);
}
return ImageUtils.scaleImage(imageBytes, width, height,
Image.SCALE_SMOOTH, imageFormatName);
}
示例7: showImage
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private void showImage(Patient patient){
if (patient.getThumbnail() == null) {
imageView.setImage(new Image(getClass().getResource("/image/avater.jpg").toExternalForm()));
} else {
File file = new File(path + "\\Documents\\DrAssistant\\" + patient.getThumbnail());
try {
BufferedImage bufferedImage = ImageIO.read(file);
Image image = SwingFXUtils.toFXImage(bufferedImage, null);
imageView.setImage(image);
} catch (IOException ex) {
Logger.getLogger(PatientCard.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
示例8: readImage
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@NotNull
private static BufferedImage readImage(int imageSize, InputStream inputStream) throws IOException {
byte[] imageAr = new byte[imageSize];
for (int i = 0; i < imageSize; i++) {
imageAr[i] = (byte) inputStream.read();
}
return ImageIO.read(new ByteArrayInputStream(imageAr));
}
示例9: downSampleImageUtil_should_downSample_image_width_greater_than_1000_pixels
import javax.imageio.ImageIO; //导入方法依赖的package包/类
@Test
void downSampleImageUtil_should_downSample_image_width_greater_than_1000_pixels()
throws IOException, StockException{
BufferedImage originalImage = ImageIO
.read(new File("src/test/resources/OriginalImageWidth.jpg"));
byte[] downSampledImage = DownSampleUtil.downSampleImageUtil(
imageToByteArray(originalImage));
ByteArrayInputStream bais = new ByteArrayInputStream(downSampledImage);
BufferedImage downSampledImg = ImageIO.read(bais);
ImageIO.write(downSampledImg, "jpg", new File("src/test/resources/DownSampledImageWidth.jpg"));
Assert.assertEquals(1000, downSampledImg.getWidth());
Assert.assertEquals(954, downSampledImg.getHeight());
}
示例10: applyServerIconToResponse
import javax.imageio.ImageIO; //导入方法依赖的package包/类
public void applyServerIconToResponse(ServerStatusResponse response)
{
File file1 = this.getFile("server-icon.png");
if (!file1.exists())
{
file1 = this.getActiveAnvilConverter().getFile(this.getFolderName(), "icon.png");
}
if (file1.isFile())
{
ByteBuf bytebuf = Unpooled.buffer();
try
{
BufferedImage bufferedimage = ImageIO.read(file1);
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
ByteBuf bytebuf1 = Base64.encode(bytebuf);
response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
}
catch (Exception exception)
{
LOG.error((String)"Couldn\'t load server icon", (Throwable)exception);
}
finally
{
bytebuf.release();
}
}
}
示例11: getImageFromUrl
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private BufferedImage getImageFromUrl(String link) {
BufferedImage image = null;
try {
URL url = new URL(link);
image = ImageIO.read(url);
} catch (Exception e) {
e.printStackTrace();
}
return image;
}
示例12: thumbnail
import javax.imageio.ImageIO; //导入方法依赖的package包/类
static byte[] thumbnail(Path path, int height) {
try {
final BufferedImage image = ImageIO.read(path.toFile());
final BufferedImage thumb = resize(image, height * image.getWidth() / image.getHeight(), height);
return png(thumb);
} catch(IOException e) {
throw Throwables.propagate(e);
}
}
示例13: loadFile
import javax.imageio.ImageIO; //导入方法依赖的package包/类
public void loadFile(File file) {
try {
image = ImageIO.read(file);
} catch (Exception ex) {
ex.printStackTrace();
image = null;
}
}
示例14: verifyFileRead
import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static void verifyFileRead() throws IOException {
File inputTestFile = createTestFile("inputTestFile");
try {
ImageIO.read(inputTestFile);
} catch (IOException ex) {
if (verifyInputExceptionMessage(ex))
throw ex;
} finally {
inputTestFile.delete();
}
}
示例15: drawImage
import javax.imageio.ImageIO; //导入方法依赖的package包/类
/**
* 将logo添加到二维码中间
* @author:chenming
* @date:2014年12月31日
*
* @param logoPath logo路径
* @param image 需要绘制的二维码图片
* @param logoConfig 配置参数
* @throws java.io.IOException
*/
private static void drawImage(String logoPath,BufferedImage image,MatrixToLogoImageConfig logoConfig) throws IOException{
if(logoConfig == null){
logoConfig = DEFAULT_CONFIG;
}
try {
BufferedImage logo = ImageIO.read(new File(logoPath));
logo.setRGB(0, 0, BufferedImage.TYPE_INT_BGR);
Graphics2D g = image.createGraphics();
//考虑到logo照片贴到二维码中,建议大小不要超过二维码的1/5;
int width = image.getWidth() / logoConfig.getLogoPart();
int height = image.getHeight() / logoConfig.getLogoPart();
//logo起始位置,此目的是为logo居中显示
int x = (image.getWidth() - width) / 2;
int y = (image.getHeight() - height) / 2;
//绘制图
g.drawImage(logo, x, y, width, height, null);
//给logo画边框
//构造一个具有指定线条宽度以及 cap 和 join 风格的默认值的实心 BasicStroke
// g.setStroke(new BasicStroke(logoConfig.getBorder()));
// g.setColor(logoConfig.getBorderColor());
// g.drawRect(x, y, width, height);
g.dispose();
} catch (Exception e) { //捕捉异常后不做任何处理,防止图片路径错误而导致二维码生成失败
}
}