基于xmpp openfire smack 开发(三)群聊发送图片

1、Activity

case TAKE_PHOTO:
			if (arg2 != null) {
				Bitmap one = null;
				Uri photoUri = arg2.getData(); 
				Bundle extra = arg2.getExtras();  
		        if (extra != null) {  
		        	one = (Bitmap)extra.get("data");
		        }
			    iv3.setImageBitmap(one);
			    SecureRandom random = new SecureRandom();  
			    String picPath = Util.saveBitmap(""+random.nextInt(10000), one);
	            semdrommessage(picPath.trim(), Content.DaTingSERVICE_Home
						+ "@conference." + Content.DaTingSERVICE_Name);
			}
			break;

2、工具,保存图片到地址

	public static String saveBitmap(String name, Bitmap bitmap) {
		File oneFile = new File(Content.APP_PATH + File.separator + name
				+ ".png");
		if (oneFile.exists())
			oneFile.delete();
		try {
			oneFile.createNewFile();
			FileOutputStream stream = new FileOutputStream(oneFile);
			bitmap.compress(CompressFormat.JPEG, 100, stream);
			stream.flush();
			stream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return oneFile.toString();
	}

3、Adapter 

if (entity.getText().contains(".png")) {
			viewHolder.tvContent.setText("");
			ImageSpan imageSpan = new ImageSpan(ctx,Util.getDiskBitmap(entity.getText())); 
            SpannableString spannableStringTuPian = new SpannableString("pp");   //这个pp不能删,必须有任意字符串,否则报错
            spannableStringTuPian.setSpan(imageSpan, 0, spannableStringTuPian.length(),  
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
            viewHolder.tvContent.setText(spannableStringTuPian);
		} else {
			viewHolder.tvContent.setText(spannableString);
		}
4、转本地为Bitmap

if (entity.getText().contains(".png")) {
			viewHolder.tvContent.setText("");
			ImageSpan imageSpan = new ImageSpan(ctx,Util.getDiskBitmap(entity.getText())); 
            SpannableString spannableStringTuPian = new SpannableString("pp"); 
            spannableStringTuPian.setSpan(imageSpan, 0, spannableStringTuPian.length(),  
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 
            viewHolder.tvContent.setText(spannableStringTuPian);
		} else {
			viewHolder.tvContent.setText(spannableString);
		}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值