NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.app.ChatLibDemo.mediapicker;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.WorkerThread;

import com.app.ChatLibDemo.utils.Log;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;


public class Utility {
private static final String TAG = "Utility";

public static String compressImage(String path) throws IOException {
File file = new File(path);
Bitmap bitmap = BitmapFactory.decodeFile(path);
OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
os.close();
return path;
}

public static String getRandomString() {
// return SystemClock.currentThreadTimeMillis()+"";
return UUID.randomUUID().toString();
}

public static void createFolder(String path) {
try {
File dir = new File(path.substring(0, path.lastIndexOf("/")));
Log.e(TAG, "createFolder: " + dir.exists());
if (!dir.exists()) {
dir.mkdirs();
}
} catch (Exception ex) {
android.util.Log.w(TAG, "creating file error: ", ex);
}

}

public static String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = {MediaStore.Images.Media.DATA};
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
assert cursor != null;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}

@WorkerThread
public static void compressAndRotateIfNeeded(File sourceFile, File destinationFile, int value, int reqWidth, int reqHeight) throws IOException {

String path = sourceFile.getAbsolutePath();

BitmapFactory.Options bounds = new BitmapFactory.Options();
Bitmap bm;
if (reqHeight != 0 && reqWidth != 0) {
bounds.inJustDecodeBounds = true;
bm = BitmapFactory.decodeFile(path, bounds);
bounds.inSampleSize = calculateInSampleSize(bounds, reqWidth, reqHeight);
bounds.inJustDecodeBounds = false;
}
bm = BitmapFactory.decodeFile(path, bounds);

if (bm == null) {
Log.e("compress", "bitmap is null");
return;
}

int rotationAngle = getCameraPhotoOrientation(sourceFile);

Matrix matrix = new Matrix();
matrix.postRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2);
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight,
matrix, true);

FileOutputStream fos = new FileOutputStream(destinationFile.getAbsoluteFile());
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, value, fos);
fos.flush();
fos.close();
}

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {

final int halfHeight = height / 2;
final int halfWidth = width / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight
&& (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}

return inSampleSize;
}

@WorkerThread
private static int getCameraPhotoOrientation(File file) throws IOException {
ExifInterface exif = new ExifInterface(
file.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);

int rotate = 0;

switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
default:
break;
}

return rotate;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.