代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
java调整图片的亮度
作者:
april
/ 发布于
2015/1/12
/
402
package cn.outofmemory.snippets.desktop; import java.awt.Component; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Toolkit; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.image.RescaleOp; public class BufferedImageSaturation { static BufferedImage image; static boolean imageLoaded = false; public static void main(String[] args) { // The ImageObserver implementation to observe loading of the image ImageObserver myImageObserver = new ImageObserver() { public boolean imageUpdate(Image image, int flags, int x, int y, int width, int height) { if ((flags & ALLBITS) != 0) { imageLoaded = true; System.out.println("Image loading finished!"); return false; } return true; } }; // The image URL - change to where your image file is located! String imageURL = "image.png"; /* * This call returns immediately and pixels are loaded in the background * We use an ImageObserver to be notified when the loading of the image * is complete */ Image sourceImage = Toolkit.getDefaultToolkit().getImage(imageURL); sourceImage.getWidth(myImageObserver); // We wait until the image is fully loaded while (!imageLoaded) { try { Thread.sleep(100); } catch (InterruptedException e) { } } // Create a buffered image from the source image with a format that's compatible with the screen GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice(); GraphicsConfiguration graphicsConfiguration = graphicsDevice.getDefaultConfiguration(); // If the source image has no alpha info use Transparency.OPAQUE instead image = graphicsConfiguration.createCompatibleImage(sourceImage.getWidth(null), sourceImage.getHeight(null), Transparency.BITMASK); // Copy image to buffered image Graphics graphics = image.createGraphics(); // Paint the image onto the buffered image graphics.drawImage(sourceImage, 0, 0, null); graphics.dispose(); // Brighten the image by 20% float scaleFactor = 1.2f; RescaleOp op = new RescaleOp(scaleFactor, 0, null); image = op.filter(image, null); // Darken the image by 5% scaleFactor = 0.5f; op = new RescaleOp(scaleFactor, 0, null); image = op.filter(image, null); // Create frame with specific title Frame frame = new Frame("Example Frame"); // Add a component with a custom paint method frame.add(new CustomPaintComponent()); // Display the frame int frameWidth = 300; int frameHeight = 300; frame.setSize(frameWidth, frameHeight); frame.setVisible(true); } /* * To draw on the screen, it is first necessary to subclass a Component and * override its paint() method. The paint() method is automatically called * by the windowing system whenever component's area needs to be repainted. */ static class CustomPaintComponent extends Component { public void paint(Graphics g) { // Retrieve the graphics context; this object is used to paint // shapes Graphics2D g2d = (Graphics2D) g; /* * Draw an Image object The coordinate system of a graphics context * is such that the origin is at the northwest corner and x-axis * increases toward the right while the y-axis increases toward the * bottom. */ int x = 0; int y = 0; g2d.drawImage(image, x, y, this); } } }
试试其它关键字
图片的亮度
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
april
贡献的其它代码
(
15
)
.
java web 获取客户端操作系统信息
.
把一个List
集合中的数据用分隔符分开,并以字
.
SQ查询添加字段为行号
.
连接三个数据表
.
KMP算法
.
替换所有指定字符串
.
输入一串整数,输出其和
.
css3文字高亮发光
.
汉字转拼音或首字母,手写版非pinyin4j,可排除例外
.
生成gray码
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3