下面列出了android.widget.ImageView#ScaleType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void updateShaderAndSize(@NonNull ImageView.ScaleType scaleType, int vWidth, int vHeight, ImageDrawable imageDrawable, BitmapShader bitmapShader) {
Matrix matrix = createShaderMatrix(scaleType, vWidth, vHeight,
imageDrawable.bitmapWidth,
imageDrawable.bitmapHeight);
int intrinsicWidth = vWidth, intrinsicHeight = vHeight;
if (scaleType == ImageView.ScaleType.FIT_CENTER) {
RectF bitmapRect = new RectF(0, 0, imageDrawable.bitmapWidth, imageDrawable.bitmapHeight), contentRect = new RectF();
matrix.mapRect(contentRect, bitmapRect);
intrinsicWidth = (int) contentRect.width();
intrinsicHeight = (int) contentRect.height();
matrix = createShaderMatrix(scaleType, intrinsicWidth, intrinsicHeight, imageDrawable
.bitmapWidth, imageDrawable.bitmapHeight);
}
imageDrawable.setIntrinsicWidth(intrinsicWidth);
imageDrawable.setIntrinsicHeight(intrinsicHeight);
bitmapShader.setLocalMatrix(matrix);
}
private static int scaleTypeToInt(ImageView.ScaleType scaleType) {
for (int i = 0; i < SCALE_TYPE_VALUES.length; i++) {
if (scaleType == SCALE_TYPE_VALUES[i]) {
return i;
}
}
return -1;
}
static boolean isSupportedScaleType(final ImageView.ScaleType scaleType) {
if (scaleType == null) {
return false;
}
switch (scaleType) {
case MATRIX:
throw new IllegalStateException("Matrix scale type is not supported");
}
return true;
}
public WearImageRequest(String url, Response.Listener<Bitmap> listener, int maxWidth, int maxHeight, Bitmap.Config decodeConfig,
ImageView.ScaleType scaleType, Response.ErrorListener errorListener) {
super(url, listener, maxWidth, maxHeight, decodeConfig, scaleType, errorListener);
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
config = decodeConfig;
this.scaleType = scaleType;
}
/**
* ImageView.ScaleTypeからMatrixUtils.ScaleTypeへ変換
* @param scaleType
* @return
*/
@NonNull
public static ScaleType fromImageViewScaleType(@NonNull final ImageView.ScaleType scaleType) {
if (sScaleTypeMap.containsKey(scaleType)) {
return sScaleTypeMap.get(scaleType);
} else {
return ScaleType.CENTER_CROP;
}
}
public void setImageHeader(Bitmap background, int headerDPHeight, ImageView.ScaleType scaleType) {
setImageHeader(background, scaleType);
this.headerDPHeight = headerDPHeight;
}
public void setScaleType(@NonNull ImageView.ScaleType scaleType) {
zoomer.setScaleType(scaleType);
}
private static Matrix.ScaleToFit scaleTypeToScaleToFit(ImageView.ScaleType st) {
// ScaleToFit enum to their corresponding Matrix.ScaleToFit values
return sS2FArray[st.ordinal() - 1];
}
public ImageView.ScaleType getScaleType() {
return ImageView.ScaleType.valueOf(mScaleType);
}
public ImageView.ScaleType getScaleType() {
return mImageView.getScaleType();
}
void setScaleType(ImageView.ScaleType scaleType) {
this.scaleType = scaleType;
}
public static Bitmap getImageThumbnail(String path, int mMaxWidth, int mMaxHeight){
Bitmap.Config mDecodeConfig = Bitmap.Config.RGB_565;
ImageView.ScaleType mScaleType = ImageView.ScaleType.CENTER_CROP;
File bitmapFile = new File(path);
Bitmap bitmap = null;
if (!bitmapFile.exists() || !bitmapFile.isFile()) {
return bitmap;
}
BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
decodeOptions.inInputShareable = true;
decodeOptions.inPurgeable = true;
decodeOptions.inPreferredConfig = mDecodeConfig;
if (mMaxWidth == 0 && mMaxHeight == 0) {
bitmap = BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
} else {
// If we have to resize this image, first get the natural bounds.
decodeOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
int actualWidth = decodeOptions.outWidth;
int actualHeight = decodeOptions.outHeight;
// Then compute the dimensions we would ideally like to decode to.
int desiredWidth = getResizedDimension(mMaxWidth, mMaxHeight,
actualWidth, actualHeight, mScaleType);
int desiredHeight = getResizedDimension(mMaxHeight, mMaxWidth,
actualHeight, actualWidth, mScaleType);
// Decode to the nearest power of two scaling factor.
decodeOptions.inJustDecodeBounds = false;
decodeOptions.inSampleSize = ImageUtils.findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
Bitmap tempBitmap = BitmapFactory.decodeFile(bitmapFile.getAbsolutePath(), decodeOptions);
// If necessary, scale down to the maximal acceptable size.
if (tempBitmap != null
&& (tempBitmap.getWidth() > desiredWidth || tempBitmap.getHeight() > desiredHeight)) {
bitmap = Bitmap.createScaledBitmap(tempBitmap, desiredWidth,
desiredHeight, true);
tempBitmap.recycle();
} else {
bitmap = tempBitmap;
}
}
return bitmap;
}
/**
* 重置
*/
void reset(@NonNull final Context context, @NonNull final Sizes sizes, @Nullable final ImageView.ScaleType scaleType, final float rotateDegrees, final boolean readMode);
/**
* Controls how the image should be resized or moved to match the size of
* the ImageView. Any scaling or panning will happen within the confines of
* this {@link android.widget.ImageView.ScaleType}.
*
* @param scaleType - The desired scaling mode.
*/
void setScaleType(ImageView.ScaleType scaleType);
/**
* remove the specified uri image cache.
* @param uri image uri
* @param maxWidth max width
* @param maxHeight max height
* @param scaleType {@link android.widget.ImageView.ScaleType}
*/
public void removeCache(String uri, int maxWidth, int maxHeight, ImageView.ScaleType scaleType) {
mImageLoader.removeCache(uri, maxWidth, maxHeight, scaleType);
}
/**
* Controls how the image should be resized or moved to match the size of the ImageView. Any
* scaling or panning will happen within the confines of this {@link
* android.widget.ImageView.ScaleType}.
*
* @param scaleType - The desired scaling mode.
*/
void setScaleType(ImageView.ScaleType scaleType);
/**
* Return the current scale type in use by the ImageView.
*/
ImageView.ScaleType getScaleType();
/**
* Return the current scale type in use by the ImageView.
*
* @return current ImageView.ScaleType
*/
ImageView.ScaleType getScaleType();
/**
* Controls how the image should be resized or moved to match the size of
* the ImageView. Any scaling or panning will happen within the confines of
* this {@link android.widget.ImageView.ScaleType}.
*
* @param scaleType - The desired scaling mode.
*/
void setScaleType(ImageView.ScaleType scaleType);
/**
* Decode a byte array into a bitmap, this will try its best to reuse old bitmaps allocations and will scale the image to the max height or width passed in.
*
* @param data image to be decoded
* @param config Bitmap config for decode into, Defaults to RGB_565 if null is passed.
* @param maxWidth maxWidth to decode to.
* @param maxHeight maxHeight to decode to.
* @return decoded bitmap or null if an error occured without a parse error.
* @throws ParseError
*/
public static Bitmap parseImage(@NonNull byte[] data, @Nullable Bitmap.Config config, ImageView.ScaleType scaleType, int maxWidth, int maxHeight) throws ParseError {
return parseImage(null, data, config, scaleType, maxWidth, maxHeight);
}