ž现 @param uri    // */ // public void startPhotoZoom(Uri uri) { // /* // *   * 至于下面这个Intent的ACTION是怎么知道的,大家可以看下自己路径下的如下网页   * // * yourself_sdk_path/docs/reference/android/content/Intent.html   * // * 直接在里面Ctrl+F搜:CROP ,之前小马没仔细看过,其实安卓系统早已经有自带图片裁剪功能,   * 是直接调本地库的,不懂C C++ // * 这个不做详细了解去了,有轮子就用轮子,不再研究轮子是怎么   * 制做的了...吼吼    // */ // Intent intent = new Intent("com.android.camera.action.CROP"); // intent.setDataAndType(uri, "image/*"); // // 下面这个crop=true是设置在开启的Intent中设置显示的VIEW可裁剪 // intent.putExtra("crop", "true"); // // aspectX aspectY 是宽高的比例 // intent.putExtra("aspectX", 16); // intent.putExtra("aspectY", 9); // // outputX outputY 是裁剪图片宽高 // intent.putExtra("outputX", 480); // intent.putExtra("outputY", 270); // intent.putExtra("return-data", true); // startActivityForResult(intent, 3); // } // // // // /** 保存裁剪之后的图片数据 **/ // private void setPicToView(Intent picdata) { // Bundle extras = picdata.getExtras(); // if (extras != null) { // photo = extras.getParcelable("data"); // if (photo != null) { // // m_imageUser.setImageBitmap((Bitmap) photo); //// 给image设置图片 //// alterImage1.setImageBitmap(photo); //// uploadPhoto.setImageBitmap(photo); //// addPhoto.setVisibility(View.GONE); //// ll_uploadPhoto.setVisibility(View.VISIBLE); // String fileName = String.valueOf(System.currentTimeMillis()); //// Bitmap bm = (Bitmap) photo.getExtras().get("data"); // FileUtils.saveBitmap(bm, fileName); //// // ImageItem takePhoto = new ImageItem(); // takePhoto.setBitmap(photo); // takePhoto.setImagePath(FileUtils.SDPATH + fileName + ".JPEG"); // Bimp.tempSelectBitmap.add(takePhoto); // } // // } // } // if (extras != null) { // photo2 = extras.getParcelable("data"); // if (photo2 != null) { // // m_imageUser.setImageBitmap((Bitmap) photo); //// 给image设置图片 // alterImage2.setImageBitmap(photo2); // // } // } // if (extras != null) { // photo3 = extras.getParcelable("data"); // if (photo3 != null) { // // m_imageUser.setImageBitmap((Bitmap) photo); //// 给image设置图片 // alterImage3.setImageBitmap(photo2); // // } // } 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; } 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; } @Override protected void onDestroy() { // Bimp.tempSelectBitmap.clear(); // adapter.update(); Bimp.tempSelectBitmap.clear(); Bimp.max = 0; super.onDestroy(); } // 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; // } // private void imageZoom(Bitmap bm) { // // 图片允许最大空间 单位:KB // double maxSize = 400.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)); // } // } public void compress(Bitmap bitmap) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); float hh = dm.heightPixels; float ww = dm.widthPixels; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; // Bitmap bitmap = BitmapFactory.decodeFile(srcPath, opts); opts.inJustDecodeBounds = false; int w = opts.outWidth; int h = opts.outHeight; int size = 0; if (w <= ww && h <= hh) { size = 1; } else { double scale = w >= h ? w / ww : h / hh; double log = Math.log(scale) / Math.log(2); double logCeil = Math.ceil(log); size = (int) Math.pow(2, logCeil); } opts.inSampleSize = size; // bitmap = BitmapFactory.decodeFile(srcPath, opts); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int quality = 100; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); System.out.println(baos.toByteArray().length); while (baos.toByteArray().length > SIZE) { baos.reset(); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos); quality -= 20; System.out.println(baos.toByteArray().length); } try { // BitmapFactory.decodeByteArray(baos, 0, baos.toByteArray()); // baos.writeTo(new FileOutputStream( // "/mnt/sdcard/Servyou/photo/buffer/22.jpg")); } catch (Exception e) { e.printStackTrace(); } finally { try { baos.flush(); baos.close(); } catch (IOException e) { e.printStackTrace(); } } } private void crop(Uri uri, Uri cutImgUri) { // �ü�ͼƬ��ͼ Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(getImageContentUri(this, tempFile), "image/*"); intent.putExtra("crop", "true"); // �ü���ı�����1��1 // intent.putExtra("aspectX", 16); // intent.putExtra("aspectY", 9); // // �ü������ͼƬ�ijߴ��С // intent.putExtra("outputX", 640); // intent.putExtra("outputY", 360); // ͼƬ��ʽ intent.putExtra("outputFormat", "JPEG"); intent.putExtra("noFaceDetection", true);// ȡ������ʶ�� intent.putExtra("return-data", false);// true:������uri��false������uri intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));//д���ȡ��ͼƬ 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; } public static Uri getImageContentUri(Context context, File imageFile) { String filePath = imageFile.getAbsolutePath(); Cursor cursor = context.getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA + "=? ", new String[]{filePath}, null); if (cursor != null && cursor.moveToFirst()) { int id = cursor.getInt(cursor .getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(baseUri, "" + id); } else { if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.DATA, filePath); return context.getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); } else { return null; } } } public static boolean containsEmoji(String source) { int len = source.length(); for (int i = 0; i < len; i++) { char codePoint = source.charAt(i); if (!isEmojiCharacter(codePoint)) { //如果不能匹配,则该字符是Emoji表情 return true; } } return false; } /** * 判断是否是Emoji * * @param codePoint 比较的单个字符 * @return */ private static boolean isEmojiCharacter(char codePoint) { return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF)); } @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(); // Have permission, do the thing! // Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show(); // ifTimeout(); } else { // Ask for one permission EasyPermissions.requestPermissions( this, "充电桩想要获取您的图片读取权限,是否允许?", RC_ALBUM_PERM, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE); } } private boolean isPermissionOK() { return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE ); } } Tayla Venable - Gogs: Go Git Service
Tayla Venable dimensions-of-20ft-container0066