如何为新生成的图像提供分辨率? [英] How to give resolution to a new generated image?

查看:21
本文介绍了如何为新生成的图像提供分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以写入图像,但其默认分辨率为 600x450.我想指定我自己的分辨率.

I can write the image but its default resolution is 600x450. I want to specify my own resolution.

public void save(String path, String name) throws IOException 
{
            int x ;
            int y;
            x=scaled.getHeight();
            y=scaled.getWidth();

            System.out.println(x);
            System.out.println(y);

            if (scaled != null) 
            {  
                name += scaled.getWidth() + "x" + scaled.getHeight();
                ImageIO.write(scaled, "png", new File(path + File.separator + name + ".png"));
            } 
            else 
            {
                throw new NullPointerException("Scaled instance is null");
            }
}

有什么建议吗?

推荐答案

我认为 scaled 是一个字段图像.另外,我假设您没有收到 NullPointerException.

I presume scaled is a field image. Also, I will assume you're not getting a NullPointerException.

您可以使用 scaled.getImageData().getScaled(int x, int y) 返回带有您自己的 xy<的新缩放图像/b>.

You can use scaled.getImageData().getScaled(int x, int y) to return a new scaled image with your own x and y.

像这样:

ImageData newData = scaled.getImageData().scaledTo(int x, int y);
Image newScaledImage = new Image(Display.getCurrent(), newData);
ImageIO.write(newScaledImage , "png", new File(path + File.separator + name + ".png"));
newScaledImage.dispose();

这篇关于如何为新生成的图像提供分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆