마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 mapV2 사용할때 캡쳐 방법좀 알려주세요

+2 추천

<LinearLayout
        android:id="@+id/LinMapCapture"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
   
  <fragment xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/map2"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         class="com.google.android.gms.maps.SupportMapFragment" />
 
 </LinearLayout>

xml은 이런식으로 구성되어있습니다

 

fragment를 사용해야 된다고 하더라구요 map v2는

그래서 이렇게 해서 맵은 잘 띄워졌습니다

그런데 해당 맵을 캡쳐했는데

검정 화면만 나옵니다

이렇게 나오더라구요

제 소스는 이렇게 되있습니다

GoogleMap mGoogleMap;

LinearLayout LinMapCaputre;

 

onCreate부분

LinMapCaputre = (LinearLayout) findViewById(R.id.LinMapCapture);
  
  mGoogleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();

 

캡쳐 부분

LinMapCaputre.buildDrawingCache();
    Bitmap bm = LinMapCaputre.getDrawingCache();
    String sd =
      Environment.getExternalStorageDirectory().getAbsolutePath();
    File dir = new File(sd+"/DCIM/mapViewCapture");
    //폴더가 존재 안하면
    if(!dir.exists()){
     dir.mkdirs();
    }
    FileOutputStream fos;
    try {
     String FileName = calendar.get(Calendar.YEAR) + "_" + calendar.get(Calendar.MONTH) + "_" + calendar.get(Calendar.DAY_OF_MONTH) +
       "_" + calendar.get(Calendar.HOUR_OF_DAY) + "_" + calendar.get(Calendar.MINUTE) + "_" + calendar.get(Calendar.SECOND);
     fos = new FileOutputStream(dir + "/" + FileName + ".jpg");
     bm.compress(CompressFormat.JPEG, 100, fos);
     MapCapturePath = dir + "/" + FileName + ".jpg";
     Toast.makeText(map2test.this, "캡쳐된 파일 이름 : " + FileName + ".jpg", Toast.LENGTH_SHORT).show();
    } catch (FileNotFoundException e) {
     
     e.printStackTrace();
    }

이렇게 했는데 검정화면에 +,- 이 표시만 나오고 지도부분은 검정화면 나오네요

실행하면 지도는 잘보입니다

폰에서 바로 종료키와 홈키를 눌러서 캡쳐하면 전체 화면이 캡쳐되면서 보이더라구요

혹시 종료키와 홈키를 누를때처럼 그 기능을 바로 불러와서 쓸수 있는 방법도 있나요??

소스로

View v1 = this.mapView.getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
이런식으로 제일 위에 뷰를 가져와서 캡쳐해도 똑같던데 ㅠ.ㅠ

 

김기훈 (390 포인트) 님이 2013년 2월 18일 질문
김기훈님이 2013년 2월 18일 수정

1개의 답변

0 추천
제가알기론 뷰마다 drawingcache를 설정할수 있다고 압니다...

그니까 mapview도 다시 setDrawingCacheEnabled()해보세요...
수상한i (8,050 포인트) 님이 2013년 2월 26일 답변
...