├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── README.md ├── ic_launcher-web.png ├── libs └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ ├── ic_launcher.png │ └── pic.jpg ├── drawable-xxhdpi │ └── ic_launcher.png ├── layout │ ├── layout_main.xml │ ├── layout_scrollview_test.xml │ └── layout_webview_test.xml ├── menu │ └── content_to_picture.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values-w820dp │ └── dimens.xml └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── src └── com └── jarlen └── picture ├── ContentToPictureUtils.java ├── ScrollViewToPictureActivity.java ├── TestMainActivity.java └── WebviewToPictureActivity.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ContentToPicture 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/com/jarlen/picture/ContentToPictureUtils.java=UTF-8 3 | encoding//src/com/jarlen/picture/ScrollViewToPictureActivity.java=UTF-8 4 | encoding//src/com/jarlen/picture/WebviewToPictureActivity.java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # content2picture 2 | 先看需求: 当内容已经超出了手机可显示的范围时,要截取这些所有的内容,从而生成所谓的”长截图”. 没什么难点,利用了webview的特点,和scrollview 的view的绘制,生成bitmap。 3 | 4 | 主要代码: 5 | 6 | //这是scrollview的 7 | 8 | public static Bitmap getBitmapByView(ScrollView scrollView) { 9 | int h = 0; 10 | Bitmap bitmap = null; 11 | 12 | for (int i = 0; i < scrollView.getChildCount(); i++) { 13 | h += scrollView.getChildAt(i).getHeight(); 14 | scrollView.getChildAt(i).setBackgroundColor( 15 | Color.parseColor("#ffffff")); 16 | } 17 | 18 | bitmap = Bitmap.createBitmap(scrollView.getWidth(), h, 19 | Bitmap.Config.RGB_565); 20 | final Canvas canvas = new Canvas(bitmap); 21 | scrollView.draw(canvas); 22 | return bitmap; 23 | } 24 | 25 | 26 | /** 27 | * mScrollView 28 | * 29 | * @param context 30 | * @param scrollView 31 | */ 32 | public static void scrollviewContent2Png(Context context, 33 | ScrollView scrollView) { 34 | Bitmap bmp = null; 35 | bmp = getBitmapByView(scrollView); 36 | saveBitmapToCamera(context, bmp, null); 37 | } 38 | 39 | //这是webview的,利用了webview的api 40 | 41 | private static Bitmap captureWebView(WebView webView) { 42 | Picture snapShot = webView.capturePicture(); 43 | Bitmap bmp = Bitmap.createBitmap(snapShot.getWidth(), 44 | snapShot.getHeight(), Bitmap.Config.ARGB_8888); 45 | Canvas canvas = new Canvas(bmp); 46 | snapShot.draw(canvas); 47 | return bmp; 48 | } 49 | 50 | 代码粗略,只实现了功能部分,在图片生成的时候,未使用线程,如果还有其他比较好的方案,可以相互交流下 51 | -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/libs/android-support-v4.jar -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-15 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/res/drawable-xhdpi/pic.jpg -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jarlen/content2picture/adc43e7a62d0aedc6a4da3581fdeeb07f1448d6a/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/layout_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 |