Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An Android Image compress library, reduce's the size of the image by 90% without losing any of its pixels.

License

NotificationsYou must be signed in to change notification settings

vinodbaste/Image-compressor

Repository files navigation

An Android image compress library,image compressor, is small and effective. With very little or no image quality degradation, a compressor enables you to reduce the size of large photos into smaller size photos.

Google DevLibrary - VinodBaste

APIGitHub tagLicenseNews - Android WeeklyStory - MediumGitHub - VinodBaste

How to implement

To get a Git project into your build:

Gradle

Step 1: Add it in yourroot build.gradle at the end of repositories:

allprojects {repositories {...maven { url'https://jitpack.io' }}}

Step 2: Add the dependency in yourproject build.gradle

dependencies {        implementation'com.github.vinodbaste:ImageCompressor:1.1.0'}

Let's compress the image size!

Compress Image File at the specifiedimagePath

Whencompressing a picture, add the following block of code to theactivity or fragment. Either after taking apicture with a camera or selecting onefrom a gallery.

ImageCompressUtils.compressImage(            context=this,            imagePath="actualImagePath",            imageName="imageName",            imageQuality=50        )

compressImage takes 4 parameters where thelast one is optional

  • context, the current/active state of the application.
  • imagePath parameter takes the absolute image path.
  • imageName is completely up to the user.
  • imageQuality is set to 50 by default. The max can be set to 100.

Compress Image File at the specifiedimagePath and return thecompressed ImagePath

val compressedImagePath=ImageCompressUtils.compressImage(            context=this,            imagePath="actualImagePath",            imageName="imageName",            imageQuality=50        )

With the image name supplied, the code block above returns the path to the compressed picture.compressedImagePath has the imagePath with the imageName specified.

Example

An illustration of how the code block can be utilized.

//absolute path of the imageval imagePath="actualImagePath"val imageFileBc=File(imagePath)val imageSizeBc= imageFileBc.length()/1024// In BYTESLog.d("image_before_compress", imageSizeBc.toString())ImageCompressUtils.compressImage(            context=this,            imagePath= imagePath,            imageName="imageName",            imageQuality=50        )val imageFileAc=File(imagePath)val imageSizeAC= imageFileAc.length()/1024// In BYTESLog.d("image_after_compress", imageSizeAC.toString())//your function to play with compressed image        loadCompressedImage(imagePath)

proguard-rules

-keepclassmembers class com.android.imagecompressor.compressImageUtils-keep class * extends com.android.imagecompressor.compressImageUtils { <init>(...);}-dontwarn javax.annotation.Nullable-dontwarn javax.annotation.ParametersAreNonnullByDefault

If you find this library useful, please consider starring this repository from the top of this page.

Support my work

Buy Me A Coffee

Note

> In the event that an image is selected from a gallery, make a copy of it and follow the path.> The original picture path is used to compress and rewrite the image.

License

Copyright [2022] [Vinod Baste]Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at    http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

[8]ページ先頭

©2009-2025 Movatter.jp