Android Open Source - bitmapfun Image Resizer






From Project

Back to project page bitmapfun.

License

The source code is released under:

Apache License

If you think the Android project bitmapfun listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2012 The Android Open Source Project
 */*from   w w  w .  j  a  v a2s  .com*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.bitmapfun.util;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.util.Log;

import com.example.android.bitampfun.BuildConfig;

import java.io.FileDescriptor;

/**
 * A simple subclass of {@link ImageWorker} that resizes images from resources given a target width
 * and height. Useful for when the input images might be too large to simply load directly into
 * memory.
 */
public class ImageResizer extends ImageWorker {
    private static final String TAG = "ImageResizer";

    /**
     * Initialize providing a single target image size (used for both width and height);
     *
     * @param context
     * @param imageWidth
     * @param imageHeight
     */
    public ImageResizer(Context context) {
        super(context);
    }

    /**
     * The main processing method. This happens in a background task. In this case we are just
     * sampling down the bitmap and returning it from a resource.
     *
     * @param resId
     * @return
     */
    private Bitmap processBitmap(int resId, int desiredWidth, int desiredHeight) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "processBitmap - " + resId);
        }
        return BitmapUtils.decodeSampledBitmapFromResource(mResources, resId, desiredWidth,
            desiredHeight, getImageCache());
    }

    @Override
    protected Bitmap processBitmap(BitmapData data) {
        return processBitmap(Integer.parseInt(String.valueOf(data.getData())), 
            data.getDesiredWidth(), data.getDesiredHeight());
    }


}




Java Source Code List

com.example.android.bitmapfun.util.AsyncTask.java
com.example.android.bitmapfun.util.BitmapData.java
com.example.android.bitmapfun.util.BitmapUtils.java
com.example.android.bitmapfun.util.DiskLruCache.java
com.example.android.bitmapfun.util.ImageCache.java
com.example.android.bitmapfun.util.ImageDetailActivity.java
com.example.android.bitmapfun.util.ImageDetailFragment.java
com.example.android.bitmapfun.util.ImageFetcher.java
com.example.android.bitmapfun.util.ImageResizer.java
com.example.android.bitmapfun.util.ImageSetFactory.java
com.example.android.bitmapfun.util.ImageSet.java
com.example.android.bitmapfun.util.ImageWorker.java
com.example.android.bitmapfun.util.RecyclingBitmapDrawable.java
com.example.android.bitmapfun.util.RecyclingImageView.java
com.example.android.bitmapfun.util.Utils.java