2014-03-06 2 views
0
void SaveScreenshot() 
{ 
    CCSize size = CCDirector::sharedDirector()->getWinSize(); 
    CCRenderTexture* texture = CCRenderTexture::create((int)size.width, (int)size.height);  
    texture->setPosition(ccp(size.width/2, size.height/2));  
    texture->begin(); 
    CCDirector::sharedDirector()->getRunningScene()->visit(); 
    texture->end(); 
    texture->saveToFile("screenshot.png", kCCImageFormatPNG); 
} 

android에서 네이티브 java로 스크린 샷에 액세스하려면 어떻게해야합니까?
보내기 의도에 대한 선택기를 만들고 싶지만 cocos2dx saveToFile() ..에 도움이되는 디렉터리를 찾을 수없는 것 같습니다.스크린 샷 저장 cocos2d-x android

+0

질문을 자세히 설명해 주시겠습니까? –

+0

중단 점을 설정 한 다음 저장 방법으로 이동하십시오. – LearnCocos2D

+0

@SumitKandoi saveToFile()이 쓰는 디렉토리는 무엇입니까? – GameDevGuru

답변

3

스크린 샷 이미지를 생성 할 Java 메소드를 호출해야합니다.

public static void ScreenShot() 
    { 
     Bitmap imageBitmap = BitmapFactory.decodeFile(Cocos2dxHelper.getCocos2dxWritablePath() + "/" + "screenshot.png"); 

     String fileHolder = "SampleFolder"; 
     File filepathData = new File("/sdcard/" + fileHolder); 

     //~~~Create Dir 
     try { 
       if (!filepathData.exists()) 
       { 
        filepathData.mkdirs(); 
        filepathData.createNewFile(); 

        FileWriter fw = new FileWriter(filepathData + fileHolder); 
        BufferedWriter out = new BufferedWriter(fw); 
        String toSave = String.valueOf(0); 
        out.write(toSave); 
        out.close(); 
       } 
      } 
      catch (IOException e1) { 

      } 

      //~~~Create Image 
      File file = new File("/sdcard/" + "Your filename"); 

      try 
      { 
       file.createNewFile(); 
       FileOutputStream ostream = new FileOutputStream(file); 
       imageBitmap.compress(CompressFormat.PNG, 100, ostream); 
       ostream.close(); 
      } 
      catch (Exception e) {} 

      Uri phototUri = Uri.fromFile(file); 
      Intent shareIntent = new Intent(); 
      shareIntent.setAction(Intent.ACTION_SEND); 
      shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri); 
      //~~~Add Code Below 
    } 
+0

유망 해 보였지만 filepathData는 읽기 전용 파일 시스템입니다.'java.io.IOException : 읽기 전용 파일 시스템 ' – GameDevGuru

+0

@GameDevGuru sd card wripe permission이 있습니까? –