woong's

Android 화면 ScreenShot 사용하기 본문

Develop/Android

Android 화면 ScreenShot 사용하기

dlsdnd345 2016. 2. 14. 17:18
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Android 화면 ScreenShot 사용하기 



Colored By Color Scripter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.iris.util;
 
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
 
public class ScreenshotUtil {
 
    public Activity activity;
    
    public ScreenshotUtil(Activity activity){
        
        this.activity = activity;
    }
    
    /**
     * 화면 스크린샷 기능
     * @param activity
     * @return
     */
    @SuppressLint("NewApi")
    public Bitmap takeScreenShot()
    {
        View view = activity.getWindow().getDecorView();
        view.setDrawingCacheEnabled(true);
        view.buildDrawingCache();
        Bitmap b1 = view.getDrawingCache();
        Rect frame = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;
 
        Display display = ((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point point = new Point();
         
        display.getSize(point);
        int height = point.y;
        int width = point.x;
        
        Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height  - statusBarHeight);
 
        view.destroyDrawingCache();
        return b;
    }
    
}
 


Comments