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


Java Canvas.setBitmap方法代码示例

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


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

示例1: createBitmapFromView

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * 从一个view创建Bitmap。
 * 注意点:绘制之前要清掉 View 的焦点,因为焦点可能会改变一个 View 的 UI 状态。
 * 来源:https://github.com/tyrantgit/ExplosionField
 *
 * @param view  传入一个 View,会获取这个 View 的内容创建 Bitmap。
 * @param scale 缩放比例,对创建的 Bitmap 进行缩放,数值支持从 0 到 1。
 */
public static Bitmap createBitmapFromView(View view, float scale) {
    if (view instanceof ImageView) {
        Drawable drawable = ((ImageView) view).getDrawable();
        if (drawable != null && drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
    }
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
            (int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);
            canvas.save();
            canvas.drawColor(Color.WHITE); // 防止 View 上面有些区域空白导致最终 Bitmap 上有些区域变黑
            canvas.scale(scale, scale);
            view.draw(canvas);
            canvas.restore();
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:33,代码来源:QMUIDrawableHelper.java

示例2: toRoundCornerMutableBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private static Bitmap toRoundCornerMutableBitmap(Canvas canvas, Paint paintClear, Bitmap srcBitmap, float[] roundRadius) {
	canvas.setBitmap(srcBitmap);
	RectF inset = new RectF(1, 1, 1, 1);
	if (roundRadius.length == 2) {
		float[] tmpRoundRadius = new float[8];
		for (int i = 0; i < 4; ++i) {
			tmpRoundRadius[i * 2 + 0] = roundRadius[0];
			tmpRoundRadius[i * 2 + 1] = roundRadius[1];
			roundRadius = tmpRoundRadius;
		}
	}
	canvas.save();
	canvas.translate(-1, -1);
	RoundRectShape roundRectShape = new RoundRectShape(null, inset, roundRadius);
	roundRectShape.resize(srcBitmap.getWidth() + 2, srcBitmap.getHeight() + 2);
	roundRectShape.draw(canvas, paintClear);
	canvas.restore();
	canvas.setBitmap(null);
	return srcBitmap;
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:21,代码来源:XulWorker.java

示例3: drawScaledPreview

import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap drawScaledPreview(Canvas canvas, Bitmap.Config config) {
    Drawable d = mView.getBackground();
    Rect bounds = getDrawableBounds(d);

    int size = Launcher.getLauncher(mView.getContext()).getDeviceProfile().iconSizePx;

    final Bitmap b = Bitmap.createBitmap(
            size + DRAG_BITMAP_PADDING,
            size + DRAG_BITMAP_PADDING,
            config);

    canvas.setBitmap(b);
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    canvas.translate(DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2);
    canvas.scale(((float) size) / bounds.width(), ((float) size) / bounds.height(), 0, 0);
    canvas.translate(bounds.left, bounds.top);
    d.draw(canvas);
    canvas.restore();
    return b;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:21,代码来源:ShortcutDragPreviewProvider.java

示例4: createDragOutline

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public Bitmap createDragOutline(Canvas canvas) {
    final Bitmap b = Bitmap.createBitmap(mOutlineSize[0], mOutlineSize[1], Bitmap.Config.ALPHA_8);
    canvas.setBitmap(b);

    Paint paint = new Paint();
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.FILL);

    // Use 0.9f times the radius for the actual circle to account for icon normalization.
    float radius = getPreviewBounds().width() * 0.5f;
    canvas.drawCircle(DRAG_BITMAP_PADDING / 2 + radius,
            DRAG_BITMAP_PADDING / 2 + radius, radius * 0.9f, paint);

    HolographicOutlineHelper.obtain(mLauncher).applyExpensiveOutlineWithBlur(b, canvas);
    canvas.setBitmap(null);
    return b;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:19,代码来源:ExternalDragPreviewProvider.java

示例5: createDragBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * Returns a new bitmap to show when the {@link #mView} is being dragged around.
 * Responsibility for the bitmap is transferred to the caller.
 */
public Bitmap createDragBitmap(Canvas canvas) {
    Bitmap b;

    if (mView instanceof TextView) {
        Drawable d = Workspace.getTextViewIcon((TextView) mView);
        Rect bounds = getDrawableBounds(d);
        b = Bitmap.createBitmap(bounds.width() + DRAG_BITMAP_PADDING,
                bounds.height() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
    } else {
        b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
                mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
    }

    canvas.setBitmap(b);
    drawDragView(canvas);
    canvas.setBitmap(null);

    return b;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:24,代码来源:DragPreviewProvider.java

示例6: resource2Bitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap resource2Bitmap(final Context context, final int resourceId) {
    Drawable drawable = ContextCompat.getDrawable(context, resourceId);
    Canvas canvas = new Canvas();
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bitmap);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:Wilshion,项目名称:HeadlineNews,代码行数:10,代码来源:SpanUtils.java

示例7: resource2Bitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap resource2Bitmap(final int resourceId) {
    Drawable drawable = ContextCompat.getDrawable(Utils.getApp(), resourceId);
    Canvas canvas = new Canvas();
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    canvas.setBitmap(bitmap);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    drawable.draw(canvas);
    return bitmap;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:SpanUtils.java

示例8: createDragOutline

import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public Bitmap createDragOutline(Canvas canvas) {
    Bitmap b = drawScaledPreview(canvas, Bitmap.Config.ALPHA_8);

    HolographicOutlineHelper.obtain(mView.getContext())
            .applyExpensiveOutlineWithBlur(b, canvas);
    canvas.setBitmap(null);
    return b;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:10,代码来源:ShortcutDragPreviewProvider.java

示例9: drawToBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
@Nullable
private static Bitmap drawToBitmap(
    BitmapPool bitmapPool, Drawable drawable, int width, int height) {
  if (width == Target.SIZE_ORIGINAL && drawable.getIntrinsicWidth() <= 0) {
    if (Log.isLoggable(TAG, Log.WARN)) {
      Log.w(TAG, "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the"
          + " Drawable has no intrinsic width");
    }
    return null;
  }
  if (height == Target.SIZE_ORIGINAL && drawable.getIntrinsicHeight() <= 0) {
    if (Log.isLoggable(TAG, Log.WARN)) {
      Log.w(TAG, "Unable to draw " + drawable + " to Bitmap with Target.SIZE_ORIGINAL because the"
          + " Drawable has no intrinsic height");
    }
    return null;
  }
  int targetWidth = drawable.getIntrinsicWidth() > 0 ? drawable.getIntrinsicWidth() : width;
  int targetHeight = drawable.getIntrinsicHeight() > 0 ? drawable.getIntrinsicHeight() : height;

  Lock lock = TransformationUtils.getBitmapDrawableLock();
  lock.lock();
  Bitmap result = bitmapPool.get(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
  try {
    Canvas canvas = new Canvas(result);
    drawable.setBounds(0, 0, targetWidth, targetHeight);
    drawable.draw(canvas);
    canvas.setBitmap(null);
  } finally {
    lock.unlock();
  }
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:DrawableToBitmapConverter.java

示例10: createDragBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * Returns a new bitmap to show when the {@link #mView} is being dragged around.
 * Responsibility for the bitmap is transferred to the caller.
 */
public Bitmap createDragBitmap(Canvas canvas) {
    float scale = 1f;
    int width = mView.getWidth();
    int height = mView.getHeight();

    if (mView instanceof TextView) {
        Drawable d = Workspace.getTextViewIcon((TextView) mView);
        Rect bounds = getDrawableBounds(d);
        width = bounds.width();
        height = bounds.height();
    } else if (mView instanceof LauncherAppWidgetHostView) {
        scale = ((LauncherAppWidgetHostView) mView).getScaleToFit();
        width = (int) (mView.getWidth() * scale);
        height = (int) (mView.getHeight() * scale);
    }

    Bitmap b = Bitmap.createBitmap(width + blurSizeOutline, height + blurSizeOutline,
            Bitmap.Config.ARGB_8888);
    canvas.setBitmap(b);

    canvas.save();
    canvas.scale(scale, scale);
    drawDragView(canvas);
    canvas.restore();

    canvas.setBitmap(null);

    return b;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:34,代码来源:DragPreviewProvider.java

示例11: toRoundCornerBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private static Bitmap toRoundCornerBitmap(Canvas canvas, Paint paintClear, Bitmap srcBitmap, float[] roundRadius) {
	if (srcBitmap.isMutable() && srcBitmap.hasAlpha()) {
		return toRoundCornerMutableBitmap(canvas, paintClear, srcBitmap, roundRadius);
	}
	Bitmap output;
	if (false) {
		output = BitmapTools.createBitmapFromRecycledBitmaps(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
	} else {
		output = BitmapTools.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), XulManager.DEF_PIXEL_FMT);
	}
	canvas.setBitmap(output);
	Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight());
	canvas.drawBitmap(srcBitmap, rect, rect, null);
	return toRoundCornerMutableBitmap(canvas, paintClear, output, roundRadius);
}
 
开发者ID:starcor-company,项目名称:starcor.xul,代码行数:16,代码来源:XulWorker.java

示例12: createDragOutline

import android.graphics.Canvas; //导入方法依赖的package包/类
/**
 * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
 * Responsibility for the bitmap is transferred to the caller.
 */
public Bitmap createDragOutline(Canvas canvas) {
    final Bitmap b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
            mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ALPHA_8);
    canvas.setBitmap(b);
    drawDragView(canvas);
    HolographicOutlineHelper.obtain(mView.getContext())
            .applyExpensiveOutlineWithBlur(b, canvas);
    canvas.setBitmap(null);
    return b;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:15,代码来源:DragPreviewProvider.java

示例13: getDefaultWallpaper

import android.graphics.Canvas; //导入方法依赖的package包/类
private static DefaultWallpaperInfo getDefaultWallpaper(Context context) {
    File defaultThumbFile = getDefaultThumbFile(context);
    Bitmap thumb = null;
    boolean defaultWallpaperExists = false;
    Resources res = context.getResources();

    if (defaultThumbFile.exists()) {
        thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
        defaultWallpaperExists = true;
    } else {
        Point defaultThumbSize = getDefaultThumbSize(res);
        Drawable wallpaperDrawable = WallpaperManager.getInstance(context).getBuiltInDrawable(
                defaultThumbSize.x, defaultThumbSize.y, true, 0.5f, 0.5f);
        if (wallpaperDrawable != null) {
            thumb = Bitmap.createBitmap(
                    defaultThumbSize.x, defaultThumbSize.y, Bitmap.Config.ARGB_8888);
            Canvas c = new Canvas(thumb);
            wallpaperDrawable.setBounds(0, 0, defaultThumbSize.x, defaultThumbSize.y);
            wallpaperDrawable.draw(c);
            c.setBitmap(null);
        }
        if (thumb != null) {
            defaultWallpaperExists = saveDefaultWallpaperThumb(context, thumb);
        }
    }
    if (defaultWallpaperExists) {
        return new DefaultWallpaperInfo(new BitmapDrawable(res, thumb));
    }
    return null;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:31,代码来源:DefaultWallpaperInfo.java

示例14: createBitmap

import android.graphics.Canvas; //导入方法依赖的package包/类
private Bitmap createBitmap(int x, int y, int w, int h) {
    Bitmap newBimap = delegate.getBitmap();
    if (newBimap != null) {
        bitmapToEdit = newBimap;
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);

    Matrix matrix = new Matrix();
    matrix.setTranslate(-bitmapToEdit.getWidth() / 2, -bitmapToEdit.getHeight() / 2);
    matrix.postRotate(orientation);
    if (orientation % 360 == 90 || orientation % 360 == 270) {
        matrix.postTranslate(bitmapToEdit.getHeight() / 2 - x, bitmapToEdit.getWidth() / 2 - y);
    } else {
        matrix.postTranslate(bitmapToEdit.getWidth() / 2 - x, bitmapToEdit.getHeight() / 2 - y);
    }
    canvas.drawBitmap(bitmapToEdit, matrix, paint);
    try {
        canvas.setBitmap(null);
    } catch (Exception e) {
        //don't promt, this will crash on 2.x
    }

    return bitmap;
}
 
开发者ID:chengzichen,项目名称:KrGallery,代码行数:28,代码来源:PhotoCropView.java

示例15: IconDrawer

import android.graphics.Canvas; //导入方法依赖的package包/类
IconDrawer(int padding) {
    mPadding = padding;
    mCircleClipBitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ALPHA_8);
    Canvas canvas = new Canvas();
    canvas.setBitmap(mCircleClipBitmap);
    canvas.drawCircle(mSize / 2, mSize / 2, mSize / 2 - padding, mPaint);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:8,代码来源:BadgeRenderer.java


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