0

重複の可能性:
カメラから画像をキャプチャしてアクティビティで表示

私はAndroidプログラミングに不慣れで、いくつかの問題が発生しています。ImageViewがあります。画像がロードされていません。カメラで写真を撮ると、キャプチャされた画像がImageViewに入れられます。これを保存したいのですが、写真のディレクトリを文字列で保存する方法と、「onCreate」のimageViewにこのディレクトリをロードする方法がわかりません。

私はこれが初心者の手がかりであることを知っていますが、これは私がこのようなものを使うのは初めてです。

ありがとう

4

2 に答える 2

0

このコードは、ImageView をビットマップとして取得します。

ImageView imgView = (ImageView) findViewById(R.id.myImageView);
imgView.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(imgView.getDrawingCache());

File root = Environment.getExternalStorageDirectory();
File cachePath = new File(root.getAbsolutePath() + "/your_app_package/image.png");

このコードはそれをファイルに保存します

try {
       FileOutputStream out = new FileOutputStream(cachePath);
       bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
       e.printStackTrace();
}
于 2012-05-15T09:28:23.967 に答える
0

私はこのようなことをしています:

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
picture.compress(Bitmap.CompressFormat.JPEG, 80, bytes);


File f = new File(Environment.getExternalStorageDirectory() + File.separator + picId + ".jpg");
FileOutputStream fo = null;
try 
{
    f.createNewFile();
    fo = new FileOutputStream(f);
} 
catch (IOException e) 
{
    e.printStackTrace();
}
catch (FileNotFoundException e) 
{
    e.printStackTrace();
}


try 
{
    fo.write(bytes.toByteArray());
} 
catch (IOException e) 
{
    e.printStackTrace();
}

...ここで、picId はファイルの名前です。

于 2012-05-15T09:29:08.963 に答える