lss
2022-05-26 ff886457f58791eea4532f6167af51184d9dfe43
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/utils/HDLImageUtils.java
@@ -5,6 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.media.MediaScannerConnection;
import android.net.Uri;
@@ -18,12 +19,15 @@
import com.hdl.hdllinphonesdk.R;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.SoftReference;
/**
 * Created by jlchen on 2021/8/16.
@@ -101,6 +105,38 @@
    }
    /**
     * 保存图片至相册
     * 需要读写权限
     */
    public static boolean saveImageToGallery(Context context, byte[] image_bytes) {
        Bitmap bitmap = byteToBitmap(image_bytes);
        return saveImageToGallery(context, bitmap);
    }
    public static Bitmap byteToBitmap(byte[] imgByte) {
        InputStream input = null;
        Bitmap bitmap = null;
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
        input = new ByteArrayInputStream(imgByte);
        SoftReference softRef = new SoftReference(BitmapFactory.decodeStream(input, null, options));  //软引用防止OOM
        bitmap = (Bitmap) softRef.get();
        if (imgByte != null) {
            imgByte = null;
        }
        try {
            if (input != null) {
                input.close();
            }
        } catch (IOException e) {
            // 异常捕获
            e.printStackTrace();
        }
        return bitmap;
    }
    /**
     * 将文件保存到公共的媒体文件夹