当初报修功能,没有完全完成,因为当时报修时候提交图片接口没有写好,现在写好了,返回图片部分由我来完成。
这是最开始的版本,取出图片的方法然后显示出来是我从网上找到的方法。
贴出来给大家学习下
public class ImageShow extends Activity { private ImageView iv; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); iv=(ImageView)findViewById(R.id.iv_photo); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); Intent data = getIntent(); final String img_src=data.getStringExtra("img_src"); Bitmap bitmap = null; try { bitmap = getBitmap(img_src); iv.setImageBitmap(bitmap); } catch (IOException e) { e.printStackTrace(); } } public Bitmap getBitmap(String path) throws IOException { try { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == 200) { InputStream inputStream = conn.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } } catch (IOException e) { e.printStackTrace(); } return null; } public void onBack(View view){ finish(); } }
最开始我获得图片URL是动态生成的,然后图片也是自适应,这就显得图片有点大
后来我就给图片限制了尺寸,然后就不是动态生成ImageView了,而是来判断,因为最多可以上传三张图片,有时候可以上传一张或者两张,然后判断点击事件,点击图片是可以进去到页面来吧图片放大的额。