Java android将图片中的黑色更改为tracspadence并保存在文件中

Java android将图片中的黑色更改为tracspadence并保存在文件中,java,android,Java,Android,您好,我想旋转我的图像并保存在文件中我执行了以下操作: for (int i = 0; i < 361; i++) { Bitmap bm = RotateMyBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.znacznik_new), i); String path = Environment.getExternalStorageDirectory().toString(); Outpu

您好,我想旋转我的图像并保存在文件中我执行了以下操作:

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);
    }
for(int i=0;i<361;i++){
位图bm=RotateMyBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.znacznik_new),i);
字符串路径=Environment.getExternalStorageDirectory().toString();
OutputStream fOut=null;
整数计数器=0;
File File=new File(路径“ikona”+i+“.jpg”);//要保存的文件,请附加递增的数字计数器以防止文件被覆盖。
试一试{
fOut=新文件输出流(文件);
}catch(filenotfounde异常){
e、 printStackTrace();
}
bm.compress(Bitmap.CompressFormat.JPEG,85,fOut);//将位图保存到压缩率为85%的JPEG压缩文件中
试一试{
fOut.flush();//实际上不是必需的
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
fOut.close();//不要忘记关闭流
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
MediaStore.Images.Media.insertImage(getContentResolver()、file.getAbsolutePath()、file.getName()、file.getName());
}catch(filenotfounde异常){
e、 printStackTrace();
}
}
公共静态位图RotateMyBitmap(位图源、浮动角度){
矩阵=新矩阵();
矩阵。旋转后(角度);
返回Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight(),matrix,true);
}

我旋转图像,我有文件,但图像有黑色背景,我的原始图像没有黑色背景,它有透明。如何将黑色更改为透明并保存在文件中JPEG不支持透明,所有透明部分将变为黑色。 使用bitmap.CompressFormat.PNG压缩位图

bm.compress(Bitmap.CompressFormat.PNG,100,fOut)


没有人知道
RotateMyBitmap
的真正含义您的
RotateMyBitmap
方法中存在问题。JPEG不支持透明,请尝试PNG。Bitmap.CompressFormat.PNG.fair(我想你正在使用JPEG),JPEG不支持transparency@VladMatvienko我编辑我的帖子