0

重複の可能性:
アクティビティからのカメラの呼び出し、画像のキャプチャ、サーバーへのアップロード

これが私がインターネットで入手したコードです:

package com.android.imageuploader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.android.imageuploader.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageUploaderActivity extends Activity {
    private static final int REQUEST_CODE = 1;
    private Button button_1;
    public int TAKE_PICTURE = 1;
    private ImageView image_view;
    private Bitmap bitmap;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        image_view = (ImageView) findViewById(R.id.result);
        button_1 = (Button) findViewById(R.id.button1);

        button_1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, TAKE_PICTURE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
            try {
                // We need to recyle unused bitmaps
                if (bitmap != null) {
                    bitmap.recycle();
                }
                InputStream stream = getContentResolver().openInputStream(
                        data.getData());
                bitmap = BitmapFactory.decodeStream(stream);
                stream.close();
                image_view.setImageBitmap(bitmap);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        super.onActivityResult(requestCode, resultCode, data);
    }
}

これはボタンとimageView(最初はデフォルトの画像を含む)を示しており、ボタンをクリックするとギャラリーに移動し、画像をクリックすると画像がimageViewに与えられます。ここで 2 つの質問があります。1. ボタンでカメラに移動する方法と、画像をキャプチャしたときに 2. Web サーバーに直接アップロードする方法

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="pickImage"
        android:text="Button" >
    </Button>

    <ImageView
        android:id="@+id/result"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/wic_logo_small" >
    </ImageView>

</LinearLayout>
4

1 に答える 1

3

ユーザーがボタンをクリックすると、意図的にカメラを開く必要があります。

    public int TAKE_PICTURE =1
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent, TAKE_PICTURE);

onactivityresultでは、カメラからキャプチャした画像を取得します。

次に、その画像をサーバーにアップロードする必要があります

plzは次のURLを通過します

Androidの投稿Base64文字列からPHP

于 2012-05-19T06:55:42.683 に答える