顯示具有 Java 標籤的文章。 顯示所有文章
顯示具有 Java 標籤的文章。 顯示所有文章

2013年11月4日 星期一

Java 影像亮度、對比

public Image filter2(Image img) {

int width = img.getWidth(null);
int height = img.getHeight(null);

BufferedImage src = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);

src.getGraphics().drawImage(img, 0, 0, null);

int[] inPixels = new int[width * height];
int[] outPixels = new int[width * height];
int index = 0;

src.getRGB(0, 0, width, height, inPixels, 0, width);

int r, g, b;

int bfi = (int) (getBrightness() * 255);// 0~255
float cf = 1f + getContrast();// -1~1
cf *= cf;
int cfi = (int) (cf * 32768) + 1;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {

index = row * width + col;
Color color = new Color(inPixels[index]);
r = color.getRed();
g = color.getGreen();
b = color.getBlue();

if (bfi != 0) {
// Add brightness
int ri = r + bfi;
int gi = g + bfi;
int bi = b + bfi;
// Clamp to byte boundaries
r = ri > 255 ? 255 : (ri < 0 ? 0 : ri);
g = gi > 255 ? 255 : (gi < 0 ? 0 : gi);
b = bi > 255 ? 255 : (bi < 0 ? 0 : bi);
}

if (cfi != 32769) {
// Transform to range [-128, 127]
int ri = r - 128;
int gi = g - 128;
int bi = b - 128;

// Multiply contrast factor
ri = (ri * cfi) >> 15;
gi = (gi * cfi) >> 15;
bi = (bi * cfi) >> 15;

// Transform back to range [0, 255]
ri = ri + 128;
gi = gi + 128;
bi = bi + 128;

// Clamp to byte boundaries
r = ri > 255 ? 255 : (ri < 0 ? 0 : ri);
g = gi > 255 ? 255 : (gi < 0 ? 0 : gi);
b = bi > 255 ? 255 : (bi < 0 ? 0 : bi);
}
color = new Color(r, g, b);
outPixels[index] = color.getRGB();
}
}

BufferedImage buffered = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
buffered.setRGB(0, 0, width, height, outPixels, 0, width);

return buffered;
}

2013年10月15日 星期二

JAVA 取得可用字型名稱

String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getAvailableFontFamilyNames();

2013年9月12日 星期四

Jar 簽證

1.在cmd中用keytool建立公鑰和密鑰,生成簽名憑証

keytool -genkey -keystore 文件名.store -alias 别名(記住密碼) -validity (days)

Ex: keytool -genkey -keystore test.store -alias testkey -validity 7200 (私(密)key)

2.執行jarsigner工具,並指定jar檔和私密金鑰的別名

 jarsigner -keystore 密鑰名 JAR名 别名

ex: jarsigner -keystore teststore testclient.jar testkey

3.產生certs.store並把testkey憑證加入
keytool -export -keystore test.store -alias testkey -file testkey.cert

keytool -import -keystore cert.store -alias testkey -file testkey.cert

4. 必須產生policy授與權限給所有以該金鑰庫中簽章的applet
在policy檔中加入
keystore "keystoreURL","keystore類型"
e.g
keystore "file:cert.store","JKS"
接著在policy中加入
grant 
{
permission java.io.FilePermission "","";
};

5.測試時,確定金鑰庫 policy 和jar全在同一目錄下
qppletviewer -J-Djava.security.policy=applets.policy TestApplet.html
application -Djava.security.policy=applets.policy TestApplet.html 

https://code.google.com/p/java-simple-serial-connector/wiki/jSSC_Terminal