77
Bimp.tempSelectMedia.clear();
}
private String bitmapToBase64(Bitmap bitmap) {
String result = null;
ByteArrayOutputStream baos = null;
try {
if (bitmap != null) {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
baos.flush();
baos.close();
byte[] bitmapBytes = baos.toByteArray();
result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (baos != null) {
baos.flush();
baos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
private Bitmap imageZoom(Bitmap bm) {
// 图片允许最大空间 单位:KB
double maxSize = 200.00;
// 将bitmap放至数组中,意在bitmap的大小(与实际读取的原文件要大)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
// 将字节换成KB
double mid = b.length / 1024;
// 判断bitmap占用空间是否大于允许最大空间 如果大于则压缩 小于则不压缩
if (mid > maxSize) {
// 获取bitmap大小 是允许最大大小的多少倍
double i = mid / maxSize;
// 开始压缩 此处用到平方根 将宽带和高度压缩掉对应的平方根倍
// (1.保持刻度和高度和原bitmap比率一致,压缩后也达到了最大大小占用空间的大小)
bm = zoomImage(bm, bm.getWidth() / Math.sqrt(i), bm.getHeight()
/ Math.sqrt(i));
}
return bm;
}
public Bitmap zoomImage(Bitmap bgimage, double newWidth, double newHeight) {
// 获取这个图片的宽和高
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight);
Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
(int) height, matrix, true);
// iv_2.setImageBitmap(bitmap);
// tv_2.setText(bitmap.getRowBytes() * bitmap.getHeight() + "");
return bitmap;
}
class NetworkChangeReceiver extends BroadcastReceiver {
@ -904,12 +1203,12 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
}
mAdapter.notifyDataSetChanged();
if (mInsterType == 1 && mAdapter.getItemCount() == 1){
if (mInsterType == 1 && mAdapter.getItemCount() == 1) {
setLayoutHintVisible(-1);
mInsterType=-1;
}else if (mInsterType == 2 && mAdapter.getItemCount() == 0){
mInsterType = -1;
} else if (mInsterType == 2 && mAdapter.getItemCount() == 0) {
setLayoutHintVisible(-1);
mInsterType=-1;
mInsterType = -1;
}
}
@ -944,4 +1243,38 @@ public class ZhanCommentActivity extends AppCompatActivity implements View.OnCli
&& (codePoint <= 0x10FFFF));
}
/**
* 将json 数组转换为Map 对象
*
* @param jsonString
* @return
*/
public static Map<String, Object> getMap(String jsonString) {
JSONObject jsonObject;
Map<String, Object> valueMap = new HashMap<String, Object>();
if (TextUtils.isEmpty(jsonString)) {
return valueMap;
}
try {
jsonObject = new JSONObject(jsonString);
@SuppressWarnings("unchecked")
Iterator<String> keyIter = jsonObject.keys();
String key;
Object value;
while (keyIter.hasNext()) {
key = (String) keyIter.next();
value = jsonObject.get(key);
valueMap.put(key, value);
}
return valueMap;
} catch (JSONException e) {
e.printStackTrace();
}
return valueMap;
}
}
|
||
| 97 | 97 |
|
| 98 | 98 |
|
| 99 | 99 |
|
| 100 |
|
|
| 101 |
|
|
| 100 | 102 |
|
| 101 | 103 |
|
| 102 | 104 |
|