你好我想旋转我的图像并保存在文件中我这样做了:
for (int i = 0; i < 361; i++) {
Bitmap bm = RotateMyBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.znacznik_new), i);
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
Integer counter = 0;
File file = new File(path, "ikona"+i+".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten.
try {
fOut = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bm.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate
try {
fOut.flush(); // Not really required
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close(); // do not forget to close the stream
} catch (IOException e) {
e.printStackTrace();
}
try {
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static Bitmap RotateMyBitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
然后我旋转图像并且我有文件但是图像有黑色背景而我的原始图像没有黑色背景它有 transpadence 。我如何将黑色更改为透明色并保存在文件中
最佳答案
JPEG 不支持透明度,所有透明部分都会变成黑色。 使用 Bitmap.CompressFormat.PNG 压缩位图。
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
关于Java android将图片中的黑色更改为tracspadence并保存在文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44493942/