Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Saving an image into SDcard in Android

    • 0
    • 2
    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 391
    Comment on it

    Sometime we need to save images on SDcard that we click or get from server in many applications, and you can do it very easily by using the below code.

    To save Images on SDcard on Android Device, write the following code:

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    // Here imageBitmap is the bitmap of image that we want to save on SDcard
    imageBitmap.compress(CompressFormat.JPEG, 75, bos); 
    // Here you will provide the folder name
    File photoDirectory= new File(android.os.Environment.getExternalStorageDirectory()+"/Varta/images");
    if(!photoDirectory.exists())
    {
        photoDirectory.mkdirs();
    }
    File photo= new File(android.os.Environment.getExternalStorageDirectory()+"/Varta/images", new Date().getTime()+".png");
    String fileName=photo.getPath();
    FileOutputStream fos;
    try 
    {
        fos = new FileOutputStream(fileName);
        bos.writeTo(fos);
        bos.flush();
        fos.flush();
        bos.close();
        fos.close();
        return fileName;
    } catch (FileNotFoundException e) 
    {
        e.printStackTrace();
        return null;
    } catch (IOException e) 
    {
    
        e.printStackTrace();
        return null;
    }
    

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: