2011-10-21 4 views
3

나는 비트 맵에 뷰를 렌더링하고 비트 맵을 저장하고 싶다. 하지만 그걸 화면에서 모두해야합니다.안드로이드에서 비트 맵에서 비트 맵으로 화면을 비우는 것

나는이 시도했다 :

LayoutInflater inflater = getLayoutInflater(); 
    View linearview = (View) findViewById(R.id.linearview); 
    linearview = inflater.inflate(R.layout.intro, null); 


Bitmap bm = Bitmap.createBitmap(linearview.getMeasuredWidth(), linearview.getMeasuredHeight(), Bitmap.Config.ARGB_8888);     
Canvas c = new Canvas(bm); 
linearview.layout(0, 0, linearview.getLayoutParams().width, linearview.getLayoutParams().height); 
linearview.draw(c); 

    String extStorageDirectory = Environment.getExternalStorageState().toString(); 
    extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 
    OutputStream outStream = null; 
    File file = new File(extStorageDirectory, "screen1.PNG"); 

    try { 
     outStream = new FileOutputStream(file); 
     bm.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
     outStream.flush(); 
     outStream.close(); 


    } catch (FileNotFoundException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

편집 : 내 응용 프로그램 충돌보기 나던은 폭이나 높이가 있기 때문이다. (조치는 그것을 해결하기위한 시도입니다)

그리고 나쁜 영어에 상처를 입히십시오.

+1

가 충돌에 대해 물어 당신은 항상 – jqpubliq

+0

내가이를 설정하는 방법 서비스 –

+0

에서 작업을 수행하여 추적을 게시해야 레이아웃 서비스? –

답변

1

문제는 여기에 있습니다 :

linearview = inflater.inflate(R.layout.intro, null); 

당신은 부모 레이아웃을 통과해야하므로 제대로 측정 할 수 있습니다. 뷰를 레이아웃에 첨부하고 싶지는 않지만이 메서드의 다른 버전을 사용하여 측정을 위해서만 부모 레이아웃을 사용할 수 있으며 attachToRoot에 false를 전달할 수 있습니다. 을 제공합니다 (attachToRoot에 해당하는 경우) 옵션 뷰가 생성 된 계층 구조의 부모가 될, 그렇지 않으면 단순히 객체 :

루트 다음 4. 기본값의 공식 문서에서

public View inflate (int resource, ViewGroup root, boolean attachToRoot) 

반환되는 계층 구조의 루트에 대한 LayoutParams 값 집합입니다 (attachToRoot가 false 인 경우).

attachToRoot : 팽창 된 계층을 루트 매개 변수에 연결해야합니까? false의 경우, root는 XML의 루트 뷰의 LayoutParams의 올바른 서브 클래스를 작성하기 위해서만 사용됩니다. 의심 당신은 항상 부모 레이아웃과 앱 콘텐츠 통과 할 때

:

findViewById(android.R.id.content); 
관련 문제