在Android中从内部内存中读取图像

Sai*_*ker 1 android android-image

我已将图像保存在内存中.例如,我将其保存为test.jpg.现在我想在imageview中显示它.我试过这个:

ImageView img = (ImageView)findViewById(R.id.imageView1);
try {                       
    img.setImageDrawable(Drawable.createFromPath("test.jpg"));                 
} catch (Exception e) {
    Log.e(e.toString());
}
Run Code Online (Sandbox Code Playgroud)

并在LogCat中获取以下消息:

SD卡可用于读写truetrue

有任何帮助或参考吗?

Nik*_*ddy 5

public class AndroidBitmap extends Activity {

private final String imageInSD = "/sdcard/er.PNG";

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

      Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
      ImageView myImageView = (ImageView)findViewById(R.id.imageview);
      myImageView.setImageBitmap(bitmap);

  }
}
Run Code Online (Sandbox Code Playgroud)

要么

    final Bitmap bm = BitmapFactory.decodeStream( ..some image.. ); 
// The openfileOutput() method creates a file on the phone/internal storage in the context of your application 
final FileOutputStream fos = openFileOutput("my_new_image.jpg", Context.MODE_PRIVATE); // Use the compress method on the BitMap object to write image to the OutputStream 
bm.compress(CompressFormat.JPEG, 90, fos);
Run Code Online (Sandbox Code Playgroud)

希望它有效......