【问题标题】:Framelayout bitmap with specific width and height具有特定宽度和高度的 Framelayout 位图
【发布时间】:2016-06-11 09:33:09
【问题描述】:

如何在将framelayout保存到图像时使用位图的特定宽度和高度?

【问题讨论】:

  • “将框架布局保存到图像”是什么意思?
  • @FabioR 将框架布局转换为具有特定宽度和高度的图像
  • 我不明白你所说的“转换”是什么意思。例如,您有一个带有图像作为背景的 FrameLayout,并且您想使用将图像传递给 ImageView?
  • @FabioR 我有一个框架布局,我在上面添加了一些文本,然后将其转换为位图。不知道把framelayout转成位图保存成图片吗?
  • 这个答案可能对你有帮助stackoverflow.com/questions/21725916/…

标签: android bitmap android-bitmap android-framelayout


【解决方案1】:

检查以下代码

public Bitmap convertFrameToBitmap(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}


ry {
        FileOutputStream output = new FileOutputStream(getActivity().getFilesDir() + File.separator+ image.png");
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
        output.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多