- Notifications
You must be signed in to change notification settings - Fork69
An image resizing library for Android
License
NotificationsYou must be signed in to change notification settings
hkk595/Resizer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Inspired by zetbaitsu'sCompressor, Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an image file to a smaller or bigger one while keeping the aspect ratio.
- Add the JitPack repository to your top-level build.gradle at the end of repositories
allprojects { repositories { maven { url'https://jitpack.io' } }}
- Add the dependency in your module-level build.gradle
dependencies { compile'com.github.hkk595:Resizer:v1.5'}
FileresizedImage =newResizer(this) .setTargetLength(1080) .setQuality(80) .setOutputFormat("JPEG") .setOutputFilename("resized_image") .setOutputDirPath(storagePath) .setSourceImage(originalImage) .getResizedFile();
BitmapresizedImage =newResizer(this) .setTargetLength(1080) .setSourceImage(originalImage) .getResizedBitmap();
Note: You only need to specify the target length (in pixel) of the longer side (or either side if it's a square) of the image. Resizer will calculate the rest automatically.
finalFile[]resizedImage =newFile[1];newResizer(this) .setTargetLength(1080) .setQuality(80) .setOutputFormat("JPEG") .setOutputFilename("resized_image") .setOutputDirPath(storagePath) .setSourceImage(originalImage) .getResizedFileAsFlowable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(newConsumer<File>() {@Overridepublicvoidaccept(Filefile) {resizedImage[0] =file; } },newConsumer<Throwable>() {@Overridepublicvoidaccept(Throwablethrowable) {throwable.printStackTrace(); } });
finalBitmap[]resizedImage =newBitmap[1];newResizer(this) .setTargetLength(1080) .setSourceImage(originalImage) .getResizedBitmapAsFlowable() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(newConsumer<Bitmap>() {@Overridepublicvoidaccept(Bitmapbitmap) {resizedImage[0] =bitmap; } },newConsumer<Throwable>() {@Overridepublicvoidaccept(Throwablethrowable) {throwable.printStackTrace(); } });
Note: You don't need to declare the new image as final nor array if it's an instance variable of the class, instead of a local variable in a function.
Refer to theJavaDoc for more details.
Minimum SDK: API 16 Default settings:targetLength: 1080quality: 80outputFormat: JPEGoutputFilename: same as the source fileoutputDirPath: the external files directory of your app Supported input formats:BMPGIFJPEGPNGWEBP Supported output formats:JPEGPNGWEBP Supported quality range: 0~100The higher value, the better image quality but larger file sizePNG, which is a lossless format, will ignore the quality setting
MIT License Copyright (c) 2017 K.K. Ho Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
An image resizing library for Android
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published