Commit bd8b2a5f by sikang

update camera

parent bc4534a9
......@@ -12,6 +12,7 @@ import android.widget.ImageView;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import java.io.File;
import java.io.FileOutputStream;
import tech.starwin.R;
......@@ -102,50 +103,41 @@ public class TakePhotoActivity extends BaseActivity {
public void onEventClick(View v) {
if (v.getId() == R.id.button_shoot) {
cameraView.captureImage(bitmap -> {
long pix_size = bitmap.getWidth() * bitmap.getHeight();
float scale = 720 * 1080 / (float) pix_size;
BitmapUtils.scaleBitmap(bitmap, scale);
if(TextUtils.equals(type, PhotoType.KTP.name())){
SPDataProvider.saveKTPImage(bitmap);
}else if(TextUtils.equals(type, PhotoType.WORK_CARD.name())){
SPDataProvider.saveWorkImage(bitmap);
// long pix_size = bitmap.getWidth() * bitmap.getHeight();
// float scale = 720 * 1080 / (float) pix_size;
// BitmapUtils.scaleBitmap(bitmap, scale);
// if(TextUtils.equals(type, PhotoType.KTP.name())){
// SPDataProvider.saveKTPImage(bitmap);
// }else if(TextUtils.equals(type, PhotoType.WORK_CARD.name())){
// SPDataProvider.saveWorkImage(bitmap);
// }
// setResult(RESULT_OK);
// finish();
File image = FileUtils.getImageFile(getApplicationContext(), KTP_IMAGE);
if (!image.exists()) {
image.mkdir();
}
setResult(RESULT_OK);
finish();
//去掉SD卡权限后弃用
// File image = FileUtils.getImageFile(getApplicationContext(), KTP_IMAGE);
// if (!image.exists()) {
// image.mkdir();
// }
//
// File file = BitmapUtils.saveBitmapToSDCard(bitmap, image, 100);
// if (file == null) {
// setResult(RESULT_CANCELED);
// finish();
// return;
// }
// //如果图片过大,则压缩
// long size = FileUtils.getFileSize(file) / 1024;
// if (FileUtils.getFileSize(file) / 1024 > 1024) {
// int quality = (int) (100 * (1024f / size));
// file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality);
//
// }
File file = BitmapUtils.saveBitmapToSDCard(bitmap, image, 100);
if (file == null) {
setResult(RESULT_CANCELED);
finish();
return;
}
//如果图片过大,则压缩
long size = FileUtils.getFileSize(file) / 1024;
if (FileUtils.getFileSize(file) / 1024 > 1024) {
int quality = (int) (100 * (1024f / size));
file = BitmapUtils.saveBitmapToSDCard(bitmap, image, quality);
// Intent intent = new Intent();
// intent.putExtra("image_path", file.getAbsolutePath());
// setResult(RESULT_OK, intent);
// finish();
}
Intent intent = new Intent();
intent.putExtra("image_path", file.getAbsolutePath());
setResult(RESULT_OK, intent);
finish();
// try {
// FileOutputStream outputStream = new FileOutputStream(image.getPath());
// outputStream.write(data);
// outputStream.close();
//
// } catch (java.io.IOException e) {
// e.printStackTrace();
// }
});
} else if (v.getId() == R.id.button_cancel) {
setResult(RESULT_CANCELED);
......
......@@ -474,22 +474,22 @@ public class UserPresenter extends BasePresenter<UserApi> {
}
// public void submitEmploymentInfo(String action, File workCardImage, EmploymentServerBean employmentBean) {
// MultipartBody.Part part = null;
// if (workCardImage != null && workCardImage.exists()) {
// part = MultipartBodyMaker.makeSimplePart("file", workCardImage);
// }
// submitEmploymentInfo(action, part, employmentBean);
// }
public void submitEmploymentInfo(String action, Bitmap bitmap, EmploymentServerBean employmentBean) {
public void submitEmploymentInfo(String action, File workCardImage, EmploymentServerBean employmentBean) {
MultipartBody.Part part = null;
if (bitmap != null) {
part = MultipartBodyMaker.makeSimplePart("file", "word_card", bitmap, Bitmap.CompressFormat.JPEG);
if (workCardImage != null && workCardImage.exists()) {
part = MultipartBodyMaker.makeSimplePart("file", workCardImage);
}
submitEmploymentInfo(action, part, employmentBean);
}
// public void submitEmploymentInfo(String action, Bitmap bitmap, EmploymentServerBean employmentBean) {
// MultipartBody.Part part = null;
// if (bitmap != null) {
// part = MultipartBodyMaker.makeSimplePart("file", "word_card", bitmap, Bitmap.CompressFormat.JPEG);
// }
// submitEmploymentInfo(action, part, employmentBean);
// }
/**
* 提交工作信息
*/
......
......@@ -62,7 +62,8 @@ public class FileUtils {
* 创建图片文件
*/
public static File getImageFile(Context context, String fileName) {
File file = new File(getAppDir(context).getAbsoluteFile() + IMAGE_CACHE);
File file = new File(context.getExternalFilesDir(null).getAbsoluteFile() + IMAGE_CACHE);
// File file = new File(getAppDir(context).getAbsoluteFile() + IMAGE_CACHE);
if (!file.exists()) {
file.mkdirs();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment