开发者

Display jpg from sdcard android

开发者 https://www.devze.com 2023-01-24 23:49 出处:网络
I cant get th开发者_开发技巧is to work anymore Here is my code: ImageView jpgView = (ImageView)findViewById(R.id.ImageView01);

I cant get th开发者_开发技巧is 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, e.g.

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. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消