zoukankan      html  css  js  c++  java
  • chromium截图实现

    声明:本blog是我自己写的,假设要转载,请注明:come from blog of niba!

    chromium终于显示是在ContentView上。但通过硬件加速。渲染合成的网页之前是在surfaceview上的。

    所以。实现chromium的截图能够通过SufraceView的截图去实现。

      自己创建一个SurfaceView的子类,例如以下:

        class ChromiumSurfaceView extends SurfaceView {
            public ChromiumSurfaceView(Context context){
                super(context);
            }
            
            @Override
            public void onDraw(Canvas canvas) {
                // We only need to draw to software canvases, which are used for taking screenshots.
                if (canvas.isHardwareAccelerated()) return;
                Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(),
                        Bitmap.Config.ARGB_8888);
                if (nativeCompositeToBitmap(mNativeContentViewRenderView, bitmap)) {
                    canvas.drawBitmap(bitmap, 0, 0, null);
                }
            }

            public void getBitmap(Canvas canvas){
                this.onDraw(canvas);
            }
        }

       通过方法getBitmap()间接去调用onDraw方法来实现将内容,进行绘制。


        public void getScreenShot() {
            Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
            Canvas bitCanvas = new Canvas(bitmap);
            ((ChromiumSurfaceView)mSurfaceView).getBitmap(bitCanvas);
           
            try{
                File file = new File("/data/data/com.hisense.goblin/test.jpeg");
                FileOutputStream fos;
                 fos = new FileOutputStream(file);
                  bitmap.compress(Bitmap.CompressFormat.JPEG, 5, fos);
                  fos.close();
            }catch(Exception e){
                e.printStackTrace();
            }
            
       }
     通过这种方法就能够实现截屏了。

     关于SurfaceView的其它信息,能够參考其它的blog,网上讲的非常多。这里不再赘述   

  • 相关阅读:
    Http方法:Get请求与Post请求的区别
    udev和rules使用规则
    c++中的动态内存分配
    c++中重载运算符
    c++中静态成员函数
    c++中值传递,址传递,引用传递
    c++中实现单例模式singleton class
    [Windows篇] 在windows 10上源码编译gtest 并编写CMakeLists.txt
    [Ubuntu篇] 在ubuntu上源码编译gtest,编写gtest-config.cmake并测试
    使用boost data_time模块来获取毫秒级时间并转换为string字符串
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5285180.html
Copyright © 2011-2022 走看看