0

Android カメラで写真を撮ると、写真と一緒imageview3に保存したい画像 ( ) が画面に表示されます。

これが私のonPictureTaken方法です

public void onPictureTaken(byte[] data, Camera camera) {
    File imagesFolder = new File(Environment.getExternalStorageDirectory(), "/Ker");
    imagesFolder.mkdirs();
    String fileName = "Ker_.jpg";
    output = new File(imagesFolder, fileName);
    ImageView view = (ImageView) gameactivity.findViewById(R.id.imageView3);
    view.setDrawingCacheEnabled(true);
    Bitmap b = view.getDrawingCache();
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(output);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
    b.compress(CompressFormat.JPEG, 95, fos);
    try {
        fos.write(data);
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
        catch (IOException e) {
        e.printStackTrace();
    }
    camera.stopPreview();
}

imageview3フォルダを開くと、背景が黒の画像しか保存されません。実際のカメラ ビューが保存されていないのはなぜですか?

編集 キャンバスでも何かを試しています:

output = new File(imagesFolder, fileName);
            ImageView view = (ImageView) gameactivity.findViewById(R.id.imageView3);
            view.setDrawingCacheEnabled(true);
            Bitmap b = view.getDrawingCache();   
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(output);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
              catch (IOException e) {
                    e.printStackTrace();
            }
            FileOutputStream fos2 = null;
            b.compress(CompressFormat.JPEG, 95, fos2);

            try {
                Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fos.getFD());
                Bitmap bitmap2 = BitmapFactory.decodeFileDescriptor(fos2.getFD());
                Canvas canvas = new Canvas(bitmap);
                canvas.drawBitmap(bitmap2, null, null);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

あれは正しいですか?キャンバスを SD カードのファイルに保存する方法 (つまり、ファイル出力ストリームにキャンバスからデータを書き込む)

4

1 に答える 1

0

imageview の JPEG とカメラからの JPEG を 1 つのファイルに追加しています。

ファイルごとに個別のファイル出力ストリームを作成し、Bitmap.compress() および onPictureTaken データ配列からのデータを独自のストリームに書き込みます。

2 つの画像を 1 つの画像に結合する場合は、データ配列をビットマップにデコードし、Canvas を使用して、ImageView ビットマップとカメラでキャプチャしたビットマップをキャンバス上に配置して描画する必要があります。したいし、それを 1 つの jpeg として保存します。

圧縮された 2 つの JPEG ビットストリームを単純に連結することはできません。ファイル形式はそのようには機能しません。

于 2013-02-06T00:14:08.247 に答える