Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

An image resizing library for Android

License

NotificationsYou must be signed in to change notification settings

hkk595/Resizer

Repository files navigation

Android Arsenal

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.

Include Resizer into your project

  1. Add the JitPack repository to your top-level build.gradle at the end of repositories
allprojects {    repositories {        maven { url'https://jitpack.io' }    }}
  1. Add the dependency in your module-level build.gradle
dependencies {    compile'com.github.hkk595:Resizer:v1.5'}

Pass in the original image file and get the resized image as a new file

FileresizedImage =newResizer(this)        .setTargetLength(1080)        .setQuality(80)        .setOutputFormat("JPEG")        .setOutputFilename("resized_image")        .setOutputDirPath(storagePath)        .setSourceImage(originalImage)        .getResizedFile();

Pass in the original image file and get the resized image as a new bitmap

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.

Using RxJava 2 with RxAndroid to get the resized image asynchronously

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.

Library specification

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

License

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.

[8]ページ先頭

©2009-2025 Movatter.jp