public class ImagActivity extends Activity {
AssetManager assetManager=null;
String []dec;
int currentImg=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imag);
final Button button=(Button)findViewById(R.id.imagButton);
final ImageView imgBig=(ImageView)findViewById(R.id.imgBig);
try
{
assetManager=getAssets();
dec=assetManager.list("");
}catch (IOException e){
e.printStackTrace();
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
InputStream inputStream=null;
currentImg=(++currentImg)%dec.length;
while(!dec[currentImg].endsWith(".jpg")) {
currentImg=(++currentImg)%dec.length;
}
try{
inputStream=assetManager.open(dec[currentImg]);
}catch (IOException e){
e.printStackTrace();
}
BitmapDrawable ibitmapDrawable=(BitmapDrawable)imgBig.getDrawable();
if(ibitmapDrawable!=null&&!bitmapDrawablep.getBitmap().isRecycled()) {
Bitmap bitmapTmp=ibitmapDrawable.getBitmap();
// bitmapTmp.recycle();
bitmapTmp=null;
}
imgBig.setImageBitmap(BitmapFactory.decodeStream(inputStream));
if(inputStream!=null){
try{
inputStream.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
assets目录图片查看器
最新推荐文章于 2021-07-02 17:47:14 发布