Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

save bitmap file for share on android 10

private void saveImage(Bitmap bitmap, @NonNull String name) throws IOException {
    boolean saved;
    OutputStream fos;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        ContentResolver resolver = mContext.getContentResolver();
        ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name);
        contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png");
        contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + IMAGES_FOLDER_NAME);
        Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
        fos = resolver.openOutputStream(imageUri);
    } else {
        String imagesDir = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DCIM).toString() + File.separator + IMAGES_FOLDER_NAME;

        File file = new File(imagesDir);

        if (!file.exists()) {
            file.mkdir();
        }

        File image = new File(imagesDir, name + ".png");
        fos = new FileOutputStream(image)

    }

    saved = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
    fos.flush();
    fos.close();
}
Comment

PREVIOUS NEXT
Code Example
Java :: java convert pdf to image 
Java :: sound file java 
Java :: how to sort arraylist 
Java :: java system.out.println not working 
Java :: jpa page sort 
Java :: how to find the largest number in java 
Java :: valueof in java 
Java :: java hashmap time complexity 
Java :: debug in java 
Java :: convert class to java 
Java :: how to plus two numbers in java 
Java :: can i have both java7 and java 11 in mac 
Java :: java array erstellen 
Java :: arraylist vs vector in java 
Java :: char array to string in java 
Java :: Programme to calculate Combination 
Java :: check if optional is empty java 
Java :: java string equal 
Java :: Java How to use List? 
Java :: how to replace in java 
Java :: Java Searching Using binarySearch() 
Java :: MyLinkedList 
Java :: long to double in java 
Java :: infinite value total 
Java :: rename action bar android 
Java :: how to create a subclass in java 
Java :: date and time java 
Java :: Unexpected end of file in android studio activity main.xml 
Java :: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251) 
Java :: java string stringbuilder array list tostring 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =