1

我已经尝试了@ Tarsem 的答案,但是发生了致命错误我可以知道为什么吗?@Tarsem答案: https : //stackoverflow.com/a/18308611/2398886

<--- 这些是我在 Eclipse 中的错误代码:--->

08-21 18:52:23.399: W/dalvikvm(29376): threadid=1: thread exiting with uncaught exception (group=0x40018578)

08-21 18:52:23.409: E/AndroidRuntime(29376): FATAL EXCEPTION: main

08-21 18:52:23.409: E/AndroidRuntime(29376): java.lang.NoClassDefFoundError: com.example.testing01.MainActivity2$6

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2.CaptureMapScreen(MainActivity2.java:410)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.example.testing01.MainActivity2$3.onClick(MainActivity2.java:182)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View.performClick(View.java:2485)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.view.View$PerformClick.run(View.java:9080)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.handleCallback(Handler.java:587)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Handler.dispatchMessage(Handler.java:92)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.os.Looper.loop(Looper.java:130)

08-21 18:52:23.409: E/AndroidRuntime(29376): at android.app.ActivityThread.main(ActivityThread.java:3687)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invokeNative(Native Method)

08-21 18:52:23.409: E/AndroidRuntime(29376): at java.lang.reflect.Method.invoke(Method.java:507)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:867)

08-21 18:52:23.409: E/AndroidRuntime(29376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

08-21 18:52:23.409: E/AndroidRuntime(29376): at dalvik.system.NativeStart.main(Native Method)

<--- 这些是我在 Eclipse 中的错误代码:--->

这些是我的编码,是我的编码有什么错误吗?

public void CaptureMapScreen() 
 {
 SnapshotReadyCallback callback = new SnapshotReadyCallback() {
             Bitmap bitmap;

             @Override
             public void onSnapshotReady(Bitmap snapshot) {
                 // TODO Auto-generated method stub
                 bitmap = snapshot;
                 try {
                     FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                         + "MyMapScreen" + System.currentTimeMillis()
                         + ".png");

                     // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

                     bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
             }
         };

         map.snapshot(callback);

         // myMap is object of GoogleMap +> GoogleMap myMap;
         // which is initialized in onCreate() => 
         // myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
 }

我的停止按钮功能:

//End Button Function
 Button timerStopButton = (Button) findViewById(R.id.btnTimerStop);      
 timerStopButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view){          

            String latitude3=Double.toString(latitude1);
            String latitude4=Double.toString(latitude2);
            String longitude3=Double.toString(longitude1);
            String longitude4=Double.toString(longitude2);
            String Kcalories=String.format("%.2f", calories);

            Intent intent = new Intent(view.getContext(),NewDataActivity.class);
            intent.putExtra("lat1", latitude3);
            intent.putExtra("lat2", latitude4);
            intent.putExtra("long1", longitude3);
            intent.putExtra("long2", longitude4);
            intent.putExtra("timer", timerStop1);
            intent.putExtra("distance", distance2 + " m");
            intent.putExtra("Ccalories", Kcalories + " kcal");
            Toast.makeText(getApplicationContext(), "Calories (kcal):" + Kcalories, Toast.LENGTH_LONG).show();
            startActivity(intent);                                          

            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            //kill task timer and other 
            int pid = android.os.Process.myPid();
            android.os.Process.killProcess(pid);
        }                

 });

是我的编码有任何错误还是我的逻辑有任何问题?谁能帮我?谢谢 :)

4

1 回答 1

1

注意您捕获地图屏幕的代码是正确的,如果您仍然感到困惑,那么

请确保以下每个步骤:-

以下是通过示例捕获 Google Map V2 屏幕截图的步骤

步骤 1.打开Android Sdk Manager (Window > Android Sdk Manager)然后Expand Extras现在update/install Google Play Services to Revision 10忽略此步骤(如果已经)installed

在此处阅读注释https://developers.google.com/maps/documentation/android/releases#august_2013

第2步。 Restart Eclipse

步骤 3。 import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;

步骤 4. 制作方法来捕获/存储地图的屏幕/图像,如下所示

public void CaptureMapScreen() 
{
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
            Bitmap bitmap;

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                // TODO Auto-generated method stub
                bitmap = snapshot;
                try {
                    FileOutputStream out = new FileOutputStream("/mnt/sdcard/"
                        + "MyMapScreen" + System.currentTimeMillis()
                        + ".png");

                    // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can customize as per your Requirement

                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        myMap.snapshot(callback);

        // myMap is object of GoogleMap +> GoogleMap myMap;
        // which is initialized in onCreate() => 
        // myMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_pass_home_call)).getMap();
}

第 5 步。CaptureMapScreen()现在在要捕获图像的位置调用此方法

就我而言,我calling this method on Button click in my onCreate()工作正常

喜欢:

Button btnCap = (Button) findViewById(R.id.btnTakeScreenshot);
    btnCap.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                CaptureMapScreen();
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }

        }
    });

在这里这里检查文档

于 2013-08-21T13:49:31.507 回答