Java Code Examples for android.graphics.Bitmap#equals()
The following examples show how to use
android.graphics.Bitmap#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitmapTransformation.java From giffun with Apache License 2.0 | 6 votes |
@Override public final Resource<Bitmap> transform(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"); } 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; }
Example 2
Source File: LoginShare.java From LoginSharePay with Apache License 2.0 | 6 votes |
@Override protected WebpageObject getMediaObject(WeiboMessageBody weiboMessageBody) { WebpageObject mediaObject = new WebpageObject(); mediaObject.identify = Utility.generateGUID(); mediaObject.title = weiboMessageBody.getTitle(); mediaObject.description = weiboMessageBody.getDescription(); // 设置 Bitmap 类型的图片到视频对象里 设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。 Bitmap bmp = BitmapFactory.decodeFile(weiboMessageBody.getLocalImage()); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, Util.THUMB_SIZE, Util.THUMB_SIZE, true); if (!bmp.equals(thumbBmp)) bmp.recycle(); mediaObject.setThumbImage(thumbBmp); mediaObject.actionUrl = weiboMessageBody.getActionUrl(); mediaObject.defaultText = "Webpage 默认文案"; return mediaObject; }
Example 3
Source File: ShareImpl.java From LoginSharePay with Apache License 2.0 | 6 votes |
@Override protected BaseReq buildImageWeChatMessageBody(WechatMessageBody wechatMessageBody) { SendMessageToWX.Req req = new SendMessageToWX.Req(); Bitmap bmp = BitmapFactory.decodeFile(wechatMessageBody.getLocalImage()); WXImageObject imgObj = new WXImageObject(bmp); WXMediaMessage msg = new WXMediaMessage(); msg.mediaObject = imgObj; Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, Util.THUMB_SIZE, Util.THUMB_SIZE, true); if (!bmp.equals(thumbBmp)) bmp.recycle(); msg.thumbData = Util.bmpToByteArray(thumbBmp, true); req.transaction = Util.buildTransaction("img"); req.message = msg; req.scene = getWecahtTargetScene(wechatMessageBody); return req; }
Example 4
Source File: ShareImpl.java From LoginSharePay with Apache License 2.0 | 6 votes |
@Override protected BaseReq buildMusicWeChatMessageBody(WechatMessageBody wechatMessageBody) { SendMessageToWX.Req req = new SendMessageToWX.Req(); WXMusicObject music = new WXMusicObject(); music.musicUrl = wechatMessageBody.getMusicUrl(); WXMediaMessage msg = new WXMediaMessage(); msg.mediaObject = music; msg.title = wechatMessageBody.getTitle(); msg.description = wechatMessageBody.getDescription(); Bitmap bmp = BitmapFactory.decodeFile(wechatMessageBody.getLocalImage()); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, Util.THUMB_SIZE, Util.THUMB_SIZE, true); if (!bmp.equals(thumbBmp)) bmp.recycle(); msg.thumbData = Util.bmpToByteArray(thumbBmp, true); req.transaction = Util.buildTransaction("music"); req.message = msg; req.scene = getWecahtTargetScene(wechatMessageBody); return req; }
Example 5
Source File: Purity.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
public boolean checkRenderView(AmazonWebView view) { if(state == null) { setBitmap(view); return false; } else { Picture p = view.capturePicture(); Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888); boolean result = newState.equals(state); newState.recycle(); return result; } }
Example 6
Source File: ShareImpl.java From LoginSharePay with Apache License 2.0 | 6 votes |
@Override protected BaseReq buildWebWeChatMessageBody(WechatMessageBody wechatMessageBody) { SendMessageToWX.Req req = new SendMessageToWX.Req(); WXWebpageObject webpage = new WXWebpageObject(); webpage.webpageUrl = wechatMessageBody.getWebpageUrl(); WXMediaMessage msg = new WXMediaMessage(webpage); msg.title = wechatMessageBody.getTitle(); msg.description = wechatMessageBody.getDescription(); Bitmap bmp = BitmapFactory.decodeFile(wechatMessageBody.getLocalImage()); Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, Util.THUMB_SIZE, Util.THUMB_SIZE, true); if (!bmp.equals(thumbBmp)) bmp.recycle(); msg.thumbData = Util.bmpToByteArray(thumbBmp, true); req.transaction = Util.buildTransaction("webpage"); req.message = msg; req.scene = getWecahtTargetScene(wechatMessageBody); return req; }
Example 7
Source File: MediaUtils.java From q-municate-android with Apache License 2.0 | 6 votes |
/** * Allows to fix issue for some phones when image processed with android-crop * is not rotated properly. * Should be used in non-UI thread. */ public static void normalizeRotationImageIfNeed(File file) { Context context = App.getInstance().getApplicationContext(); String filePath = file.getPath(); Uri uri = getValidUri(file, context); try { ExifInterface exif = new ExifInterface(filePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); Bitmap rotatedBitmap = rotateBitmap(bitmap, orientation); if (!bitmap.equals(rotatedBitmap)) { saveBitmapToFile(context, rotatedBitmap, uri); } } catch (Exception e) { ErrorUtils.logError("Exception:", e.getMessage()); } }
Example 8
Source File: BitmapUtil.java From HaoReader with GNU General Public License v3.0 | 6 votes |
/** * 设置固定的宽度,高度随之变化,使图片不会变形 */ public static Bitmap fitBitmap(Bitmap target, int newWidth) { if(target == null){ return null; } int width = target.getWidth(); int height = target.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) newWidth) / width; // float scaleHeight = ((float)newHeight) / height; int newHeight = (int) (scaleWidth * height); matrix.postScale(scaleWidth, scaleWidth); // Bitmap result = Bitmap.createBitmap(target,0,0,width,height, // matrix,true); Bitmap bmp = Bitmap.createBitmap(target, 0, 0, width, height, matrix, true); if (!target.equals(bmp) && !target.isRecycled()) { target.recycle(); target = null; } return bmp; }
Example 9
Source File: BitmapUtil.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
/** * 设置固定的宽度,高度随之变化,使图片不会变形 */ public static Bitmap fitBitmap(Bitmap target, int newWidth) { int width = target.getWidth(); int height = target.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) newWidth) / width; // float scaleHeight = ((float)newHeight) / height; matrix.postScale(scaleWidth, scaleWidth); // Bitmap result = Bitmap.createBitmap(target,0,0,width,height, // matrix,true); Bitmap bmp = Bitmap.createBitmap(target, 0, 0, width, height, matrix, true); if (!target.equals(bmp) && !target.isRecycled()) { target.recycle(); } return bmp;// Bitmap.createBitmap(target, 0, 0, width, height, matrix, // true); }
Example 10
Source File: RoundedTransformationBuilder.java From ClipCircleHeadLikeQQ with Apache License 2.0 | 6 votes |
/** * 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; } }; }
Example 11
Source File: BitmapUtil.java From a with GNU General Public License v3.0 | 6 votes |
/** * 缩放Bitmap满屏 */ public static Bitmap getBitmap(Bitmap bitmap, int screenWidth, int screenHeight) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); float scale = (float) screenWidth / w; float scale2 = (float) screenHeight / h; // scale = scale < scale2 ? scale : scale2; matrix.postScale(scale, scale); Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); if (!bitmap.equals(bmp) && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; } return bmp;// Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); }
Example 12
Source File: RoundedTransformationBuilder.java From Loop with Apache License 2.0 | 6 votes |
/** * 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; } }; }
Example 13
Source File: BitmapUtils.java From CameraCardCropDemo with Apache License 2.0 | 5 votes |
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; }
Example 14
Source File: BitmapLoader.java From aurora-imui with MIT License | 5 votes |
public static Bitmap imageCropWithRect(Bitmap bitmap) { if (bitmap == null) { return null; } int w = bitmap.getWidth(); // 得到图片的宽,高 int h = bitmap.getHeight(); int nw, nh, retX, retY; if (w > h) { nw = h / 2; nh = h; retX = (w - nw) / 2; retY = 0; } else { nw = w / 2; nh = (h - w) / 2; retX = w / 4; retY = (int) (h - 0.95 * w); } // 下面这句是关键 Bitmap bmp = Bitmap.createBitmap(bitmap, retX, retY, nw, nh, null, false); if (bitmap != null && !bitmap.equals(bmp) && !bitmap.isRecycled()) { bitmap.recycle(); bitmap = null; } return bmp; }
Example 15
Source File: CircleTransform.java From px-android with MIT License | 5 votes |
@Override public Bitmap transform(@NonNull final Bitmap source) { final int size = Math.min(source.getWidth(), source.getHeight()); final int x = (source.getWidth() - size) / 2; final int y = (source.getHeight() - size) / 2; final Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (!squaredBitmap.equals(source)) { source.recycle(); } final Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; final Bitmap bitmap = Bitmap.createBitmap(size, size, config); final Canvas canvas = new Canvas(bitmap); final Paint paint = new Paint(); final BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); final float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
Example 16
Source File: BitmapHelper.java From libcommon with Apache License 2.0 | 5 votes |
@NonNull public static Bitmap copyBitmap(@NonNull final Bitmap src, Bitmap dest) { if (dest == null) { dest = Bitmap.createBitmap(src); } else if (!src.equals(dest)) { final Canvas canvas = new Canvas(dest); canvas.setBitmap(src); } return dest; }
Example 17
Source File: KSYTextureView.java From KSYMediaPlayer_Android with Apache License 2.0 | 4 votes |
private Bitmap getBitmap(IMediaPlayer mediaPlayer) { float scaleX = 1.0f; float scaleY = 1.0f; int frame_width = 0; int frame_height = 0; if (mTextureView == null) return null; if (mediaPlayer != null) { frame_width = mediaPlayer.getVideoWidth(); frame_height = mediaPlayer.getVideoHeight(); } if (frame_height == 0 || frame_width == 0) return null; Bitmap origin = mTextureView.getBitmap(); if (origin == null) return null; int width = origin.getWidth(); int height = origin.getHeight(); int pivotPointX = (int) (frame_width / 2); int pivotPointY = (int) (frame_height / 2); scaleX = (float)frame_width/width; scaleY = (float)frame_height/height; Matrix matrix = new Matrix(); matrix.postScale(scaleX, scaleY, pivotPointX, pivotPointY); Bitmap newBM = Bitmap.createBitmap(origin, 0, 0, width, height, matrix, false); if (newBM.equals(origin)) { return newBM; } origin.recycle(); return newBM; }
Example 18
Source File: BitmapProcessor.java From Android-ImageManager with MIT License | 4 votes |
public static InputStream compressToFit(final Context context, Bitmap bitmap, final int maximumSizeInBytes, final int pixelBounds, final CompressFormat format, final int quality) { InputStream inputStream = null; try { // If the bitmap is within our size bounds, try an initial compression if (bitmap.getWidth() <= pixelBounds && bitmap.getHeight() <= pixelBounds) inputStream = BitmapProcessor.compress(bitmap, format, quality); // Re-scale image if width > widthBound float ceil = (float)Math.ceil(pixelBounds * 1.333); int rWidth = bitmap.getWidth(); int rHeight = bitmap.getHeight(); // If inputStream is null (too big) or the compressed bitmap is too large, downscale if (inputStream == null || inputStream.available() > maximumSizeInBytes) { Log.i(TAG, "Image is too large" + (inputStream != null ? (" (" + inputStream.available() / 1024 + "kb)") : "") + ", will be adjusted to " + pixelBounds + ", " + pixelBounds); do { // Adjust our ceiling ceil = (float)Math.ceil(ceil * .75f); final int fCeil = (int)ceil; Log.d(TAG, "compression attempt at " + fCeil + "x" + fCeil); // Downscale bitmap JobOptions options = new JobOptions(); options.requestedWidth = fCeil; options.requestedHeight = fCeil; options.scaleType = ScaleType.FIT_CENTER; Bitmap transformedBitmap = ImageUtil.transformBitmap(bitmap, options); // Store some data we need to access beyond the do{} block rWidth = transformedBitmap.getWidth(); rHeight = transformedBitmap.getHeight(); // If it's the same, something went wrong (out of mem), iterate here and try a smaller image if (transformedBitmap.equals(bitmap)) continue; // Recycle the Bitmap bitmap.recycle(); bitmap = null; // Compress to JPEG and get its input stream for uploading if (inputStream != null) inputStream.close(); inputStream = BitmapProcessor.compress(transformedBitmap, format, quality); // Lets use the transformedBitmap as our next source bitmap = transformedBitmap; transformedBitmap = null; // Yield to prevent the OS from killing us Thread.yield(); } while (inputStream.available() > maximumSizeInBytes); } Log.d(TAG, String.format("Resulting image of size: %d, %d - %dkb", rWidth, rHeight, inputStream != null ? (inputStream.available() / 1024) : 0)); } catch (final Exception e) { // IOException Log.e(TAG, "", e); } finally { if (bitmap != null) bitmap.recycle(); } return inputStream; }
Example 19
Source File: BitmapUtil.java From AndroidMathKeyboard with Apache License 2.0 | 4 votes |
/** * 根据宽高缩放bitmap,可以设置最大缩放值 * @param resource * @return */ public static Bitmap scaleImage(Bitmap resource,int reqWidth,int reqHeight,float maxScale,boolean isRecycleSrc) { if (resource == null || resource.isRecycled()){ return null; } // 获得图片的宽高 int width = resource.getWidth(); int height = resource.getHeight(); // Log.d("wdcloud","scaleImage---->缩放前:图片宽:" + width + ",目标宽:" + reqWidth + ";图片高:" + height + ",目标高:" + reqHeight); float scale = 1.0f; if (width > reqWidth && height <= reqHeight) { // 图片宽度大于控件宽度,图片高度小于控件高度 scale = reqWidth * 1.0f / width; }else if (height > reqHeight && width <= reqWidth) { // 图片高度度大于控件宽高,图片宽度小于控件宽度 scale = reqHeight * 1.0f / height; }else if (height > reqHeight && width > reqWidth) { // 图片宽度大于控件宽度,图片高度大于控件高度 scale = Math.min(reqHeight * 1.0f / height, reqWidth * 1.0f / width); }else if (height < reqHeight && width < reqWidth) { // 图片宽度小于控件宽度,图片高度小于控件高度 scale = Math.min(reqHeight * 1.0f / height, reqWidth * 1.0f / width); } if (maxScale != -1 && scale > maxScale){ scale = maxScale; // Logger.getLogger().d("scaleImage--->缩放值超过最大缩放值:scale:"+ scale +",maxScale:"+ maxScale); } // Log.d("wdcloud","scaleImage--->计算宽高后scale:" + scale); // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // 得到新的图片 Bitmap newBitmap = Bitmap.createBitmap(resource, 0, 0, width, height, matrix, true); if (newBitmap.equals(resource)){ return newBitmap; } if (isRecycleSrc) { resource.recycle(); } return newBitmap; }
Example 20
Source File: ImageViewPlus.java From BaseProject with Apache License 2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { Bitmap rawBitmap = getBitmap(getDrawable()); if (rawBitmap != null && mType != TYPE_NONE){ int viewWidth = getWidth(); int viewHeight = getHeight(); int viewMinSize = Math.min(viewWidth, viewHeight); float dstWidth = mType == TYPE_CIRCLE ? viewMinSize : viewWidth; float dstHeight = mType == TYPE_CIRCLE ? viewMinSize : viewHeight; float halfBorderWidth = mBorderWidth / 2.0f; float doubleBorderWidth = mBorderWidth * 2; if (mShader == null || !rawBitmap.equals(mRawBitmap)){ mRawBitmap = rawBitmap; mShader = new BitmapShader(mRawBitmap, TileMode.CLAMP, TileMode.CLAMP); } if (mShader != null) { mMatrix.setScale((dstWidth - doubleBorderWidth) / rawBitmap.getWidth(), (dstHeight - doubleBorderWidth) / rawBitmap.getHeight()); mShader.setLocalMatrix(mMatrix); } mPaintBitmap.setShader(mShader); mPaintBorder.setStyle(Paint.Style.STROKE); mPaintBorder.setStrokeWidth(mBorderWidth); mPaintBorder.setColor(mBorderWidth > 0 ? mBorderColor : Color.TRANSPARENT); if (mType == TYPE_CIRCLE){ float radius = viewMinSize / 2.0f; canvas.drawCircle(radius, radius, radius - halfBorderWidth, mPaintBorder); canvas.translate(mBorderWidth, mBorderWidth); canvas.drawCircle(radius - mBorderWidth, radius - mBorderWidth, radius - mBorderWidth, mPaintBitmap); } else if (mType == TYPE_ROUNDED_RECT){ mRectBorder.set(halfBorderWidth, halfBorderWidth, dstWidth - halfBorderWidth, dstHeight - halfBorderWidth); mRectBitmap.set(0.0f, 0.0f, dstWidth - doubleBorderWidth, dstHeight - doubleBorderWidth); float borderRadius = mRectRoundRadius - halfBorderWidth > 0.0f ? mRectRoundRadius - halfBorderWidth : 0.0f; float bitmapRadius = mRectRoundRadius - mBorderWidth > 0.0f ? mRectRoundRadius - mBorderWidth : 0.0f; canvas.drawRoundRect(mRectBorder, borderRadius, borderRadius, mPaintBorder); canvas.translate(mBorderWidth, mBorderWidth); canvas.drawRoundRect(mRectBitmap, bitmapRadius, bitmapRadius, mPaintBitmap); } } else { super.onDraw(canvas); } }