toast显示图片
//是图片直接显示 if (isImageFile(fileName)) { Toast toast = Toast.makeText(context, "预览", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout ToastContentView = (LinearLayout) toast.getView(); ImageView img = new ImageView(context); img.setImageBitmap(BitmapFactory.decodeFile(fileName)); ToastContentView.addView(img); toast.show();}
/** * 判断一个文件是否是图片文件的方法 * @param filePath * @return */ public static boolean isImageFile(String filePath) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); if (options.outWidth == -1) { return false; } return true; }