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);
}