Search in sources :

Example 96 with Bitmap

use of android.graphics.Bitmap in project android_frameworks_base by ParanoidAndroid.

the class SlidingDrawer method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    final long drawingTime = getDrawingTime();
    final View handle = mHandle;
    final boolean isVertical = mVertical;
    drawChild(canvas, handle, drawingTime);
    if (mTracking || mAnimating) {
        final Bitmap cache = mContent.getDrawingCache();
        if (cache != null) {
            if (isVertical) {
                canvas.drawBitmap(cache, 0, handle.getBottom(), null);
            } else {
                canvas.drawBitmap(cache, handle.getRight(), 0, null);
            }
        } else {
            canvas.save();
            canvas.translate(isVertical ? 0 : handle.getLeft() - mTopOffset, isVertical ? handle.getTop() - mTopOffset : 0);
            drawChild(canvas, mContent, drawingTime);
            canvas.restore();
        }
    } else if (mExpanded) {
        drawChild(canvas, mContent, drawingTime);
    }
}
Also used : Bitmap(android.graphics.Bitmap) View(android.view.View)

Example 97 with Bitmap

use of android.graphics.Bitmap in project android_frameworks_base by ParanoidAndroid.

the class NinePatchDrawable method inflate.

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);
    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.NinePatchDrawable);
    final int id = a.getResourceId(com.android.internal.R.styleable.NinePatchDrawable_src, 0);
    if (id == 0) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
    }
    final boolean dither = a.getBoolean(com.android.internal.R.styleable.NinePatchDrawable_dither, DEFAULT_DITHER);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    if (dither) {
        options.inDither = false;
    }
    options.inScreenDensity = r.getDisplayMetrics().noncompatDensityDpi;
    final Rect padding = new Rect();
    final Rect opticalInsets = new Rect();
    Bitmap bitmap = null;
    try {
        final TypedValue value = new TypedValue();
        final InputStream is = r.openRawResource(id, value);
        bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options);
        is.close();
    } catch (IOException e) {
    // Ignore
    }
    if (bitmap == null) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
    } else if (bitmap.getNinePatchChunk() == null) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image");
    }
    setNinePatchState(new NinePatchState(new NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"), padding, opticalInsets, dither), r);
    mNinePatchState.mTargetDensity = mTargetDensity;
    a.recycle();
}
Also used : Rect(android.graphics.Rect) InputStream(java.io.InputStream) NinePatch(android.graphics.NinePatch) IOException(java.io.IOException) Paint(android.graphics.Paint) Bitmap(android.graphics.Bitmap) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BitmapFactory(android.graphics.BitmapFactory) TypedValue(android.util.TypedValue)

Example 98 with Bitmap

use of android.graphics.Bitmap in project android_frameworks_base by ParanoidAndroid.

the class Allocation method copy2DRangeFrom.

/**
     * Copy a {@link android.graphics.Bitmap} into an Allocation.  The height
     * and width of the update will use the height and width of the {@link
     * android.graphics.Bitmap}.
     *
     * @param xoff X offset of the region to update in this Allocation
     * @param yoff Y offset of the region to update in this Allocation
     * @param data the Bitmap to be copied
     */
public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) {
    mRS.validate();
    if (data.getConfig() == null) {
        Bitmap newBitmap = Bitmap.createBitmap(data.getWidth(), data.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(newBitmap);
        c.drawBitmap(data, 0, 0, null);
        copy2DRangeFrom(xoff, yoff, newBitmap);
        return;
    }
    validateBitmapFormat(data);
    validate2DRange(xoff, yoff, data.getWidth(), data.getHeight());
    mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 99 with Bitmap

use of android.graphics.Bitmap in project android_frameworks_base by ParanoidAndroid.

the class Allocation method createFromBitmapResource.

/**
     * Creates an Allocation from the Bitmap referenced
     * by resource ID.
     *
     * @param rs Context to which the allocation will belong.
     * @param res application resources
     * @param id resource id to load the data from
     * @param mips specifies desired mipmap behaviour for the
     *             allocation
     * @param usage bit field specifying how the allocation is
     *              utilized
     *
     * @return Allocation containing resource data
     *
     */
public static Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, MipmapControl mips, int usage) {
    rs.validate();
    if ((usage & (USAGE_SHARED | USAGE_IO_INPUT | USAGE_IO_OUTPUT)) != 0) {
        throw new RSIllegalArgumentException("Unsupported usage specified.");
    }
    Bitmap b = BitmapFactory.decodeResource(res, id);
    Allocation alloc = createFromBitmap(rs, b, mips, usage);
    b.recycle();
    return alloc;
}
Also used : Bitmap(android.graphics.Bitmap)

Example 100 with Bitmap

use of android.graphics.Bitmap in project android_frameworks_base by ParanoidAndroid.

the class RemoteControlClient method scaleBitmapIfTooBig.

//===========================================================
// Internal utilities
/**
     * Scale a bitmap to fit the smallest dimension by uniformly scaling the incoming bitmap.
     * If the bitmap fits, then do nothing and return the original.
     *
     * @param bitmap
     * @param maxWidth
     * @param maxHeight
     * @return
     */
private Bitmap scaleBitmapIfTooBig(Bitmap bitmap, int maxWidth, int maxHeight) {
    if (bitmap != null) {
        final int width = bitmap.getWidth();
        final int height = bitmap.getHeight();
        if (width > maxWidth || height > maxHeight) {
            float scale = Math.min((float) maxWidth / width, (float) maxHeight / height);
            int newWidth = Math.round(scale * width);
            int newHeight = Math.round(scale * height);
            Bitmap.Config newConfig = bitmap.getConfig();
            if (newConfig == null) {
                newConfig = Bitmap.Config.ARGB_8888;
            }
            Bitmap outBitmap = Bitmap.createBitmap(newWidth, newHeight, newConfig);
            Canvas canvas = new Canvas(outBitmap);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setFilterBitmap(true);
            canvas.drawBitmap(bitmap, null, new RectF(0, 0, outBitmap.getWidth(), outBitmap.getHeight()), paint);
            bitmap = outBitmap;
        }
    }
    return bitmap;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

Bitmap (android.graphics.Bitmap)3662 Canvas (android.graphics.Canvas)875 Paint (android.graphics.Paint)697 BitmapDrawable (android.graphics.drawable.BitmapDrawable)447 IOException (java.io.IOException)384 Rect (android.graphics.Rect)338 Test (org.junit.Test)255 File (java.io.File)253 Matrix (android.graphics.Matrix)250 Drawable (android.graphics.drawable.Drawable)241 BitmapFactory (android.graphics.BitmapFactory)236 View (android.view.View)220 ImageView (android.widget.ImageView)205 FileOutputStream (java.io.FileOutputStream)182 Intent (android.content.Intent)177 InputStream (java.io.InputStream)165 FileNotFoundException (java.io.FileNotFoundException)150 RectF (android.graphics.RectF)148 Point (android.graphics.Point)146 Uri (android.net.Uri)117