图片上传、显示网络图片、相册选取、拍照选取、图片裁剪

来源:互联网 发布:域名能干什么 编辑:程序博客网 时间:2024/05/18 03:51

左右滑动倒影:http://blog.csdn.net/ryantang03/article/details/8053643

显示网络图片:http://www.cnblogs.com/dyllove98/p/3191916.html

http子线程下显示图片:http://bbs.9ria.com/thread-232411-1-1.html

上传图片(含照像、从SD卡选取、裁剪等):

http://blog.csdn.net/liangjiu2009/article/details/18978891

http://blog.csdn.net/ryantang03/article/details/8656278



————————————————华丽丽的分割线————————————————————————————


主线程显示网络图片:

public static Bitmap GetInternetBitMap(String _url) {StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());Bitmap bitmap = null;try{HttpURLConnection conn = (HttpURLConnection)(new URL(_url).openConnection());conn.connect();if(conn.getResponseCode()==200){InputStream input = conn.getInputStream();bitmap = BitmapFactory.decodeStream(input);input.close();}}catch(Exception e){e.printStackTrace();}return bitmap;    }

子线程显示网络图片:

public static void GetHttpBitMap(final String url,final Handler handle,final boolean timeout) {new Thread(){@Overridepublic void run() {  try {      DefaultHttpClient dhc = new DefaultHttpClient();    if(timeout){    dhc.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000); //请求超时时间    dhc.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 2000); //等待数据时间    }            handle.obtainMessage(1,BitmapFactory.decodeStream(dhc.execute(new HttpGet(url)).getEntity().getContent())).sendToTarget();    }catch (Exception e) { handle.obtainMessage(0,"服务器出错,请稍候重试!").sendToTarget();}}}.start();    }

需要权限:

<uses-permission android:name="android.permission.INTERNET" />

————————————————华丽丽的分割线————————————————————————————


让HTML5支持上传图片(android版本兼容性差):

http://www.android100.org/html/201306/28/3325.html

http://sinykk.iteye.com/blog/1493580

http://www.tuicool.com/articles/buu6ji


————————————————华丽丽的分割线————————————————————————————


本地上传图片正常,发布版点击图片上传没反映?

解决:“代码混淆”功能导致的问题,需在proguard-project.txt中加入:

-keepclassmembers class * extends android.webkit.WebChromeClient {public void openFileChooser(...);}

该解决方法出自:http://stackoverflow.com/questions/5907369/file-upload-in-webview

0 0