微信上传图片问题
2016-01-26 12:11
555 查看
最近做了微信上传图片,果断把大神的demo拷了过来,后来发现上传的时候出现了几个问题,那个博客下老是提醒链接过多,评论不了,就搬到这了
———首先先贴大神的demo地址:http://blog.csdn.net/jdsjlzx/article/details/44160603#html1.
获取的图片就是null,尤其是拍照的,我就把那个FileUtil那个存储bitmap的方法给返回了一个路径,然后就好了,下面是照相机返回的路径
[code]//照相机 public void photo() { Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(openCameraIntent, TAKE_PICTURE); } //照相机返回的图片 protected void onActivityResult(int requestCode, int resultCode, final Intent data) { switch (requestCode) { case TAKE_PICTURE: if (Bimp.tempSelectBitmap.size() < 9 && resultCode == RESULT_OK) { new Thread(new Runnable() { @Override public void run() { String fileName = String.valueOf(System.currentTimeMillis() + ".png"); Bitmap bm = (Bitmap) data.getExtras().get("data"); String path = FileUtils.saveBitmap(bm, fileName); ImageItem takePhoto = new ImageItem(); takePhoto.setBitmap(bm); takePhoto.setImagePath(path); Bimp.tempSelectBitmap.add(takePhoto); } }).start(); } break; } }
——–Fileutil中return SDPATH + picName;就可以了,办法有点笨,但是不出错
2.在GridAdapter中的update()方法中,要么给loading()中的else后面添加break;要么改成adapter.notifyDataSetChanged();
之后就不会出现oom,并且导致时不时点不了的情况了
[code] //所选图片适配 @SuppressLint("HandlerLeak") public class GridAdapter extends BaseAdapter { private LayoutInflater inflater; private int selectedPosition = -1; private boolean shape; public boolean isShape() { return shape; } public void setShape(boolean shape) { this.shape = shape; } public GridAdapter(Context context) { inflater = LayoutInflater.from(context); } public void update() { // loading(); adapter.notifyDataSetChanged(); } public int getCount() { if (Bimp.tempSelectBitmap.size() == 9) {//最多选9张图片 return 9; } return (Bimp.tempSelectBitmap.size() + 1); } public Object getItem(int arg0) { return null; } public long getItemId(int arg0) { return 0; } public void setSelectedPosition(int position) { selectedPosition = position; } public int getSelectedPosition() { return selectedPosition; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = inflater.inflate(R.layout.item_upload_gridview, parent, false); holder = new ViewHolder(); holder.image = (ImageView) convertView .findViewById(R.id.item_grida_image); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (Bimp.tempSelectBitmap != null) { if (position == Bimp.tempSelectBitmap.size()) { holder.image.setImageBitmap(BitmapFactory.decodeResource( getResources(), R.mipmap.ic_add_img));//加号 if (position == 9) {//只能选9张图片 holder.image.setVisibility(View.GONE); } } else { holder.image.setImageBitmap(Bimp.tempSelectBitmap.get(position).getBitmap()); imagePath = Bimp.tempSelectBitmap.get(position).getImagePath();//这是相册选中的图片路径,大神有说的 map.put(position, imagePath); System.out.println("list选中上传的集合---" + map.size()); System.out.println("list选中上传的集合Path---" + map.get(position)); } } return convertView; } public class ViewHolder { public ImageView image; } Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case 1: adapter.notifyDataSetChanged(); break; } super.handleMessage(msg); } }; //添加break,就可以调用 public void loading() { new Thread(new Runnable() { public void run() { while (true) { if (Bimp.max == Bimp.tempSelectBitmap.size()) { Message message = new Message(); message.what = 1; handler.sendMessage(message); break; } else { Bimp.max += 1; Message message = new Message(); message.what = 1; handler.sendMessage(message); break;//在这添加 } } } }).start(); } }
相关文章推荐
- php 简单判断是否微信浏览器
- PHP微信开发代码
- Android RichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)
- 【解决方案】谈公众号红包的正确打开方式--传奇创世
- 微信扫码支付 curl出错,错误码:28
- 1秒被抢完的那3000个QQ公众号,这四个月发展得怎样
- 我的微信
- iOS微信支付_第一节_申请(从申请到集成)
- iOS微信支付_第二节_企业资料进行审核(从申请到集成)
- 微信公众号的一些事
- 微信JS-SDK说明文档
- JS判断是否微信浏览器
- AndroidRichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)
- 微信抢红包软件说明
- 微信支付太坑了
- ios微信修改title
- APP创业者必知的H5、微信开发、APP优缺点分析
- 【箭扣观点】企业类微信,这次能“钉”上吗?
- 微信企业号红包提交签名错误解决
- 微信公众平台开发(PHP) 数据库操作