1

我尝试开发的应用程序有一点问题。这只是一个小相机应用程序。

这就是我想要做的:...拍照并保存。开始另一个活动,在图片视图中加载图片(因此我保存图片路径,因此我可以使用 BitmapFactory.decodeFile(picutrepath) 加载/创建 bmp)...

但这不起作用。屏幕变黑,甚至没有加载 xml。我总是收到一个 System.out 说“不是正常打开的 drm 文件”,但我不知道这是否与我尝试通过 BitmapFactory 加载图片有关。我使用 Log.i 查看我使用的路径是否有问题,但一切都很好。所以我决定尝试是否可以从我的 R.drawables 加载一个简单的 .png 图像,但这也不起作用。奇怪的是,在屏幕变黑后,应用程序只是退出/退出而没有错误。

希望有人可以帮助我,谢谢:)

这是代码:

我如何开始我的第二个活动:

.
.
.
takepictureButton = (ImageButton) findViewById(R.id.cameralayout_takepictureButton);
        takepictureButton.setOnClickListener(new ImageButton.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                camera.takePicture(shutterCallback, rawCallback, jpgCallback);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Log.i("", "Starting INTENT");
                intentstart();

            }
        });
.
.
.
private void intentstart() {
        // TODO Auto-generated method stub
        Intent intent = new Intent(this, FacebarActivity.class);
        startActivity(intent);

    }
.
.
.

我想开始的活动:

public class FacebarActivity extends Activity {

    private ImageView imageview;
    private ImageButton cButton, xButton;
    private Bitmap picture;

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pictureview);

    ImageView imageview = (ImageView) findViewById(R.id.pictureviewLayout_pictureView);

    picture = BitmapFactory.decodeResource(getResources(),
            R.drawable.buttonplay);
    imageview.setImageBitmap(picture);

    cButton = (ImageButton) findViewById(R.id.pictureviewLayout_CButton);
    cButton.setOnClickListener(new ImageButton.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });
    XButton = (ImageButton) findViewById(R.id.pictureviewLayout_XButton);
    XButton.setOnClickListener(new ImageButton.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });
    startthis();

}

还有我用 setContentView() 加载的 pictureview.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".CameraActivity" >

<RelativeLayout
    android:id="@+id/pictureviewLayout_topbarlinearlayout"
    android:layout_width="fill_parent"
    android:layout_height="75dp"
    android:layout_alignParentTop="true"
    android:background="@drawable/topbar" >
</RelativeLayout>

<ImageView
    android:id="@+id/pictureviewLayout_pictureView"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/pictureviewLayout_bottombarlinearlayout"
    android:layout_below="@+id/pictureviewLayout_topbarlinearlayout" />

<RelativeLayout
    android:id="@+id/pictureviewLayout_bottombarlinearlayout"
    android:layout_width="fill_parent"
    android:layout_height="75dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/bottombar" >

    <ImageButton
        android:id="@+id/pictureviewLayout_CButton"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/pictureviewLayout_XButton"
        android:layout_centerHorizontal="true"
        android:background="@android:color/transparent"
        android:src="@android:drawable/ic_menu_camera" />

    <ImageButton
        android:id="@+id/pictureviewLayout_XButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginRight="24dp"
        android:layout_toLeftOf="@+id/pictureviewLayout_CButton"
        android:background="@android:color/transparent"
        android:src="@android:drawable/ic_notification_clear_all" />
</RelativeLayout>

和日志猫:

01-23 20:47:00.995: D/dalvikvm(7776): GC_FOR_ALLOC freed 69K, 6% free 12160K/12931K, paused 18ms, total 19ms
01-23 20:47:00.995: I/dalvikvm-heap(7776): Grow heap (frag case) to 12.841MB for 432016-byte allocation
01-23 20:47:01.020: D/dalvikvm(7776): GC_CONCURRENT freed <1K, 6% free 12581K/13383K, paused 12ms+1ms, total 25ms
01-23 20:47:01.055: D/dalvikvm(7776): GC_FOR_ALLOC freed 0K, 6% free 12581K/13383K, paused 18ms, total 18ms
01-23 20:47:01.055: I/dalvikvm-heap(7776): Grow heap (frag case) to 13.573MB for 768016-byte allocation
01-23 20:47:01.085: D/dalvikvm(7776): GC_CONCURRENT freed 0K, 6% free 13331K/14151K, paused 12ms+2ms, total 27ms
01-23 20:47:01.085: D/dalvikvm(7776): WAIT_FOR_CONCURRENT_GC blocked 11ms
01-23 20:47:01.105: D/dalvikvm(7776): GC_FOR_ALLOC freed 424K, 9% free 12913K/14151K, paused 14ms, total 14ms
01-23 20:47:01.120: D/dalvikvm(7776): GC_CONCURRENT freed <1K, 6% free 13335K/14151K, paused 2ms+1ms, total 18ms
01-23 20:47:01.120: D/dalvikvm(7776): WAIT_FOR_CONCURRENT_GC blocked 2ms
01-23 20:47:01.140: D/dalvikvm(7776): GC_FOR_ALLOC freed 0K, 6% free 13335K/14151K, paused 20ms, total 20ms
01-23 20:47:01.145: I/dalvikvm-heap(7776): Grow heap (frag case) to 14.309MB for 768016-byte allocation
01-23 20:47:01.160: D/dalvikvm(7776): GC_CONCURRENT freed 0K, 6% free 14085K/14919K, paused 3ms+1ms, total 19ms
01-23 20:47:01.330: D/libEGL(7776): loaded /system/lib/egl/libEGL_mali.so
01-23 20:47:01.355: D/libEGL(7776): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-23 20:47:01.355: D/libEGL(7776): loaded /system/lib/egl/libGLESv2_mali.so
01-23 20:47:01.380: D/(7776): Device driver API match
01-23 20:47:01.380: D/(7776): Device driver API version: 10
01-23 20:47:01.380: D/(7776): User space API version: 10 
01-23 20:47:01.380: D/(7776): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 
01-23 20:47:01.440: D/OpenGLRenderer(7776): Enabling debug mode 0
01-23 20:47:02.040: I/Choreographer(7776): Skipped 46 frames!  The application may be doing too much work on its main thread.
01-23 20:47:09.230: I/APPLICATION(7776): STARTIng INTENT
01-23 20:47:09.235: I/Kurz bevor(7776): null
01-23 20:47:09.290: I/APPLICATION(7776): STARTED INTENT
01-23 20:47:09.290: I/Choreographer(7776): Skipped 308 frames!  The application may be doing too much work on its main thread.
01-23 20:47:09.605: D/dalvikvm(7776): GC_CONCURRENT freed 836K, 10% free 13905K/15367K, paused 1ms+2ms, total 12ms
01-23 20:47:09.605: D/dalvikvm(7776): WAIT_FOR_CONCURRENT_GC blocked 4ms
4

0 回答 0