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


Java VectorDrawable类代码示例

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


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

示例1: drawableToBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        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);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:18,代码来源:ContextUtils.java

示例2: getBitmapFromDrawable

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public Bitmap getBitmapFromDrawable(int drawableId) {
    Bitmap bitmap = null;
    Drawable drawable = ContextCompat.getDrawable(_context, drawableId);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat)) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        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);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
开发者ID:gsantner,项目名称:markor,代码行数:19,代码来源:ContextUtils.java

示例3: drawableToBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public static Bitmap drawableToBitmap(Drawable thumb) {
    if (thumb == null) {
        return null;
    }

    Bitmap bitmap;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (thumb instanceof VectorDrawable) {
            int w = thumb.getIntrinsicWidth();
            int h = thumb.getIntrinsicHeight();
            Bitmap.Config config = thumb.getOpacity() != PixelFormat.OPAQUE ?
                    Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
            bitmap = Bitmap.createBitmap(w, h, config);
            Canvas canvas = new Canvas(bitmap);
            thumb.setBounds(0, 0, w, h);
            thumb.draw(canvas);
        } else {
            bitmap = ((BitmapDrawable) thumb).getBitmap();
        }
    } else {
        bitmap = ((BitmapDrawable) thumb).getBitmap();
    }
    return bitmap;
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:25,代码来源:FeThumbUtils.java

示例4: testColorVectorDrawable

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
/**
 * Tests the {@link Coloring#colorVectorDrawable(VectorDrawable, int)} method.
 * <p>
 * Unfortunately {@link VectorDrawable#setColorFilter(int, PorterDuff.Mode)} is not mocked in Android JAR yet.
 */
@Test
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public final void testColorVectorDrawable() {
    try {
        final VectorDrawable vectorDrawable = new VectorDrawable();
        assertNotNull("VectorDrawable is null", vectorDrawable);
        final VectorDrawable colored = Coloring.colorVectorDrawable(vectorDrawable, Color.RED);
        final PorterDuff.Mode mode = PorterDuff.Mode.SRC_ATOP;
        assertEquals("Vector color filter does not match", new PorterDuffColorFilter(Color.RED, mode), colored.getColorFilter());
    } catch (RuntimeException e) {
        boolean knownIssue = e.getMessage().contains("not mocked");
        if (!knownIssue) {
            e.printStackTrace();
        }
        assertTrue("Unknown error: " + e.getMessage(), knownIssue);
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:23,代码来源:ColoringTest.java

示例5: getBitmapFromDrawable

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
/**
 * Получение объекта Bitmap из Drawable из ресурсов
 */
public static Bitmap getBitmapFromDrawable(Context context, @DrawableRes int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawable || drawable instanceof VectorDrawableCompat) {
        Bitmap 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;
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
开发者ID:interactiveservices,项目名称:utils-android,代码行数:22,代码来源:BitmapUtils.java

示例6: createBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public static Bitmap createBitmap(Context context, @DrawableRes int drawableResId, @ColorRes int tintColor) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableResId).mutate();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return createBitmapKitKat(context, drawable, tintColor);
    }
    if (tintColor != 0) {
        DrawableCompat.setTint(drawable, ContextCompat.getColor(context, tintColor));
    }
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawableCompat) {
        return createBitmap((VectorDrawableCompat) drawable);
    } else if (drawable instanceof VectorDrawable) {
        return createBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("Unsupported drawable type");
    }
}
 
开发者ID:sakebook,项目名称:CustomTabsSample,代码行数:19,代码来源:ResourceUtil.java

示例7: onDraw

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
@Override
@TargetApi(21)
public void onDraw(Canvas c){
    paint.setStrokeWidth(10);
    for (int i = 2; i < 7; i++){
        c.drawLine(20, DensityMetrics.getSpaceHeight() * i + DensityMetrics.Companion.getToolbarHeight(),STAFF_WIDTH, DensityMetrics.getSpaceHeight() * i + DensityMetrics.Companion.getToolbarHeight(), paint);
    }
    float drawX = 320;
    for (ArrayList<Note> chord : MusicStore.sheet){
        for (Note note : chord){
            int noteHeadID = 0;
            if (note.getRhythm() == 2){
                noteHeadID = R.drawable.half_note_head;

            }else{
                noteHeadID = R.drawable.quarter_note_head;
            }

            VectorDrawable noteHead = (VectorDrawable) getResources().getDrawable(noteHeadID);
            Bitmap nh = NoteBitmap.getBitmap(noteHead);
            c.drawBitmap(Bitmap.createScaledBitmap(nh, (int) (DensityMetrics.getSpaceHeight() * 1.697), (int) DensityMetrics.getSpaceHeight(), true), (int) drawX , note.getY() - DensityMetrics.getSpaceHeight() / 2, paint);

        }
        drawX += 600;
    }
}
 
开发者ID:pattyjogal,项目名称:MusicScratchpad,代码行数:27,代码来源:CompositionView.java

示例8: needsTileify

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
/**
 * Returns {@code true} if the target drawable needs to be tileified.
 * <p/>
 * Note: Copied from android.widget.ProgressBar
 *
 * @param dr the drawable to check
 * @return {@code true} if the target drawable needs to be tileified,
 * {@code false} otherwise
 */
private static boolean needsTileify(Drawable dr) {
    if (dr instanceof LayerDrawable) {
        final LayerDrawable orig = (LayerDrawable) dr;
        final int N = orig.getNumberOfLayers();
        for (int i = 0; i < N; i++) {
            if (needsTileify(orig.getDrawable(i))) {
                return true;
            }
        }
        return false;
    }

    // If there's a bitmap that's not wrapped with a ClipDrawable or
    // ScaleDrawable, we'll need to wrap it and apply tiling.
    return dr instanceof BitmapDrawable || dr instanceof VectorDrawable;

}
 
开发者ID:brightec,项目名称:RateTheApp-Android,代码行数:27,代码来源:RatingBar.java

示例9: colorDrawable

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
/**
 * Colors the given drawable to the specified color. Uses {@link PorterDuff.Mode#SRC_ATOP}.
 *
 * @param context  Which context to use
 * @param drawable Which drawable to color
 * @param color    Which color to use
 * @return A colored drawable, new instance in most cases for bitmaps, cached instance for most other cases
 */
@NonNull
public static Drawable colorDrawable(@NonNull final Context context, @NonNull final Drawable drawable, @ColorInt final int color) {
    if (drawable instanceof VectorDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return colorVectorDrawable((VectorDrawable) drawable, color);
    }

    if (drawable instanceof VectorDrawableCompat) {
        return colorVectorDrawableCompat((VectorDrawableCompat) drawable, color);
    }

    if (drawable instanceof ColorDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ((ColorDrawable) drawable).setColor(color);
        return drawable;
    }

    if (drawable instanceof GradientDrawable) {
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        return drawable;
    }

    if (drawable instanceof BitmapDrawable) {
        final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
        return new BitmapDrawable(context.getResources(), colorBitmap(bitmap, color));
    }

    // have no idea what this is..
    return colorUnknownDrawable(drawable, color);
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:37,代码来源:Coloring.java

示例10: getBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
static public Bitmap getBitmap(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable instanceof BitmapDrawable) {
        return BitmapFactory.decodeResource(context.getResources(), drawableId);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
开发者ID:m2049r,项目名称:xmrwallet,代码行数:11,代码来源:Helper.java

示例11: getBitmapFromResource

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
private static Bitmap getBitmapFromResource(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:9,代码来源:ViewUtils.java

示例12: onDraw

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {

	Drawable drawable = getDrawable();

	if (drawable == null) {
		return;
	}

	if (getWidth() == 0 || getHeight() == 0) {
		return;
	}

	Bitmap b = null;
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
			&& drawable instanceof VectorDrawable) {
		((VectorDrawable) drawable).draw(canvas);
		b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
		Canvas c = new Canvas();
		c.setBitmap(b);
		drawable.draw(c);
	} else if (drawable instanceof BitmapDrawable){
		b = ((BitmapDrawable) drawable).getBitmap();
	} else if (drawable instanceof LayerDrawable) {
		LayerDrawable layerDrawable = (LayerDrawable) drawable;
		b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
		layerDrawable.draw(new Canvas(b));
	}
	Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
	int w = getWidth(), h = getHeight();

	Bitmap roundBitmap =  getCroppedBitmap(bitmap, w);
	canvas.drawBitmap(roundBitmap, 0,0, null);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:35,代码来源:RoundedImageView.java

示例13: getBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public static Bitmap getBitmap(Drawable drawable, int width, int height) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawableCompat) {
        return getBitmap((VectorDrawableCompat) drawable, width, height);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable, width, height);
    } else {
        throw new IllegalArgumentException("Unsupported drawable type");
    }
}
 
开发者ID:mangoblogger,项目名称:MangoBloggerAndroidApp,代码行数:12,代码来源:Utils.java

示例14: getVecDrawable

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
public static Drawable getVecDrawable(Context context, @DrawableRes int id) {
    Drawable drawable = AppCompatResources.getDrawable(context, id);
    if (!(drawable instanceof VectorDrawableCompat || drawable instanceof VectorDrawable)) {
        throw new RuntimeException();
    }
    return drawable;
}
 
开发者ID:RadiationX,项目名称:ForPDA,代码行数:8,代码来源:App.java

示例15: getBitmap

import android.graphics.drawable.VectorDrawable; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
开发者ID:NickAndroid,项目名称:Accessories_Android,代码行数:10,代码来源:ResourceAccessories.java


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