Back to project page bitmapfun.
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.
/* * 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()); } }