Java 我是否在绘图,然后保存图像,然后将其重新加载到绘图画布中?

Java 我是否在绘图,然后保存图像,然后将其重新加载到绘图画布中?,java,android,android-studio,canvas,draw,Java,Android,Android Studio,Canvas,Draw,因此,我正在制作这个应用程序,你在画布上绘制,我将你绘制的内容保存在应用程序特定的存储中(可以说是敏感内容),然后我应该能够再次加载位图,进行修改并再次保存。 下面的代码是如何保存从绘图中获得的位图。目录是文件类型 public String saveImage(String filename, Bitmap image){ File file=new File(directory,filename+"jpg"); try { FileOu

因此,我正在制作这个应用程序,你在画布上绘制,我将你绘制的内容保存在应用程序特定的存储中(可以说是敏感内容),然后我应该能够再次加载位图,进行修改并再次保存。 下面的代码是如何保存从绘图中获得的位图。目录是文件类型

public  String saveImage(String filename, Bitmap image){
    File file=new File(directory,filename+"jpg");

    try {
        FileOutputStream out = new FileOutputStream(file);
        image.compress(Bitmap.CompressFormat.JPEG, 90, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        System.out.println("FileNotFoundException");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("IOException");
        e.printStackTrace();
    }
    return file.getAbsolutePath();
}
以下是我如何从内部存储器加载映像:

public  Bitmap loadImage(String filename) throws FileNotFoundException {
    File f = new File(directory, filename + "jpg");
    Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
    return convertToMutable(context,b);
}
我必须添加我不完全理解的方法,才能将位图转换为可变:

public static Bitmap convertToMutable(final Context context, final Bitmap imgIn) {
    final int width = imgIn.getWidth(), height = imgIn.getHeight();
    final Bitmap.Config type = imgIn.getConfig();
    File outputFile = null;
    final File outputDir = context.getCacheDir();
    try {
        outputFile = File.createTempFile(Long.toString(System.currentTimeMillis()), null, outputDir);
        outputFile.deleteOnExit();
        final RandomAccessFile randomAccessFile = new RandomAccessFile(outputFile, "rw");
        final FileChannel channel = randomAccessFile.getChannel();
        final MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, imgIn.getRowBytes() * height);
        imgIn.copyPixelsToBuffer(map);
        imgIn.recycle();
        final Bitmap result = Bitmap.createBitmap(width, height, type);
        map.position(0);
        result.copyPixelsFromBuffer(map);
        channel.close();
        randomAccessFile.close();
        outputFile.delete();
        return result;
    } catch (final Exception e) {
    } finally {
        if (outputFile != null)
            outputFile.delete();
    }
    return null;
}
我将画布设置为:

public void setCanvasBitmap(Bitmap b){
    drawCanvas=new Canvas(b);
}
希望时间不要太长。问题是它没有显示我以前保存在画布中的位图