浏览代码

Merge branch 'master' of http://10.1.235.20:3000/ipu/android-share

leijie 8 年之前
父节点
当前提交
5094165740

+ 37 - 31
wade-mobile-func/src/com/wade/mobile/func/MobileCamera.java

@ -22,10 +22,10 @@ import com.ai.ipu.mobile.ui.image.MobileGraphics;
22 22
import com.ai.ipu.mobile.util.IpuMobileUtility;
23 23
import com.ailk.common.data.IData;
24 24
import com.ailk.common.data.impl.DataMap;
25
import com.google.zxing.WriterException;
26 25
import com.wade.mobile.app.IpuAppInfo;
27 26
import com.wade.mobile.frame.IWadeMobile;
28 27
import com.wade.mobile.frame.plugin.Plugin;
28
import com.wade.mobile.util.BitmapUtils;
29 29
import com.wade.mobile.util.DirectionUtil;
30 30

31 31
/**
@ -178,38 +178,44 @@ public class MobileCamera extends Plugin {
178 178
				callback(scanResult);
179 179
			}
180 180
		} else if (func.equals(Function.getPhoto)) {
181
			// 照相功能
181
			// 照相功能modify by wyj 按照分辨率压缩
182 182
			if (resultCode == Activity.RESULT_OK) {
183
				Bitmap bitmap = null; 
184
				try {
185
					bitmap = getBitmapByImage(photoFullPath); //核实照片文件是否已经生成???????
186
				} catch (Exception e) {
187
					HintUtil.alert(context, e.getMessage());
188
					return;
189
				}
183
//				Bitmap bitmap = null; 
184
//				try {
185
//					bitmap = getBitmapByImage(photoFullPath); //核实照片文件是否已经生成???????
186
//				} catch (Exception e) {
187
//					HintUtil.alert(context, e.getMessage());
188
//					return;
189
//				}
190
//				
191
//				if (requestCode == TYPE.PATH.getType()) {
192
//					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
193
//					callback(photoFullPath);
194
//				}else if(requestCode == TYPE.BASE64.getType()){
195
//					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
196
//					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
197
//					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64缩略图
198
//					base64Bitmap.recycle();
199
//					callback(out);
200
//				}else{
201
//					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
202
//					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
203
//					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
204
//					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
205
//					base64Bitmap.recycle();
206
//					IData result = new DataMap();
207
//					result.put("thumbnail", out); //缩略图
208
//					result.put("path", photoFullPath); //路径
209
//					callback(result.toString());
210
//				}
211
//				bitmap.recycle();
212
//				photoFullPath = null;
190 213
				
191
				if (requestCode == TYPE.PATH.getType()) {
192
					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
193
					callback(photoFullPath);
194
				}else if(requestCode == TYPE.BASE64.getType()){
195
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
196
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
197
					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64缩略图
198
					base64Bitmap.recycle();
199
					callback(out);
200
				}else{
201
					//MobileGraphics.savePicToLocal(bitmap, photoFullPath); //保存压缩文件
202
					bitmap = MobileGraphics.compressImage(bitmap, 50, quality);	//压缩到50k
203
					Bitmap base64Bitmap = MobileGraphics.compressImage(bitmap, 10, 30);	//quality=30?
204
					String out = MobileGraphics.bitmapToString(base64Bitmap); //base64处理
205
					base64Bitmap.recycle();
206
					IData result = new DataMap();
207
					result.put("thumbnail", out); //缩略图
208
					result.put("path", photoFullPath); //路径
209
					callback(result.toString());
210
				}
211
				bitmap.recycle();
212
				photoFullPath = null;
214
				String picBase64 = BitmapUtils.compressBitmap(photoFullPath, photoFullPath, 640);
215
				IData result = new DataMap();
216
				result.put("base64", picBase64);
217
				result.put("path", photoFullPath);
218
				callback(result.toString());
213 219
			}
214 220
		} else if (func.equals(Function.getPicture)) {// 从媒体库中获取
215 221
			if (resultCode == Activity.RESULT_OK) {

+ 118 - 0
wade-mobile-func/src/com/wade/mobile/util/BitmapUtils.java

@ -0,0 +1,118 @@
1
package com.wade.mobile.util;
2

3
import java.io.ByteArrayOutputStream;
4
import java.io.File;
5
import java.io.FileNotFoundException;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
8

9
import android.graphics.Bitmap;
10
import android.graphics.BitmapFactory;
11

12
import com.ai.ipu.basic.string.Base64;
13

14
/**
15
 * 压缩图片处理工具类
16
 * 
17
 * @author wangyujuan
18
 *
19
 */
20
public final class BitmapUtils {
21

22
	/**
23
	 * 压缩图片
24
	 * 
25
	 * @param sourcePath
26
	 *            原图路径
27
	 * @param targetPath
28
	 *            目标图片路径
29
	 * @param maxSize
30
	 *            最大分辨率
31
	 */
32
	public static String compressBitmap(String sourcePath, String targetPath,
33
			int maxSize) {
34

35
		// 如果将其设为true的话,在decode时将会返回null,通过此设置可以去查询一个bitmap的属性
36
		BitmapFactory.Options options = new BitmapFactory.Options();
37
		options.inJustDecodeBounds = true;
38

39
		BitmapFactory.decodeFile(sourcePath, options);
40

41
		final float originalWidth = options.outWidth;
42
		final float originalHeight = options.outHeight;
43
		float convertedWidth;
44

45
		if (originalWidth > originalHeight) {
46
			convertedWidth = maxSize;
47
		} else {
48
			convertedWidth = maxSize / originalHeight * originalWidth;
49
		}
50

51
		final float ratio = originalWidth / convertedWidth;
52

53
		options.inSampleSize = (int) ratio;
54
		options.inJustDecodeBounds = false;
55

56
		Bitmap bitmap = BitmapFactory.decodeFile(sourcePath, options);
57
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
58
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
59
		FileOutputStream fileOutputStream = null;
60
		try {
61
			fileOutputStream = new FileOutputStream(new File(targetPath));
62
			byte[] imageByte = byteArrayOutputStream.toByteArray();
63
			fileOutputStream.write(imageByte);
64
			fileOutputStream.flush();
65

66
			return Base64.encode(imageByte);
67
		} catch (FileNotFoundException e) {
68
			e.printStackTrace();
69
		} catch (IOException e) {
70
			e.printStackTrace();
71
		} finally {
72
			if (null != fileOutputStream) {
73
				try {
74
					fileOutputStream.close();
75
				} catch (IOException e) {
76
					e.printStackTrace();
77
				}
78

79
			}
80
			bitmap.recycle();
81
		}
82

83
		return null;
84
	}
85

86
	// /**
87
	// * 获取图片Base64字符串
88
	// *
89
	// * @param filePath
90
	// * 图片路径
91
	// */
92
	// public static String bitmapToString(String filePath) {
93
	// BitmapFactory.Options options = new BitmapFactory.Options();
94
	//
95
	// options.inJustDecodeBounds = false;
96
	// Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
97
	//
98
	// ByteArrayOutputStream byteArrayOutputStream = new
99
	// ByteArrayOutputStream();
100
	// bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
101
	// FileOutputStream fileOutputStream = null;
102
	// try {
103
	// byte[] imageByte = byteArrayOutputStream.toByteArray();
104
	// return Base64.encode(imageByte);
105
	// } finally {
106
	// if (null != fileOutputStream) {
107
	// try {
108
	// fileOutputStream.close();
109
	// } catch (IOException e) {
110
	// e.printStackTrace();
111
	// }
112
	//
113
	// }
114
	// bitmap.recycle();
115
	// }
116
	// }
117

118
}