/** * 采用建造者模式,设置Builder */ public static class Builder { private CompressHelper mCompressHelper; public Builder(Context context) { mCompressHelper = new CompressHelper(context); } /** * 设置图片最大宽度 * @param maxWidth 最大宽度 */ public Builder setMaxWidth(float maxWidth) { mCompressHelper.maxWidth = maxWidth; return this; } /** * 设置图片最大高度 * @param maxHeight 最大高度 */ public Builder setMaxHeight(float maxHeight) { mCompressHelper.maxHeight = maxHeight; return this; } /** * 设置压缩的后缀格式 */ public Builder setCompressFormat(Bitmap.CompressFormat compressFormat) { mCompressHelper.compressFormat = compressFormat; return this; } /** * 设置Bitmap的参数 */ public Builder setBitmapConfig(Bitmap.Config bitmapConfig) { mCompressHelper.bitmapConfig = bitmapConfig; return this; } /** * 设置压缩质量,建议80 * @param quality 压缩质量,[0,100] */ public Builder setQuality(int quality) { mCompressHelper.quality = quality; return this; } /** * 设置目的存储路径 * @param destinationDirectoryPath 目的路径 */ public Builder setDestinationDirectoryPath(String destinationDirectoryPath) { mCompressHelper.destinationDirectoryPath = destinationDirectoryPath; return this; } /** * 设置文件前缀 * @param prefix 前缀 */ public Builder setFileNamePrefix(String prefix) { mCompressHelper.fileNamePrefix = prefix; return this; } /** * 设置文件名称 * @param fileName 文件名 */ public Builder setFileName(String fileName) { mCompressHelper.fileName = fileName; return this; } public CompressHelper build() { return mCompressHelper; } }
CompressHelper.Builder构造者
最新推荐文章于 2024-05-12 09:35:47 发布