如何在Android Studio中保存图像并将其覆盖到图库中?

如何在Android Studio中保存图像并将其覆盖到图库中?,android,Android,我们正在尝试制作一个应用程序,让用户上传图像,在上面写下文本,然后用文本保存新图像 我们当前的实现是使用ImageView保存图像,然后使用TextView在其上进行写入 保存整个图像的最佳方法是什么?下面是我们当前的代码 谢谢你的帮助!:) 使用以下命令: public Bitmap takeScreenshot() { View rootView = getView(); rootView.setDrawingCacheEnabled(true);

我们正在尝试制作一个应用程序,让用户上传图像,在上面写下文本,然后用文本保存新图像

我们当前的实现是使用ImageView保存图像,然后使用TextView在其上进行写入

保存整个图像的最佳方法是什么?下面是我们当前的代码

谢谢你的帮助!:)

使用以下命令:

  public Bitmap takeScreenshot() {
        View rootView = getView();
        rootView.setDrawingCacheEnabled(true);
        rootView.buildDrawingCache(true);
        Bitmap b1 = Bitmap.createBitmap(rootView.getDrawingCache(true));
        rootView.setDrawingCacheEnabled(false); // clear drawing cache
        return b1;
    }
要将位图保存到图像,请执行以下操作:

public void saveBitmap(Bitmap bitmap) {
    if(bitmap==null){
        return;
    }
    File imagePath1 = new File(savePath,"screenshot.jpg");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath1);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}
使用以下命令:

  public Bitmap takeScreenshot() {
        View rootView = getView();
        rootView.setDrawingCacheEnabled(true);
        rootView.buildDrawingCache(true);
        Bitmap b1 = Bitmap.createBitmap(rootView.getDrawingCache(true));
        rootView.setDrawingCacheEnabled(false); // clear drawing cache
        return b1;
    }
要将位图保存到图像,请执行以下操作:

public void saveBitmap(Bitmap bitmap) {
    if(bitmap==null){
        return;
    }
    File imagePath1 = new File(savePath,"screenshot.jpg");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath1);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

这个问题已经被提出和回答了。是的,6年前。。。完全不赞成。这个问题已经被提出和回答了。是的,6年前。。。完全不赞成。