javaは写真をbase 64文字列javaに回転させることを実現します。
java写真はbase 64文字列、base 64文字列を回転してピクチャーを回転して、具体的な内容は以下の通りです。
1.写真はbase 64文字列を回転します。
・・
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。
1.写真はbase 64文字列を回転します。
/**
* base64
* @param imgStr base64
* @param path
* @return
*/
public static boolean base64StrToImage(String imgStr, String path) {
if (imgStr == null)
return false;
BASE64Decoder decoder = new BASE64Decoder();
try {
//
byte[] b = decoder.decodeBuffer(imgStr);
//
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
b[i] += 256;
}
}
//
File tempFile = new File(path);
if (!tempFile.getParentFile().exists()) {
tempFile.getParentFile().mkdirs();
}
OutputStream out = new FileOutputStream(tempFile);
out.write(b);
out.flush();
out.close();
return true;
} catch (Exception e) {
return false;
}
}
2.base 64文字列は画像を回転します。
/**
* base64
* @param imgFile
* @return
*/
public static String imageToBase64Str(String imgFile) {
InputStream inputStream = null;
byte[] data = null;
try {
inputStream = new FileInputStream(imgFile);
data = new byte[inputStream.available()];
inputStream.read(data);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
//
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
3.テスト:
public static void main(String[] args) {
String base64Str = imageToBase64Str("D:/pic/001.jpg");
System.out.println(base64Str);
boolean b = base64StrToImage(base64Str, "D:/pic/temp/002.jpg");
System.out.println(b);
}
効果図:・・
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。