Java Code Examples for android.graphics.Picture#getWidth()

The following examples show how to use android.graphics.Picture#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: X5WebUtils.java    From YCWebView with Apache License 2.0 6 votes vote down vote up
/**
 * X5内核截取长图【暂时用不了】
 * @param webView               x5WebView的控件
 * @return                      返回bitmap对象
 *
 *        方法
 *        1. 使用X5内核方法snapshotWholePage(Canvas, boolean, boolean);在X5内核中提供了一个截取整个
 *        WebView界面的方法snapshotWholePage(Canvas, boolean, boolean),但是这个方法有个缺点,
 *        就是不以屏幕上WebView的宽高截图,只是以WebView的contentWidth和contentHeight为宽高截图,
 *        所以截出来的图片会不怎么清晰,但作为缩略图效果还是不错了。
 *        2. 使用capturePicture()截取清晰长图;如果想要在X5内核下截到清晰的长图,不能使用
 *        snapshotWholePage(),依然可以采用capturePicture()。X5内核下使用capturePicture()进行截图,
 *        可以直接拿到WebView的清晰长图,但这是个Deprecated的方法,使用的时候要做好异常处理。
 */
@Deprecated
public static Bitmap captureX5Picture(WebView webView) {
    if (webView == null) {
        return null;
    }
    try {
        Picture picture =  webView.capturePicture();
        int width = picture.getWidth();
        int height = picture.getHeight();
        if (width > 0 && height > 0) {
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bitmap);
            picture.draw(canvas);
            return bitmap;
        }
    } catch (Exception e){
        e.printStackTrace();
        return null;
    }
    return null;
}
 
Example 2
Source File: DetailFragment.java    From iZhihu with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 截取所有网页内容到 Bitmap
 *
 * @return Bitmap
 */
Bitmap genCaptureBitmap() throws OutOfMemoryError {
    // @todo Future versions of WebView may not support use on other threads.
    try {
        Picture picture = getWebView().capturePicture();
        int height = picture.getHeight(), width = picture.getWidth();
        if (height == 0 || width == 0) {
            return null;
        }
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
        return bitmap;
    } catch (NullPointerException e) {
        return null;
    }
}
 
Example 3
Source File: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public final void drawPicture(@NonNull Picture picture, @NonNull Rect dst) {
    save();
    translate(dst.left, dst.top);
    if (picture.getWidth() > 0 && picture.getHeight() > 0) {
        scale((float) dst.width() / picture.getWidth(),
                (float) dst.height() / picture.getHeight());
    }
    drawPicture(picture);
    restore();
}
 
Example 4
Source File: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public final void drawPicture(@NonNull Picture picture, @NonNull RectF dst) {
    save();
    translate(dst.left, dst.top);
    if (picture.getWidth() > 0 && picture.getHeight() > 0) {
        scale(dst.width() / picture.getWidth(), dst.height() / picture.getHeight());
    }
    drawPicture(picture);
    restore();
}
 
Example 5
Source File: WebViewCapture.java    From ViewCapture with Apache License 2.0 5 votes vote down vote up
private Bitmap captureWebView(WebView webView) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    if (width > 0 && height > 0) {
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
        return bitmap;
    }
    return null;
}
 
Example 6
Source File: ScreenShotHelper.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Bitmap createType1(WebView webView, FileHelper.OnSavedToGalleryListener listener) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    Bitmap bitmap = null;
    if (width > 0 && height > 0) {
        bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
    }
    return bitmap;
}
 
Example 7
Source File: X5WebUtils.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
/**
 * Android5.0以下版本
 * 对WebView进行截屏,虽然使用过期方法,
 * 但在当前Android版本中测试可行
 * @param webView               WebView控件
 * @return                      返回bitmap对象
 */
public static Bitmap captureWebViewKitKat(WebView webView) {
    Picture picture = webView.capturePicture();
    int width = picture.getWidth();
    int height = picture.getHeight();
    if (width > 0 && height > 0) {
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        picture.draw(canvas);
        return bitmap;
    }
    return null;
}
 
Example 8
Source File: PictureBitmapTextureAtlasSource.java    From tilt-game-android with MIT License 4 votes vote down vote up
public PictureBitmapTextureAtlasSource(final Picture pPicture, final int pTextureX, final int pTextureY) {
	this(pPicture, pTextureX, pTextureY, pPicture.getWidth(), pPicture.getHeight());
}
 
Example 9
Source File: PictureBitmapTextureAtlasSource.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public PictureBitmapTextureAtlasSource(final Picture pPicture, final int pTextureX, final int pTextureY) {
	this(pPicture, pTextureX, pTextureY, pPicture.getWidth(), pPicture.getHeight());
}