Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Scalr调整图像大小,输出图像不正确,灰色_Java_Image_Resize_Imgscalr - Fatal编程技术网

Java 使用Scalr调整图像大小,输出图像不正确,灰色

Java 使用Scalr调整图像大小,输出图像不正确,灰色,java,image,resize,imgscalr,Java,Image,Resize,Imgscalr,可能重复: 我希望我能在录制之前调整图像的大小!我试了好几次,但都没有成功。你能告诉我程序吗。我想使用imgscarlr或更好的。多谢各位 private static void getImages(String src,String Name) throws IOException { String folder = null; //Exctract the name of the image from the src attribute int indexnam

可能重复:

我希望我能在录制之前调整图像的大小!我试了好几次,但都没有成功。你能告诉我程序吗。我想使用imgscarlr或更好的。多谢各位

private static void getImages(String src,String Name) throws IOException {

    String folder = null;

    //Exctract the name of the image from the src attribute
    int indexname = src.lastIndexOf("/");


    if (indexname == src.length()) {
        src = src.substring(1, indexname);
    }

    indexname = src.lastIndexOf("/");
    String name = src.substring(indexname, src.length());

    System.out.println(name);

    //Open a URL Stream
    URL url = new URL(src);
    InputStream in = url.openStream();

    OutputStream out = new BufferedOutputStream(new FileOutputStream( folderPath+ name));

    for (int b; (b = in.read()) != -1;) {

        out.write(b);
    }


  BufferedImage originalImage = ImageIO.read(new File(folderPath+name));
    BufferedImage scaledImage = Scalr.resize(originalImage, 200);
    ImageIO.write(scaledImage, "jpg", new File(folderPath+name));
    }
    }
我没问题,但是根据图片,我对灰色部分的采样有问题

您需要先“加载”图像,查看API以了解更多详细信息,然后,根据您的需要,缩放图像相对简单

更新


我忘记了
out.close()现在开始工作了

您能否只发布处理图像的代码?所有文件处理都不重要。BTW-DYM(只有一个“r”)?错误-->线程“main”java.lang.ExceptionInInitializerError在DownloadImages.getImages(DownloadImages.java:145)在DownloadImages.main(DownloadImages.java:83)中出现异常原因:java.lang.IllegalArgumentException:无法加载标准配置文件:java.awt.color.ICC_profile$2.run(ICC_profile.java:931)java.security.AccessController.doPrivileged(本机方法)java.awt.color.ICC_profile.getStandardProfile(ICC_profile.java:924)java.awt.color.ICC_profile.getDeferreInstance(ICC_Profile.java:1071)“缩放图像相对简单”对于动画GIF来说并不“容易”。谢谢你的回复,你能给我一个代码示例让我理解process@AndrewThompson一切都是相对的;),你我觉得相对简单,其他人会觉得相对困难……此外,现在你使用动画GIF;P(今天每个人都是批评我的人+1,因为它让我保持警觉)我正要对我的第一句评论眨眼,但拒绝了(…好了,我现在感觉好多了。)