Git Product home page Git Product logo

Comments (2)

ravi-savaj avatar ravi-savaj commented on May 25, 2024

File outputFile = FileUtils.genEditFile();
try {
Intent intent = new ImageEditorIntentBuilder(this, root, outputFile.getAbsolutePath())
.withAddText() // Add the features you need
.withPaintFeature()
.withFilterFeature()
.withRotateFeature()
.withCropFeature()
.withBrightnessFeature()
.withSaturationFeature()
.withBeautyFeature()
.withStickerFeature()
.forcePortrait(true) // Add this to force portrait mode (It's set to false by default)
.setSupportActionBarVisibility(false) // To hide app's default action bar
.build();
EditImageActivity.start(ImagePriview.this, intent, PHOTO_EDITOR_REQUEST_CODE);
} catch (Exception e) {
Log.e("Demo App", e.getMessage()); // This could throw if either sourcePath or outputPath is blank or Null
}

than cretate FileUtils Class:

public class FileUtils {
public static final String FOLDER_NAME = "Destination File Name";

/**
 * 获取存贮文件的文件夹路径
 *
 * @return
 */
public static File createFolders() {

File baseDir;
if (android.os.Build.VERSION.SDK_INT < 8) {
baseDir = Environment.getExternalStorageDirectory();
} else {
baseDir = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
}
if (baseDir == null)
return Environment.getExternalStorageDirectory();
File aviaryFolder = new File(baseDir, FOLDER_NAME);
if (aviaryFolder.exists())
return aviaryFolder;
if (aviaryFolder.isFile())
aviaryFolder.delete();
if (aviaryFolder.mkdirs())
return aviaryFolder;
return Environment.getExternalStorageDirectory();
}

public static File genEditFile(){
    return FileUtils.getEmptyFile("FolderName"
            + System.currentTimeMillis() + ".jpg");
}

public static File getEmptyFile(String name) {
    File folder = FileUtils.createFolders();
    if (folder != null) {
        if (folder.exists()) {
            File file = new File(folder, name);
            return file;
        }
    }
    return null;
}

/**
 * 删除指定文件
 *
 * @param path
 * @return
 */
public static boolean deleteFileNoThrow(String path) {
    File file;
    try {
        file = new File(path);
    } catch (NullPointerException e) {
        return false;
    }

    if (file.exists()) {
        return file.delete();
    }
    return false;
}

/**
 * 保存图片
 *
 * @param bitName
 * @param mBitmap
 */
public static String saveBitmap(String bitName, Bitmap mBitmap) {
    File baseFolder = createFolders();
    File f = new File(baseFolder.getAbsolutePath(), bitName);
    FileOutputStream fOut = null;
    try {
        f.createNewFile();
        fOut = new FileOutputStream(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return f.getAbsolutePath();
}

// 获取文件夹大小
public static long getFolderSize(File file) throws Exception {
    long size = 0;
    try {
        File[] fileList = file.listFiles();
        for (int i = 0; i < fileList.length; i++) { // 如果下面还有文件
            if (fileList[i].isDirectory()) {
                size = size + getFolderSize(fileList[i]);
            } else {
                size = size + fileList[i].length();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return size;
}

/** * 格式化单位 * * @param size * @return */
public static String getFormatSize(double size) {
    double kiloByte = size / 1024d;
    int megaByte = (int) (kiloByte / 1024d);
    return megaByte + "MB";
}

/**
 *
 * @Description:
 * @Author 11120500
 * @Date 2013-4-25
 */
public static boolean isConnect(Context context) {
    try {
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
    } catch (Exception e) {

    }
    return false;
}

}

fileutility.zip

from ananas.

iamutkarshtiwari avatar iamutkarshtiwari commented on May 25, 2024

Closing since it's similar to this issue which is resolved in version 1.2.5.

from ananas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.