?? imageutil.java
字號:
package imageapp;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
public class ImageUtil {
public static int[] decodeColor(int color, int rgb[]) {
if(rgb == null) rgb = new int[3];
rgb[0] = (color & 0x00ff0000) >> 16;
rgb[1] = (color & 0x0000ff00) >> 8;
rgb[2] = (color & 0x000000ff);
return rgb;
}
public static int encodeColor(int rgb[]) {
int color = (255 << 24) | (rgb[0] << 16) | (rgb[1] << 8) | rgb[2];
return color;
}
public static int getBrightness(int color) {
int r = (color & 0x00ff0000) >> 16;
int g = (color & 0x0000ff00) >> 8;
int b = (color & 0x000000ff);
int y = Math.round(0.3f*r+0.59f*g+0.11f*b);
y = y < 0 ? 0 : y;
y = y > 255 ? 255 : y;
return y;
}
public static float[] convertRGBToYHS(int color, float yhs[]) {
if(yhs == null) yhs = new float[3];
int r = (color & 0x00ff0000) >> 16;
int g = (color & 0x0000ff00) >> 8;
int b = (color & 0x000000ff);
yhs[0] = (float)(0.3*r+0.59*g+0.11*b);
double c1 = 0.7*r-0.59*g-0.11*b;
double c2 = -0.3*r-0.59*g+0.89*b;
yhs[2] = (float)Math.sqrt(c1*c1+c2*c2);
if(yhs[2] < 0.005) yhs[1] = 0;
else {
yhs[1] = (float)Math.atan2(c1, c2);
if(yhs[1] < 0) yhs[1] += (float)Math.PI*2;
}
return yhs;
}
public static int convertYHSToRGB(float yhs[]) {
double c1 = yhs[2]*Math.sin(yhs[1]);
double c2 = yhs[2]*Math.cos(yhs[1]);
int r = (int)Math.round(yhs[0]+c1);
r = r < 0 ? 0 : r;
r = r > 255 ? 255 : r;
int g = (int)Math.round(yhs[0]-0.3*c1/0.9-0.11*c2/0.59);
g = g < 0 ? 0 : g;
g = g > 255 ? 255 : g;
int b = (int)Math.round(yhs[0]+c2);
b = b < 0 ? 0 : b;
b = b > 255 ? 255 : b;
int color = (255 << 24) | (r << 16) | (g << 8) | b;
return color;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -