Java Code Examples for android.graphics.Bitmap.recycle()

The following are Jave code examples for showing how to use recycle() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: buildAPKsApps   File: TextureHelper.java   View Source Code Vote up 5 votes
public static int loadTexture(final Context context, final int resourceId)
{
	final int[] textureHandle = new int[1];
	
	GLES20.glGenTextures(1, textureHandle, 0);
	
	if (textureHandle[0] != 0)
	{
		final BitmapFactory.Options options = new BitmapFactory.Options();
		options.inScaled = false;	// No pre-scaling

		// Read in the resource
		final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
					
		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		
		// Set filtering
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
		
		// Load the bitmap into the bound texture.
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		
		// Recycle the bitmap, since its data has been loaded into OpenGL.
		bitmap.recycle();						
	}
	
	if (textureHandle[0] == 0)
	{
		throw new RuntimeException("Error loading texture.");
	}
	
	return textureHandle[0];
}
 
Example 2
Project: weex-3d-map   File: ViewfinderView.java   View Source Code Vote up 5 votes
public void drawViewfinder() {
  Bitmap resultBitmap = this.resultBitmap;
  this.resultBitmap = null;
  if (resultBitmap != null) {
    resultBitmap.recycle();
  }
  invalidate();
}
 
Example 3
Project: aos-MediaLib   File: LoadTaskExecutor.java   View Source Code Vote up 5 votes
public void run() {
    ImageView view = mTaskItem.getViewIfValid();
    if (view != null) {
        mTaskItem.putThreadMapping();
        // get bitmap
        mTaskItem.imageProcessor.loadBitmap(mTaskItem);
        Bitmap bitmap = mTaskItem.result.bitmap;

        // debug sleep
        if (mTaskItem.sleep) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }

        // after loading check again if task is valid
        boolean useBitmap = false;
        if (!Thread.interrupted() && mTaskItem.getViewIfValid() != null) {
            useBitmap = true;
            if (mTaskItem.cache != null && bitmap != null) {
                // cache does not like null, so don't put that there
                mTaskItem.cache.put(mTaskItem.key, bitmap);
            }
            mTaskItem.reply.obj = mTaskItem;
            mTaskItem.reply.sendToTarget();
        }
        if (!useBitmap && bitmap != null) {
            bitmap.recycle();
        }

        mTaskItem.removeThreadMapping();
    }
}
 
Example 4
Project: Android-Demo_ImageCroper   File: BitmapCroppingWorkerTask.java   View Source Code Vote up 5 votes
/**
 * Crop image in background.
 *
 * @param params ignored
 * @return the decoded bitmap data
 */
@Override
protected BitmapCroppingWorkerTask.Result doInBackground(Void... params) {
    try {
        if (!isCancelled()) {

            BitmapUtils.BitmapSampled bitmapSampled;
            if (mUri != null) {
                bitmapSampled = BitmapUtils.cropBitmap(mContext, mUri, mCropPoints, mDegreesRotated, mOrgWidth, mOrgHeight,
                        mFixAspectRatio, mAspectRatioX, mAspectRatioY, mReqWidth, mReqHeight);
            } else if (mBitmap != null) {
                bitmapSampled = BitmapUtils.cropBitmapObjectHandleOOM(mBitmap, mCropPoints, mDegreesRotated, mFixAspectRatio, mAspectRatioX, mAspectRatioY);
            } else {
                return new Result((Bitmap) null, 1);
            }

            Bitmap bitmap = BitmapUtils.resizeBitmap(bitmapSampled.bitmap, mReqWidth, mReqHeight, mReqSizeOptions);

            if (mSaveUri == null) {
                return new Result(bitmap, bitmapSampled.sampleSize);
            } else {
                BitmapUtils.writeBitmapToUri(mContext, bitmap, mSaveUri, mSaveCompressFormat, mSaveCompressQuality);
                if (bitmap != null) {
                    bitmap.recycle();
                }
                return new Result(mSaveUri, bitmapSampled.sampleSize);
            }
        }
        return null;
    } catch (Exception e) {
        return new Result(e, mSaveUri != null);
    }
}
 
Example 5
Project: LJFramework   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 添加倒影
 *
 * @param src 源图片的
 * @param reflectionHeight 倒影高度
 * @param recycle 是否回收
 * @return 带倒影图片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) {
        return null;
    }
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight -
            reflectionHeight, srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth,
            srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0,
            srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight, 0,
            ret.getHeight() +
                    REFLECTION_GAP, 0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0,
            srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) {
        reflectionBitmap.recycle();
    }
    if (recycle && !src.isRecycled()) {
        src.recycle();
    }
    return ret;
}
 
Example 6
Project: ReadMark   File: DotView.java   View Source Code Vote up 5 votes
/**
 * 把bitmap变圆
 *
 * @param bitmap
 * @return
 */
private Bitmap getCircleBitmap(Bitmap bitmap) {
    //创建一个Bitmap,准备在上面作画
    Bitmap base = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(base);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    //防抖动
    paint.setDither(true);

    //先在base上画一个圆
    canvas.drawCircle(getMeasuredWidth() / 2
            , getMeasuredHeight() / 2
            , getMeasuredWidth() / 2, paint);
    //设置为SRC_IN
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    //再在base上画上传进来的bitmap,注意坐标对应(这里从原点开始)
    canvas.drawBitmap(bitmap, 0, 0, paint);

    //回收
    bitmap.recycle();
    bitmap = null;
    return base;
}
 
Example 7
Project: editor-sql   File: FeThumbUtils.java   View Source Code Vote up 5 votes
private static Bitmap getImageThumbnail(String imagePath, int width, int height) {
    Bitmap bitmap = null;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;

    try {
        bitmap = BitmapFactory.decodeFile(imagePath, options);

        int h = options.outHeight;
        int w = options.outWidth;
        int beWidth = w / width;
        int beHeight = h / height;
        int be;
        if (beWidth < beHeight) {
            be = beWidth;
        } else {
            be = beHeight;
        }
        if (be <= 0) {
            be = 1;
        }
        options.inSampleSize = be;
        options.inJustDecodeBounds = false;

        bitmap = BitmapFactory.decodeFile(imagePath, options);
        bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
                ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    } catch (OutOfMemoryError e) {
        if (bitmap != null) {
            bitmap.recycle();
        }
    }

    return bitmap;
}
 
Example 8
Project: AndroidUtilCode-master   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 按质量压缩
 *
 * @param src         源图片
 * @param maxByteSize 允许最大值字节数
 * @param recycle     是否回收
 * @return 质量压缩压缩过的图片
 */
public static Bitmap compressByQuality(Bitmap src, long maxByteSize, boolean recycle) {
    if (isEmptyBitmap(src) || maxByteSize <= 0) return null;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int quality = 100;
    src.compress(CompressFormat.JPEG, quality, baos);
    while (baos.toByteArray().length > maxByteSize && quality > 0) {
        baos.reset();
        src.compress(CompressFormat.JPEG, quality -= 5, baos);
    }
    if (quality < 0) return null;
    byte[] bytes = baos.toByteArray();
    if (recycle && !src.isRecycled()) src.recycle();
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}
 
Example 9
Project: Open-Quran-Radio   File: ImageHelper.java   View Source Code Vote up 5 votes
public static Bitmap TransformToRounded(Bitmap source, Context mContext, int width, int heigth) {
    // Create the RoundedBitmapDrawable.
    RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), source);
    drawable.setCircular(true);
    //drawable.setCornerRadius(mContext.getCornerRadius(source));
    Bitmap output = Bitmap.createBitmap(width, heigth, source.getConfig());
    Canvas canvas = new Canvas(output);
    drawable.setAntiAlias(true);
    drawable.setBounds(0, 0, width, heigth);
    drawable.draw(canvas);
    if (source != output) {
        source.recycle();
    }
    return output;
}
 
Example 10
Project: GongXianSheng   File: ImageUtils.java   View Source Code Vote up 5 votes
public static String getScaledImage(Context paramContext, String paramString, int paramInt)
{
	File localFile1 = new File(paramString);
	if (localFile1.exists())
	{
		long l = localFile1.length();
		if (l > 102400L*5)
		{
			Bitmap localBitmap = decodeScaleImage(paramString, SCALE_IMAGE_WIDTH, SCALE_IMAGE_HEIGHT);
			try
			{
				File localFile2 = new File(paramContext.getExternalCacheDir(), "eaemobTemp" + paramInt + ".jpg");
				FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
				localBitmap.compress(Bitmap.CompressFormat.JPEG, 60, localFileOutputStream);
				localFileOutputStream.close();
				return localFile2.getAbsolutePath();
			}
			catch (Exception localException)
			{
				localException.printStackTrace();
			}
			finally{
				if ( localBitmap != null && !localBitmap.isRecycled()) {
					localBitmap.recycle();
					localBitmap = null ;
				}
			}
		}
	}
	return paramString;
}
 
Example 11
Project: ASS   File: ScreenShotContentObserver.java   View Source Code Vote up 5 votes
public static void resultProcess(Context context, Bitmap bitmap, String fileName) throws Exception {
    String text = WATERMARK;
    for (int i = 0; i < 700; i++) {
        text += " " + WATERMARK;
    }
    Bitmap newBitmap = Util.getOverlayBitmap(context, bitmap, text);
    bitmap.recycle();
    newBitmap = Util.getOverlayBitmap2(context, newBitmap, "Hello. Capture with Android Screenshot Service :)");
    Util.saveImage(context, newBitmap, fileName);
    newBitmap.recycle();
}
 
Example 12
Project: GitHub   File: BitmapPool.java   View Source Code Vote up 4 votes
/**
 * Frees the bitmap
 * @param value the bitmap to free
 */
@Override
protected void free(Bitmap value) {
  Preconditions.checkNotNull(value);
  value.recycle();
}
 
Example 13
Project: airgram   File: ImageLoader.java   View Source Code Vote up 4 votes
private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway) throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    location.local_id = UserConfig.lastLocalId;
    UserConfig.lastLocalId--;
    TLRPC.PhotoSize size = new TLRPC.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
Example 14
Project: FireFiles   File: ImageUtils.java   View Source Code Vote up 4 votes
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;
}
 
Example 15
Project: KrGallery   File: ImageLoader.java   View Source Code Vote up 4 votes
private static PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW,
        float photoH, float scaleFactor, int quality, boolean cache, boolean scaleAnyway)
        throws Exception {
    Bitmap scaledBitmap;
    if (scaleFactor > 1 || scaleAnyway) {
        scaledBitmap = Bitmaps.createScaledBitmap(bitmap, w, h, true);
    } else {
        scaledBitmap = bitmap;
    }

    FileLocation.TL_fileLocation location = new FileLocation.TL_fileLocation();
    location.volume_id = Integer.MIN_VALUE;
    location.dc_id = Integer.MIN_VALUE;
    PhotoSize size = new PhotoSize.TL_photoSize();
    size.location = location;
    size.w = scaledBitmap.getWidth();
    size.h = scaledBitmap.getHeight();
    if (size.w <= 100 && size.h <= 100) {
        size.type = "s";
    } else if (size.w <= 320 && size.h <= 320) {
        size.type = "m";
    } else if (size.w <= 800 && size.h <= 800) {
        size.type = "x";
    } else if (size.w <= 1280 && size.h <= 1280) {
        size.type = "y";
    } else {
        size.type = "w";
    }

    String fileName = location.volume_id + "_" + location.local_id + ".jpg";
    final File cacheFile = new File(
            FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
    FileOutputStream stream = new FileOutputStream(cacheFile);
    scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
    if (cache) {
        ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
        scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream2);
        size.bytes = stream2.toByteArray();
        size.size = size.bytes.length;
        stream2.close();
    } else {
        size.size = (int) stream.getChannel().size();
    }
    stream.close();
    if (scaledBitmap != bitmap) {
        scaledBitmap.recycle();
    }

    return size;
}
 
Example 16
Project: GitHub   File: ImageRequest.java   View Source Code Vote up 4 votes
/**
 * The real guts of parseNetworkResponse. Broken out for readability.
 */
private Response<Bitmap> doParse(NetworkResponse response) {
    byte[] data = response.data;
    BitmapFactory.Options decodeOptions = new BitmapFactory.Options();
    Bitmap bitmap = null;
    if (mMaxWidth == 0 && mMaxHeight == 0) {
        decodeOptions.inPreferredConfig = mDecodeConfig;
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, decodeOptions);
    } else {
        // If we have to resize this image, first get the natural bounds.
        decodeOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeByteArray(data, 0, data.length, 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;
        // TODO(ficus): Do we need this or is it okay since API 8 doesn't support it?
        // decodeOptions.inPreferQualityOverSpeed = PREFER_QUALITY_OVER_SPEED;
        decodeOptions.inSampleSize =
            findBestSampleSize(actualWidth, actualHeight, desiredWidth, desiredHeight);
        Bitmap tempBitmap =
            BitmapFactory.decodeByteArray(data, 0, data.length, 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;
        }
    }

    if (bitmap == null) {
        return Response.error(new ParseError(response));
    } else {
        return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
    }
}
 
Example 17
Project: aos-MediaLib   File: BitmapUtils.java   View Source Code Vote up 4 votes
/**
* Scale the original image uniformly so that both dimensions of the resized image will be
* equal or larger than the display area, then crop the parts outside the destination image.
*/
public static Bitmap scaleThumbnailCenterCrop(Bitmap original, int displayWidth, int displayHeight) {
    Bitmap thumb;
    float scale;
    Matrix matrix = new Matrix();

    // Compute the destination bitmap aspect ratio
    final float displayAspectRatio = (float) displayWidth / displayHeight;

    // Check if the source bitmap is wider or higher than the expected aspect ratio
    final int originalWidth = original.getWidth();
    final int originalHeight = original.getHeight();
    if (DBG) Log.d(TAG, "Source size =" + originalWidth + "x" + originalHeight);

    final float ratio = (float) originalWidth / originalHeight;
    if (ratio < displayAspectRatio) {
        // The source bitmap is higher than the display area => resize the bitmap
        // to match the width of the display area and crop the top and bottom areas
        scale = (float) displayWidth / originalWidth;
    }
    else {
        // The source bitmap is wider than the display area => resize the bitmap
        // to match the height of the display area and crop the left and right parts
        scale = (float) displayHeight / originalHeight;
    }
    matrix.setScale(scale, scale);
    final Bitmap resized = Bitmap.createBitmap(original, 0, 0, originalWidth, originalHeight, matrix, true);
    // Free the original bitmap ASAP if we made a copy (Caution!!! createBitmap() doesn't always make a copy)
    if (resized != original) {
        original.recycle();
    }

    // Get the size of the resized thumbnail
    final int resizedWidth = resized.getWidth();
    final int resizedHeight = resized.getHeight();
    if (DBG) Log.d(TAG, "resized thumbnail size=" + resizedWidth + "x" + resizedHeight);

    // Compute the offset of the resized thumbnail so that it is centered with the the destination bitmap
    int xOffset = 0;
    int yOffset = 0;
    if (resizedWidth > displayWidth) {
        xOffset = (int) ((resizedWidth - displayWidth) / 2);
    }
    if (resizedHeight > displayHeight) {
        yOffset = (int) ((resizedHeight - displayHeight) / 2);
    }
    if (DBG) Log.d(TAG, "resized thumbnail position in destination bitmap : xOffset=" + xOffset + " yOffset=" + yOffset);

    // Copy the resized thumbnail cropped to the destination bitmap
    thumb = Bitmap.createBitmap(resized, xOffset, yOffset, displayWidth, displayHeight);
    // Free the original bitmap ASAP if we made a copy (Caution!!! createBitmap() doesn't always make a copy)
    if (thumb != resized) {
        resized.recycle();
    }

    return thumb;
}
 
Example 18
Project: boohee_v5.6   File: CustomHandler.java   View Source Code Vote up 4 votes
protected byte[] getThumbByteArray(UMediaObject uMediaObject) {
    if (uMediaObject == null) {
        return null;
    }
    byte[] bArr;
    Object obj = "";
    if (uMediaObject instanceof UMusic) {
        UMusic uMusic = (UMusic) uMediaObject;
        obj = uMusic.getThumb();
        uMediaObject = uMusic.getThumbImage();
    } else if (uMediaObject instanceof UMVideo) {
        UMVideo uMVideo = (UMVideo) uMediaObject;
        obj = uMVideo.getThumb();
        uMediaObject = uMVideo.getThumbImage();
    } else if (uMediaObject instanceof UMWebPage) {
        UMWebPage uMWebPage = (UMWebPage) uMediaObject;
        obj = uMWebPage.getThumb();
        uMediaObject = uMWebPage.getThumbImage();
    } else if (uMediaObject instanceof UMImage) {
        UMImage uMImage = (UMImage) uMediaObject;
        if (!TextUtils.isEmpty(uMImage.getThumb())) {
            obj = uMImage.getThumb();
        } else if (uMImage.isUrlMedia()) {
            obj = uMImage.toUrl();
        }
    } else {
        uMediaObject = null;
    }
    if (uMediaObject != null && uMediaObject.isUrlMedia()) {
        obj = uMediaObject.toUrl();
    }
    if (!TextUtils.isEmpty(obj)) {
        Bitmap bitmapFromFile = BitmapUtils.getBitmapFromFile(obj, this.mThumbSize, this
                .mThumbSize);
        if (!(bitmapFromFile == null || bitmapFromFile.isRecycled())) {
            byte[] bitmap2Bytes = BitmapUtils.bitmap2Bytes(bitmapFromFile);
            bitmapFromFile.recycle();
            bArr = bitmap2Bytes;
            if ((bArr == null && bArr.length != 0) || uMediaObject == null || uMediaObject
                    .isUrlMedia()) {
                return bArr;
            }
            return uMediaObject.toByte();
        }
    }
    bArr = null;
    if (bArr == null) {
    }
    return uMediaObject.toByte();
}
 
Example 19
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 旋转图片
 *
 * @param src     源图片
 * @param degrees 旋转角度
 * @param px      旋转点横坐标
 * @param py      旋转点纵坐标
 * @param recycle 是否回收
 * @return 旋转后的图片
 */
public static Bitmap rotate(Bitmap src, int degrees, float px, float py, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    if (degrees == 0) return src;
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
Example 20
Project: RLibrary   File: ImageUtils.java   View Source Code Vote up 3 votes
/**
 * 倾斜图片
 *
 * @param src     源图片
 * @param kx      倾斜因子x
 * @param ky      倾斜因子y
 * @param px      平移因子x
 * @param py      平移因子y
 * @param recycle 是否回收
 * @return 倾斜后的图片
 */
public static Bitmap skew(Bitmap src, float kx, float ky, float px, float py, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    Matrix matrix = new Matrix();
    matrix.setSkew(kx, ky, px, py);
    Bitmap ret = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}