当前位置: 首页>>代码示例>>Java>>正文


Java Drawable.getIntrinsicWidth方法代码示例

本文整理汇总了Java中android.graphics.drawable.Drawable.getIntrinsicWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Drawable.getIntrinsicWidth方法的具体用法?Java Drawable.getIntrinsicWidth怎么用?Java Drawable.getIntrinsicWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.drawable.Drawable的用法示例。


在下文中一共展示了Drawable.getIntrinsicWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawableToBitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
private static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:robertlevonyan,项目名称:materialExpansionPanel,代码行数:22,代码来源:ExpandableUtils.java

示例2: drawableToBitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
public static Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap;

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:22,代码来源:ArtworkUtils.java

示例3: onDraw

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    Drawable[] drawables = getCompoundDrawables();
    if (drawables != null) {
        Drawable drawableLeft = drawables[0];
        if (drawableLeft != null) {
            float textWidth = getPaint().measureText(getText().toString());
            int drawablePadding = getCompoundDrawablePadding();
            int drawableWidth = 0;
            drawableWidth = drawableLeft.getIntrinsicWidth();
            float bodyWidth = textWidth + drawableWidth + drawablePadding;
            canvas.translate((getWidth() - bodyWidth) / 2 -20, 0);
        }
    }
    super.onDraw(canvas);
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:17,代码来源:DrawableCenterEditText.java

示例4: setIcon

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
public void setIcon(Drawable icon) {
    this.mIcon = icon;
    if (icon != null) {
        float scale;
        int width = icon.getIntrinsicWidth();
        int height = icon.getIntrinsicHeight();
        if (width > this.mMaxIconSize) {
            scale = ((float) this.mMaxIconSize) / ((float) width);
            width = this.mMaxIconSize;
            height = (int) (((float) height) * scale);
        }
        if (height > this.mMaxIconSize) {
            scale = ((float) this.mMaxIconSize) / ((float) height);
            height = this.mMaxIconSize;
            width = (int) (((float) width) * scale);
        }
        icon.setBounds(0, 0, width, height);
    }
    setCompoundDrawables(icon, null, null, null);
    updateTextButtonVisibility();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:22,代码来源:ActionMenuItemView.java

示例5: drawable2Bitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();

    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;

    Bitmap bitmap = Bitmap.createBitmap(w, h, config);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);

    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:20,代码来源:ACache.java

示例6: onDraw

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
    Drawable[] drawables = getCompoundDrawables();
    if (drawables != null) {
        Drawable drawableLeft = drawables[0];
        if (drawableLeft != null) {
            float textWidth = getPaint().measureText(getText().toString());
            int drawablePadding = getCompoundDrawablePadding();
            int drawableWidth = 0;
            drawableWidth = drawableLeft.getIntrinsicWidth();
            float bodyWidth = textWidth + drawableWidth + drawablePadding;
            canvas.translate((getWidth() - bodyWidth) / 11 * 5, 0);
        }
    }
    super.onDraw(canvas);
}
 
开发者ID:zwmlibs,项目名称:BookReader-master,代码行数:17,代码来源:DrawableCenterButton.java

示例7: drawable2Bitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:20,代码来源:ACache.java

示例8: emoticonDisplay

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
public static void emoticonDisplay(Context context, Spannable spannable, int emoticon, int fontSize, int start, int end) {
    Drawable drawable = getDrawable(context, emoticon);
    if (drawable != null) {
        int itemHeight;
        int itemWidth;
        if (fontSize == WRAP_DRAWABLE) {
            itemHeight = drawable.getIntrinsicHeight();
            itemWidth = drawable.getIntrinsicWidth();
        } else {
            itemHeight = fontSize;
            itemWidth = fontSize;
        }
        drawable.setBounds(0, 0, itemHeight, itemWidth);
        EmoticonSpan imageSpan = new EmoticonSpan(drawable);
        spannable.setSpan(imageSpan, start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
    }
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:18,代码来源:QQFilter.java

示例9: drawableToBitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
public static Bitmap drawableToBitmap(@NonNull Drawable drawable) {
    Bitmap bitmap;
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565); // Single color bitmap will be created of 1x1 pixel
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
    }

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:21,代码来源:DrawableUtils.java

示例10: drawable2Bitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
            ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:zwmlibs,项目名称:BookReader-master,代码行数:21,代码来源:ACache.java

示例11: drawable2Bitmap

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:27,代码来源:ConvertUtils.java

示例12: setDivider

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
/**
 * Sets the drawable that will be drawn between each item in the list. If
 * the drawable does not have an intrinsic height, you should also call
 * {@link #setDividerHeight(int)}
 * 
 * @param divider
 *            The drawable to use.
 */
public void setDivider(Drawable divider) {
    if (LOG_ENABLED) {
        Log.i(LOG_TAG, "setDivider: " + divider);
    }

    if (divider != null) {
        mDividerWidth = divider.getIntrinsicWidth();
    } else {
        mDividerWidth = 0;
    }
    mDivider = divider;
    mDividerIsOpaque = divider == null || divider.getOpacity() == PixelFormat.OPAQUE;
    requestLayout();
    invalidate();
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:24,代码来源:HListView.java

示例13: setTargetAspectRatio

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
/**
 * This method sets aspect ratio for crop bounds.
 * If {@link #SOURCE_IMAGE_ASPECT_RATIO} value is passed - aspect ratio is calculated
 * based on current image width and height.
 *
 * @param targetAspectRatio - aspect ratio for image crop (e.g. 1.77(7) for 16:9)
 */
public void setTargetAspectRatio(float targetAspectRatio) {
    final Drawable drawable = getDrawable();
    if (drawable == null) {
        mTargetAspectRatio = targetAspectRatio;
        return;
    }

    if (targetAspectRatio == SOURCE_IMAGE_ASPECT_RATIO) {
        mTargetAspectRatio = drawable.getIntrinsicWidth() / (float) drawable.getIntrinsicHeight();
    } else {
        mTargetAspectRatio = targetAspectRatio;
    }

    setupCropBounds();
    postInvalidate();
}
 
开发者ID:BrandonVargas,项目名称:AndroidOCRFforID,代码行数:24,代码来源:CropImageView.java

示例14: createBitmapFromRes

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
public static Bitmap createBitmapFromRes( int nResID, Context context, boolean bScaleToPO2 ) {

        // pull in the resource
        Bitmap bitmap = null;

        Drawable image = context.getResources().getDrawable( nResID );
        float density = context.getResources().getDisplayMetrics().density;

        int originalWidth = (int)(image.getIntrinsicWidth() / density);
        int originalHeight = (int)(image.getIntrinsicHeight() / density);

        int powWidth = OGLChart.getNextHighestPO2( originalWidth );
        int powHeight = OGLChart.getNextHighestPO2( originalHeight );

        if ( bScaleToPO2 ) {
            image.setBounds( 0, 0, powWidth, powHeight );
        } else {
            image.setBounds( 0, 0, originalWidth, originalHeight );
        }

        // Create an empty, mutable bitmap
        bitmap = Bitmap.createBitmap( powWidth, powHeight, Bitmap.Config.ARGB_8888 );
        // get a canvas to paint over the bitmap
        Canvas canvas = new Canvas( bitmap );
        bitmap.eraseColor(0);

        image.draw( canvas ); // draw the image onto our bitmap
        
        return bitmap;
    }
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:31,代码来源:ActivityChartDemon.java

示例15: getScrollPosition

import android.graphics.drawable.Drawable; //导入方法依赖的package包/类
/**
 * Return the point at the center of the zoomed image. The PointF coordinates range
 * in value between 0 and 1 and the focus point is denoted as a fraction from the left
 * and top of the view. For example, the top left corner of the image would be (0, 0).
 * And the bottom right corner would be (1, 1).
 * @return PointF representing the scroll position of the zoomed image.
 */
public PointF getScrollPosition() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return null;
    }
    int drawableWidth = drawable.getIntrinsicWidth();
    int drawableHeight = drawable.getIntrinsicHeight();

    PointF point = transformCoordTouchToBitmap(viewWidth / 2, viewHeight / 2, true);
    point.x /= drawableWidth;
    point.y /= drawableHeight;
    return point;
}
 
开发者ID:lueans,项目名称:LueansRead,代码行数:21,代码来源:TouchImageView.java


注:本文中的android.graphics.drawable.Drawable.getIntrinsicWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。