Text().toString()); par.put("fast_num", fastNum.getText().toString()); par.put("slow_num", slowNum.getText().toString()); if (tag.equals("edit")) { par.put("where", id); par.put("picid", "a"); } try { String u = UploadUtil.post(MainApplication.url + "/zhannew/basic/web/index.php/applist/createpile", par, null); Message msg = new Message(); msg.obj = u; msg.what = 2; handler.sendMessage(msg); } catch (IOException e) { e.printStackTrace(); } } @Override public void onPermissionsGranted(int requestCode, List<String> perms) { } @Override public void onPermissionsDenied(int requestCode, List<String> perms) { } @AfterPermissionGranted(RC_ALBUM_PERM) public void permissionTask() { if (isPermissionOK()) { callGallery(); } else { EasyPermissions.requestPermissions( this, "充电桩想要获取您的图片读取权限,是否允许?", RC_ALBUM_PERM, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA ); } } private boolean isPermissionOK() { return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA ); } public String getString(String s) { String path = null; if (s == null) return ""; for (int i = s.length() - 1; i > 0; i++) { s.charAt(i); } return path; } protected void onRestart() { super.onRestart(); } private static final int TAKE_PICTURE = 0x000001; public void photo() { if (hasSdcard()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile)); startActivityForResult(intent, PHOTO_REQUEST_CAMERA); } } @Override protected void onDestroy() { Bimp.tempSelectBitmap.clear(); Bimp.max = 0; super.onDestroy(); } private Bitmap compressBmpFromBmp(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int options = 100; image.compress(Bitmap.CompressFormat.JPEG, 60, baos); while (baos.toByteArray().length / 1024 > 200) { baos.reset(); options -= 10; image.compress(Bitmap.CompressFormat.JPEG, options, baos); } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null); return bitmap; } private void crop(Uri uri, Uri cutImgUri) { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("outputFormat", "JPEG"); intent.putExtra("noFaceDetection", true);// ȡ������ʶ�� intent.putExtra("return-data", false);// true:������uri��false������uri intent.putExtra(MediaStore.EXTRA_OUTPUT, cutImgUri);//д���ȡ��ͼƬ startActivityForResult(intent, PHOTO_REQUEST_CUT); } private boolean hasSdcard() { if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { return true; } else { return false; } } private static String getPath(String path) { File f = new File(path); if (!f.exists()) { f.mkdirs(); } return f.getAbsolutePath(); } private File getFile(String path) { File f = new File(path); if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return f; } public Bitmap decodeUriAsBitmap(Uri uri) { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap; } private Bitmap comp(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 30, baos); if (baos.toByteArray().length / 1024 > 1024) {//判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出 baos.reset();//重置baos即清空baos image.compress(Bitmap.CompressFormat.JPEG, 50, baos);//这里压缩50%,把压缩后的数据存放到baos中 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray()); BitmapFactory.Options newOpts = new BitmapFactory.Options(); //开始读入图片,此时把options.inJustDecodeBounds 设回true了 newOpts.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, newOpts); newOpts.inJustDecodeBounds = false; int w = newOpts.outWidth; int h = newOpts.outHeight; //现在主流手机比较多是800*480分辨率,所以高和宽我们设置为 float hh = 800f;//这里设置高度为800f float ww = 480f;//这里设置宽度为480f //缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可 int be = 1;//be=1表示不缩放 if (w > h && w > ww) {//如果宽度大的话根据宽度固定大小缩放 be = (int) (newOpts.outWidth / ww); } else if (w < h && h > hh) {//如果高度高的话根据宽度固定大小缩放 be = (int) (newOpts.outHeight / hh); } if (be <= 0) be = 1; newOpts.inSampleSize = be;//设置缩放比例 newOpts.inPreferredConfig = Bitmap.Config.RGB_565;//降低图片从ARGB888到RGB565 //重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了 isBm = new ByteArrayInputStream(baos.toByteArray()); bitmap = BitmapFactory.decodeStream(isBm, null, newOpts); return compressImage(bitmap);//压缩好比例大小后再进行质量压缩 } private Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 80, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中 int options = 70; while (baos.toByteArray().length / 1024 > 300) { //循环判断如果压缩后图片是否大于100kb,大于继续压缩 baos.reset();//重置baos即清空baos options -= 10;//每次都减少10 image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中 } ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中 Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片 return bitmap; } 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); return bitmap; } @Override protected void onResume() { super.onResume(); for (int i = 0; i < selectBitmap.length; i++) { ImageItem imageItem = selectBitmap[i]; if (imageItem == null) { takeImageCameraList.get(i).setVisibility(View.VISIBLE); ImageView takeImageView = takeImageViewList.get(i); takeImageView.setImageResource(Res.getDrawableID("private_point_pic_" + (i + 1))); takeImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) takeImageView.getLayoutParams(); lp.width = ViewGroup.LayoutParams.WRAP_CONTENT; lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; takeImageView.setLayoutParams(lp); } else { takeImageCameraList.get(i).setVisibility(View.GONE); } } } public Bitmap getHttpBitmap(String url) { Bitmap bitmap = null; try { URL pictureUrl = new URL(url); InputStream in = pictureUrl.openStream(); bitmap = BitmapFactory.decodeStream(in); in.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return bitmap; } public void savePicture(Bitmap bitmap) { String pictureName = "/storage/emulated/0/DCIM/Camera/aaaa.jpg"; File file = new File(pictureName); FileOutputStream out; try { out = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuItem item = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, "Exit"); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { System.exit(0); return true; } }); return true; } } Marcelino Deasey - Gogs: Go Git Service
Marcelino Deasey a4-copy-paper-stock5869