当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.equals方法代码示例

本文整理汇总了Java中android.graphics.Bitmap.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.equals方法的具体用法?Java Bitmap.equals怎么用?Java Bitmap.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Bitmap的用法示例。


在下文中一共展示了Bitmap.equals方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates a {@link Transformation} for use with picasso.
 *
 * @return the {@link Transformation}
 */
public Transformation build() {
  return new Transformation() {
    @Override public Bitmap transform(Bitmap source) {
      Bitmap transformed = RoundedDrawable.fromBitmap(source)
          .setScaleType(mScaleType)
          .setCornerRadius(mCornerRadii[0], mCornerRadii[1], mCornerRadii[2], mCornerRadii[3])
          .setBorderWidth(mBorderWidth)
          .setBorderColor(mBorderColor)
          .setOval(mOval)
          .toBitmap();
      if (!source.equals(transformed)) {
        source.recycle();
      }
      return transformed;
    }

    @Override public String key() {
      return "r:" + Arrays.toString(mCornerRadii)
          + "b:" + mBorderWidth
          + "c:" + mBorderColor
          + "o:" + mOval;
    }
  };
}
 
开发者ID:weimin96,项目名称:shareNote,代码行数:30,代码来源:RoundedTransformationBuilder.java

示例2: transform

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public final Resource<Bitmap> transform(
    Context context, Resource<Bitmap> resource, int outWidth, int outHeight) {
  if (!Util.isValidDimensions(outWidth, outHeight)) {
    throw new IllegalArgumentException(
        "Cannot apply transformation on width: " + outWidth + " or height: " + outHeight
            + " less than or equal to zero and not Target.SIZE_ORIGINAL");
  }
  BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
  Bitmap toTransform = resource.get();
  int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
  int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
  Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight);

  final Resource<Bitmap> result;
  if (toTransform.equals(transformed)) {
    result = resource;
  } else {
    result = BitmapResource.obtain(transformed, bitmapPool);
  }
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:BitmapTransformation.java

示例3: build

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Transformation build() {
    return new Transformation() {
        public Bitmap transform(Bitmap source) {
            Bitmap transformed = RoundedDrawable.fromBitmap(source).setScaleType
                    (RoundedTransformationBuilder.this.mScaleType).setCornerRadius
                    (RoundedTransformationBuilder.this.mCornerRadii[0],
                            RoundedTransformationBuilder.this.mCornerRadii[1],
                            RoundedTransformationBuilder.this.mCornerRadii[2],
                            RoundedTransformationBuilder.this.mCornerRadii[3]).setBorderWidth
                    (RoundedTransformationBuilder.this.mBorderWidth).setBorderColor
                    (RoundedTransformationBuilder.this.mBorderColor).setOval
                    (RoundedTransformationBuilder.this.mOval).toBitmap();
            if (!source.equals(transformed)) {
                source.recycle();
            }
            return transformed;
        }

        public String key() {
            return "r:" + Arrays.toString(RoundedTransformationBuilder.this.mCornerRadii) +
                    "b:" + RoundedTransformationBuilder.this.mBorderWidth + "c:" +
                    RoundedTransformationBuilder.this.mBorderColor + "o:" + RoundedTransformationBuilder.this.mOval;
        }
    };
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:RoundedTransformationBuilder.java

示例4: rotateBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 旋转bitmap
 *
 * @param origin bitmap
 * @param alpha  旋转角度
 * @return 旋转后的bitmap
 */
public static Bitmap rotateBitmap(Bitmap origin, float alpha) {
    if (origin == null || origin.isRecycled()) {
        return null;
    }
    int width = origin.getWidth();
    int height = origin.getHeight();
    Matrix matrix = new Matrix();
    matrix.setRotate(alpha);
    Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false);
    if (newBM.equals(origin)) {
        return newBM;
    }
    origin.recycle();
    return newBM;
}
 
开发者ID:shenhuanet,项目名称:Ocr-android,代码行数:23,代码来源:BitmapUtils.java

示例5: roundedCorners

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates a bitmap from a source bitmap and rounds the corners.
 *
 * @param inBitmap the source bitmap to use as a basis for the created bitmap.
 * @param width the width of the generated bitmap.
 * @param height the height of the generated bitmap.
 * @param roundingRadius the corner radius to be applied (in device-specific pixels).
 * @return a {@link Bitmap} similar to inBitmap but with rounded corners.
 * @throws IllegalArgumentException if roundingRadius, width or height is 0 or less.
 */
public static Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
    int width, int height, int roundingRadius) {
  Preconditions.checkArgument(width > 0, "width must be greater than 0.");
  Preconditions.checkArgument(height > 0, "height must be greater than 0.");
  Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0.");

  // Alpha is required for this transformation.
  Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);
  Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888);

  result.setHasAlpha(true);

  BitmapShader shader = new BitmapShader(toTransform, Shader.TileMode.CLAMP,
      Shader.TileMode.CLAMP);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(shader);
  RectF rect = new RectF(0, 0, result.getWidth(), result.getHeight());
  BITMAP_DRAWABLE_LOCK.lock();
  try {
    Canvas canvas = new Canvas(result);
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint);
    clear(canvas);
  } finally {
    BITMAP_DRAWABLE_LOCK.unlock();
  }

  if (!toTransform.equals(inBitmap)) {
    pool.put(toTransform);
  }

  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:45,代码来源:TransformationUtils.java

示例6: roundedCorners

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates a bitmap from a source bitmap and rounds the corners.
 *
 * <p>This method does <em>NOT</em> resize the given {@link Bitmap}, it only rounds it's corners.
 * To both resize and round the corners of an image, consider
 * {@link com.bumptech.glide.request.RequestOptions#transforms(Transformation[])} and/or
 * {@link com.bumptech.glide.load.MultiTransformation}.
 *
 * @param inBitmap the source bitmap to use as a basis for the created bitmap.
 * @param roundingRadius the corner radius to be applied (in device-specific pixels).
 * @return a {@link Bitmap} similar to inBitmap but with rounded corners.
 * @throws IllegalArgumentException if roundingRadius, width or height is 0 or less.
 */
public static Bitmap roundedCorners(
    @NonNull BitmapPool pool, @NonNull Bitmap inBitmap, int roundingRadius) {
  Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0.");

  // Alpha is required for this transformation.
  Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);
  Bitmap result =
      pool.get(toTransform.getWidth(), toTransform.getHeight(), Bitmap.Config.ARGB_8888);

  result.setHasAlpha(true);

  BitmapShader shader = new BitmapShader(toTransform, Shader.TileMode.CLAMP,
      Shader.TileMode.CLAMP);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(shader);
  RectF rect = new RectF(0, 0, result.getWidth(), result.getHeight());
  BITMAP_DRAWABLE_LOCK.lock();
  try {
    Canvas canvas = new Canvas(result);
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint);
    clear(canvas);
  } finally {
    BITMAP_DRAWABLE_LOCK.unlock();
  }

  if (!toTransform.equals(inBitmap)) {
    pool.put(toTransform);
  }

  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:47,代码来源:TransformationUtils.java

示例7: scaleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap scaleBitmap(Bitmap origin, float ratio) {
    if (origin == null) {
        return null;
    }
    int width = origin.getWidth();
    int height = origin.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(ratio, ratio);
    Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false);
    if (newBM.equals(origin)) {
        return newBM;
    }
    origin.recycle();
    return newBM;
}
 
开发者ID:MarcusMa,项目名称:MyCreditCardDemo,代码行数:16,代码来源:CmbChinaLoginActivity.java

示例8: rotateBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap rotateBitmap(Bitmap origin, float alpha) {
    if (origin == null) {
        return null;
    }
    int width = origin.getWidth();
    int height = origin.getHeight();
    Matrix matrix = new Matrix();
    matrix.setRotate(alpha);
    Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false);
    if (newBM.equals(origin)) {
        return newBM;
    }
    origin.recycle();
    return newBM;
}
 
开发者ID:zhouzhuo810,项目名称:CameraCardCropDemo,代码行数:16,代码来源:BitmapUtils.java

示例9: circleCrop

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Crop the image to a circle and resize to the specified width/height.  The circle crop will
 * have the same width and height equal to the min-edge of the result image.
 *
 * @param pool   The BitmapPool obtain a bitmap from.
 * @param inBitmap   The Bitmap to resize.
 * @param destWidth    The width in pixels of the final Bitmap.
 * @param destHeight   The height in pixels of the final Bitmap.
 * @return The resized Bitmap (will be recycled if recycled is not null).
 */
public static Bitmap circleCrop(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
    int destWidth, int destHeight) {
  int destMinEdge = Math.min(destWidth, destHeight);
  float radius = destMinEdge / 2f;

  int srcWidth = inBitmap.getWidth();
  int srcHeight = inBitmap.getHeight();

  float scaleX = destMinEdge / (float) srcWidth;
  float scaleY = destMinEdge / (float) srcHeight;
  float maxScale = Math.max(scaleX, scaleY);

  float scaledWidth = maxScale * srcWidth;
  float scaledHeight = maxScale * srcHeight;
  float left = (destMinEdge - scaledWidth) / 2f;
  float top = (destMinEdge - scaledHeight) / 2f;

  RectF destRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

  // Alpha is required for this transformation.
  Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);

  Bitmap result = pool.get(destMinEdge, destMinEdge, Bitmap.Config.ARGB_8888);
  result.setHasAlpha(true);

  BITMAP_DRAWABLE_LOCK.lock();
  try {
    Canvas canvas = new Canvas(result);
    // Draw a circle
    canvas.drawCircle(radius, radius, radius, CIRCLE_CROP_SHAPE_PAINT);
    // Draw the bitmap in the circle
    canvas.drawBitmap(toTransform, null, destRect, CIRCLE_CROP_BITMAP_PAINT);
    clear(canvas);
  } finally {
    BITMAP_DRAWABLE_LOCK.unlock();
  }

  if (!toTransform.equals(inBitmap)) {
    pool.put(toTransform);
  }

  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:54,代码来源:TransformationUtils.java

示例10: decodeFromWrappedStreams

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap decodeFromWrappedStreams(InputStream is,
    BitmapFactory.Options options, DownsampleStrategy downsampleStrategy,
    DecodeFormat decodeFormat, int requestedWidth, int requestedHeight,
    boolean fixBitmapToRequestedDimensions, DecodeCallbacks callbacks) throws IOException {

  int[] sourceDimensions = getDimensions(is, options, callbacks);
  int sourceWidth = sourceDimensions[0];
  int sourceHeight = sourceDimensions[1];
  String sourceMimeType = options.outMimeType;

  int orientation = ImageHeaderParserUtils.getOrientation(parsers, is, byteArrayPool);
  int degreesToRotate = TransformationUtils.getExifOrientationDegrees(orientation);

  options.inPreferredConfig = getConfig(is, decodeFormat);
  if (options.inPreferredConfig != Bitmap.Config.ARGB_8888) {
    options.inDither = true;
  }

  int targetWidth = requestedWidth == Target.SIZE_ORIGINAL ? sourceWidth : requestedWidth;
  int targetHeight = requestedHeight == Target.SIZE_ORIGINAL ? sourceHeight : requestedHeight;

  calculateScaling(downsampleStrategy, degreesToRotate, sourceWidth, sourceHeight, targetWidth,
      targetHeight, options);

  boolean isKitKatOrGreater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
  // Prior to KitKat, the inBitmap size must exactly match the size of the bitmap we're decoding.
  if ((options.inSampleSize == 1 || isKitKatOrGreater)
      && shouldUsePool(is)) {
    int expectedWidth;
    int expectedHeight;
    if (fixBitmapToRequestedDimensions && isKitKatOrGreater) {
      expectedWidth = targetWidth;
      expectedHeight = targetHeight;
    } else {
      float densityMultiplier = isScaling(options)
          ? (float) options.inTargetDensity / options.inDensity : 1f;
      int sampleSize = options.inSampleSize;
      int downsampledWidth = (int) Math.ceil(sourceWidth / (float) sampleSize);
      int downsampledHeight = (int) Math.ceil(sourceHeight / (float) sampleSize);
      expectedWidth = Math.round(downsampledWidth * densityMultiplier);
      expectedHeight = Math.round(downsampledHeight * densityMultiplier);

      if (Log.isLoggable(TAG, Log.VERBOSE)) {
        Log.v(TAG, "Calculated target [" + expectedWidth + "x" + expectedHeight + "] for source"
            + " [" + sourceWidth + "x" + sourceHeight + "]"
            + ", sampleSize: " + sampleSize
            + ", targetDensity: " + options.inTargetDensity
            + ", density: " + options.inDensity
            + ", density multiplier: " + densityMultiplier);
      }
    }
    // If this isn't an image, or BitmapFactory was unable to parse the size, width and height
    // will be -1 here.
    if (expectedWidth > 0 && expectedHeight > 0) {
      setInBitmap(options, bitmapPool, expectedWidth, expectedHeight);
    }
  }
  Bitmap downsampled = decodeStream(is, options, callbacks);
  callbacks.onDecodeComplete(bitmapPool, downsampled);

  if (Log.isLoggable(TAG, Log.VERBOSE)) {
    logDecode(sourceWidth, sourceHeight, sourceMimeType, options, downsampled,
        requestedWidth, requestedHeight);
  }

  Bitmap rotated = null;
  if (downsampled != null) {
    // If we scaled, the Bitmap density will be our inTargetDensity. Here we correct it back to
    // the expected density dpi.
    downsampled.setDensity(displayMetrics.densityDpi);

    rotated = TransformationUtils.rotateImageExif(bitmapPool, downsampled, orientation);
    if (!downsampled.equals(rotated)) {
      bitmapPool.put(downsampled);
    }
  }

  return rotated;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:80,代码来源:Downsampler.java

示例11: setIconBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public void setIconBitmap(Bitmap bitmap) {
    if (!bitmap.equals(mIconBitmap)) {
        mIconBitmap = bitmap;
        invalidateView();
    }
}
 
开发者ID:JackWHLiu,项目名称:jackknife,代码行数:7,代码来源:ShadeView.java


注:本文中的android.graphics.Bitmap.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。