简体   繁体   English

从sdcard android显示jpg

[英]Display jpg from sdcard android

I cant get this to work anymore 我不能让它工作了

Here is my code: 这是我的代码:

ImageView jpgView = (ImageView)findViewById(R.id.ImageView01);
    String myJpgPath = "/sdcard/pic.jpg";              

    jpgView.setVisibility(View.VISIBLE);
    //jpgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    jpgView.setAdjustViewBounds(true);


  BitmapFactory.Options options = new BitmapFactory.Options();  
  options.inSampleSize = 2;
  Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
  jpgView.setImageBitmap(bm);

Can anyone help? 有人可以帮忙吗?

You can just use bitmapdrawable, eg 您可以只使用bitmapdrawable,例如

ImageView jpgView = (ImageView)findViewById(R.id.ImageView01);
String myJpgPath = "/sdcard/pic.jpg";
BitmapDrawable d = new BitmapDrawable(getResources(), myJpgPath);
jpgView.setImageDrawable(d);

The image won't be shown if you open the emulator directly from the eclipse, by clicking run. 如果直接从Eclipse中打开运行模拟器(单击运行),则不会显示该图像。 You'll be able to access the SD card if you start the emulator using the command line, then click your app on the emulator. 如果使用命令行启动仿真器,然后在仿真器上单击您的应用程序,则可以访问SD卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM