如何在java中将图像转换为棕褐色?

2024-03-30

我正在寻找免费或收费图书馆。

Update

看起来没有这样的库,但以下代码按预期工作:

/**
*
* @param img Image to modify
* @param sepiaIntensity From 0-255, 30 produces nice results
* @throws Exception
*/
public static void applySepiaFilter(BufferedImage img, int sepiaIntensity) {
    // Play around with this. 20 works well and was recommended
    // by another developer. 0 produces black/white image
    int sepiaDepth = 20;

    int w = img.getWidth();
    int h = img.getHeight();

    WritableRaster raster = img.getRaster();

    // We need 3 integers (for R,G,B color values) per pixel.
    int[] pixels = new int[w*h*3];
    raster.getPixels(0, 0, w, h, pixels);

    // Process 3 ints at a time for each pixel.
    // Each pixel has 3 RGB colors in array
    for (int i=0;i<pixels.length; i+=3) {
        int r = pixels[i];
        int g = pixels[i+1];
        int b = pixels[i+2];

        int gry = (r + g + b) / 3;
        r = g = b = gry;
        r = r + (sepiaDepth * 2);
        g = g + sepiaDepth;

        if (r>255) r=255;
        if (g>255) g=255;
        if (b>255) b=255;

        // Darken blue color to increase sepia effect
        b-= sepiaIntensity;

        // normalize if out of bounds
        if (b<0) b=0;
        if (b>255) b=255;

        pixels[i] = r;
        pixels[i+1]= g;
        pixels[i+2] = b;
    }
    raster.setPixels(0, 0, w, h, pixels);
}

http://www.swissdelphicenter.ch/en/showcode.php?id=1794 http://www.swissdelphicenter.ch/en/showcode.php?id=1794

http://www.rhinocerus.net/forum/lang-java-programmer/574119-sepia-tone-image-filter-java.html http://www.rhinocerus.net/forum/lang-java-programmer/574119-sepia-tone-image-filter-java.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在java中将图像转换为棕褐色? 的相关文章

随机推荐

  • 在caffe中定义新层时如何获取学习率或迭代次数

    我想当迭代次数达到一定次数时改变损失层中的损失计算方法 为了实现它 我认为我需要获取当前的学习率或迭代次数 然后我使用if短语选择是否改变损失计算方法 您可以添加一个成员变量咖啡类保存当前的学习率或迭代次数并在您想要的层中访问它 例如 要获
  • 如何从命令行删除钥匙串引用

    From the Keychain app I have the option to delete just the reference to a listed Keychain that was unlocked and listed v
  • 使用元类覆盖复杂内置方法

    作为学习练习 我正在尝试实现一个类来模拟 python 的行为complex内置的 但具有不同的行为 str and repr 方法 我希望它们以以下格式打印 1 0 2 0 代替 1 2j 我首先尝试简单地从complex并重新定义 st
  • 在 Fortran 语言中 advance='no' 是什么意思?

    我是 Fortran 新手 我不明白这一行 write a35 advance no in program democonvertion implicit none real tc tf tr tk write a35 advance no
  • Windows RT .NET 兼容性

    我只需要知道我是否需要相同的框架来开发适用于平板电脑 Windows RT 和 PC 的 Windows 8 应用程序 或者平板电脑仍然使用 NET 紧凑框架 在 Windows RT 即 Windows 8 的平板电脑 ARM 版本 上运
  • C# 中的字节数组加密

    我想使用按位运算符创建一个很好的密码学 然而我没有这样做 我希望它具有使用字节数组的按位运算符来加密和解密我的字节数组 public class Cryptographer private byte Keys get set public
  • 从 F# 访问名称中包含 .base 的命名空间

    正如标题所示 我试图使用在名称中包含 base 的名称空间中声明的类 考虑如下情况 open Foo base Bar 在 C 中 我只是在基数之前使用 但 F 似乎忽略了这一点 并认为 是用于列表连接的中缀运算符 由于命名空间属于我无法修
  • 创建每个键包含多个值的字典

    如何创建一个字典 其中每个键包含 2 个列表中的多个值 例如 我有 gt gt gt list1 fruit fruit vegetable gt gt gt list2 apple banana carrot 而且 我想要一些效果 gt
  • 将 jquery masonry 集成到 zurb 基础网格中

    我在将砌体与基础网格布局集成时遇到问题 本质上 对于具有不同高度的相同宽度图像 砌体按预期工作 但在某些断点处 网格将仅具有两列布局 而不是通常的四列布局 但是 如果您继续最小化浏览器宽度 则会返回四列 因此不可能没有空间来显示它们 var
  • 通过父id和mysql中的where子句获取所有子项

    我有一个表 将 id 和parent id 存储在同一个表中 我想要一个接受parent id 作为参数并返回第n 级的所有子节点的递归查询 为此 我正在使用此代码并为我正常工作 select id name parent from sel
  • 如何使用 PowerShell 发送电子邮件

    我想从 PowerShell 发送电子邮件 所以我使用这个命令 EmailFrom email protected cdn cgi l email protection EmailTo email protected cdn cgi l e
  • 使用 eval 和 eval-source-map 有什么区别?

    我正在使用 webpack 来配置源映射 我想知道有人可以澄清 eval 和 eval source map 之间的区别吗 我个人看不出有什么区别 来自文档 https webpack js org configuration devtoo
  • .NET Core 的 IWebProxy 实现的位置

    System Net IWebProxy 的可用实现是什么 来自 System Net Primitives DNX Core 根据应用程序要求 dnxcore50 中可以使用唯一的框架 那么包含代理实现的正确 NuGet 包是什么 解决此
  • 在运行时测试 iOS 版本特定功能的推荐方法

    我的目标是 IOS 4 3 和 5 0 其中一个应用程序是针对 5 0 SDK 构建的 并且希望仅当该应用程序在 iOS5 设备上运行时才添加对 iOS5 中引入的 Twitter 功能的支持 在运行时可靠地测试这些操作系统功能的可用性而不
  • Apollo GraphQL 请求被取消

    我正在使用 React 类型前置文本字段组件Downshift and react apollo 当用户输入时 我正在查询输入建议并将其显示在文本字段下方 不幸的是 这段经历并不顺利 由于某种原因 Apollo 时不时会取消 50 以上的请
  • 使用 facebook graph api 搜索好友

    Facebook 是否有用于搜索用户好友的 API Tim 您可以这样搜索朋友的名字 select uid name sex from user where uid in SELECT uid2 FROM friend WHERE uid1
  • 对于阿拉伯语应用程序,英文字母的顺序相反(在 wkwebview 内)

    您好 当我将操作系统更新到版本 14 时 我在 webview 中看到了一个问题 即我的阿拉伯应用程序上的英文字母顺序相反 我的应用程序本地化设置为 Localization native development region ar 并使用
  • database_cleaner 正在擦除我的开发数据库

    I have database cleaner为我的 Rails 4 应用程序配置 每次运行测试时 我发现我的数据库在两个版本中都被清除了test and development环境 我的配置在rails helper如下 ENV RAIL
  • 使用 build_runner 在子模块中构建 JsonSerialized 模型

    我有一个带有子模块的 Flutter 项目 root Flutter project Flutter module 1 Flutter module 2 Flutter module N 每个模块包含带有注释的类 JsonSerializa
  • 如何在java中将图像转换为棕褐色?

    我正在寻找免费或收费图书馆 Update 看起来没有这样的库 但以下代码按预期工作 param img Image to modify param sepiaIntensity From 0 255 30 produces nice res