GithubHelp home page GithubHelp logo

neil-orzzh / content2picture Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jarlen/content2picture

0.0 1.0 0.0 896 KB

先看需求: 当内容已经超出了手机可显示的范围时,要截取这些所有的内容,从而生成所谓的”长截图”. 没什么难点,利用了webview的特点,和scrollview 的view的绘制,生成bitmap。

Java 100.00%

content2picture's Introduction

content2picture

先看需求: 当内容已经超出了手机可显示的范围时,要截取这些所有的内容,从而生成所谓的”长截图”. 没什么难点,利用了webview的特点,和scrollview 的view的绘制,生成bitmap。

主要代码:

//这是scrollview的

public static Bitmap getBitmapByView(ScrollView scrollView) { int h = 0; Bitmap bitmap = null;

    for (int i = 0; i < scrollView.getChildCount(); i++) {
        h += scrollView.getChildAt(i).getHeight();
        scrollView.getChildAt(i).setBackgroundColor(
                Color.parseColor("#ffffff"));
    }

    bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
            Bitmap.Config.RGB_565);
    final Canvas canvas = new Canvas(bitmap);
    scrollView.draw(canvas);
    return bitmap;
}

/** * mScrollView * * @param context * @param scrollView */ public static void scrollviewContent2Png(Context context, ScrollView scrollView) { Bitmap bmp = null; bmp = getBitmapByView(scrollView); saveBitmapToCamera(context, bmp, null); }

//这是webview的,利用了webview的api

private static Bitmap captureWebView(WebView webView) { Picture snapShot = webView.capturePicture(); Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), snapShot.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); snapShot.draw(canvas); return bmp; }

代码粗略,只实现了功能部分,在图片生成的时候,未使用线程,如果还有其他比较好的方案,可以相互交流下

content2picture's People

Contributors

jarlen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.