相关疑难解决方法(0)

在 Android 中在屏幕外将视图渲染为位图

我想将视图渲染到位图并保存位图。但我需要在屏幕外完成这一切。

我试过这个:

    LayoutInflater inflater = getLayoutInflater();
    View linearview = (View) findViewById(R.id.linearview);
    linearview = inflater.inflate(R.layout.intro, null);


Bitmap bm = Bitmap.createBitmap( linearview.getMeasuredWidth(), linearview.getMeasuredHeight(), Bitmap.Config.ARGB_8888);                
Canvas c = new Canvas(bm);
linearview.layout(0, 0, linearview.getLayoutParams().width, linearview.getLayoutParams().height);
linearview.draw(c);

    String extStorageDirectory = Environment.getExternalStorageState().toString();
    extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    OutputStream outStream = null;
    File file = new File(extStorageDirectory, "screen1.PNG");

    try {
        outStream = new FileOutputStream(file);
        bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();


    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch …
Run Code Online (Sandbox Code Playgroud)

java android

5
推荐指数
1
解决办法
3893
查看次数

来自View的位图未在Android上显示

我试图从一个尚未显示的视图创建一个位图,将其设置为Android中的OpenGL纹理.问题是,当我创建我的位图时,我的View的布局参数有0值,因为尚未调用onLayout()函数.有没有办法"模拟"布局或做一个"背景布局"来获得正确的布局参数?我正在考虑具有两个视图的Frame布局,背景一个用于创建我的位图,因为布局已经完成.

谢谢.

layout android bitmap

4
推荐指数
1
解决办法
5136
查看次数

标签 统计

android ×2

bitmap ×1

java ×1

layout ×1