本文整理汇总了C#中Android.Graphics.Canvas.DrawBitmap方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawBitmap方法的具体用法?C# Canvas.DrawBitmap怎么用?C# Canvas.DrawBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.DrawBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw (Canvas canvas)
{
canvas.DrawColor (Color.White);
Paint p = new Paint ();
float y = 10;
p.Color = Color.Red;
canvas.DrawBitmap (mBitmap, 10, y, p);
y += mBitmap.Height + 10;
canvas.DrawBitmap (mBitmap2, 10, y, p);
y += mBitmap2.Height + 10;
p.SetShader (mShader);
canvas.DrawBitmap (mBitmap3, 10, y, p);
}
示例2: GetRoundedCornerBitmap
// If you would like to create a circle of the image set pixels to half the width of the image.
internal static Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
{
Bitmap output = null;
try
{
output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Color color = new Color(66, 66, 66);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
RectF rectF = new RectF(rect);
float roundPx = pixels;
paint.AntiAlias = true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color = color;
canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(bitmap, rect, rect, paint);
}
catch (System.Exception err)
{
System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
}
return output;
}
示例3: Draw
public override void Draw(Canvas canvas)
{
LoadResources ();
var blackPaint = new Paint () { Color = black.Value };
var whitePaint = new Paint () { Color = white.Value };
XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
{
var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);
}, (RectangleF rect, object image) =>
{
if (image != null)
canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
});
// New Game button
whitePaint.Color = white.Value;
whitePaint.SetStyle (Paint.Style.Fill);
whitePaint.TextSize = 30;
whitePaint.AntiAlias = true;
Rect bounds = new Rect ();
whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);
whitePaint.Dispose ();
blackPaint.Dispose ();
base.Draw (canvas);
}
示例4: GetCroppedBitmap
static Bitmap GetCroppedBitmap (Bitmap bmp, int radius)
{
Bitmap sbmp;
if (bmp.Width != radius || bmp.Height != radius)
sbmp = Bitmap.CreateScaledBitmap (bmp, radius, radius, false);
else
sbmp = bmp;
var output = Bitmap.CreateBitmap (sbmp.Width,
sbmp.Height, Bitmap.Config.Argb8888);
var canvas = new Canvas (output);
var paint = new Paint ();
var rect = new Rect (0, 0, sbmp.Width, sbmp.Height);
paint.AntiAlias = true;
paint.FilterBitmap = true;
paint.Dither = true;
canvas.DrawARGB (0, 0, 0, 0);
paint.Color = Color.ParseColor ("#BAB399");
canvas.DrawCircle (sbmp.Width / 2 + 0.7f, sbmp.Height / 2 + 0.7f,
sbmp.Width / 2 + 0.1f, paint);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
canvas.DrawBitmap (sbmp, rect, rect, paint);
return output;
}
示例5: OnDraw
protected override void OnDraw (Canvas canvas)
{
drawCanvas = canvas;
canvas.DrawBitmap(canvasBitmap, 0, 0, canvasPaint);
canvas.DrawPath(drawPath, drawPaint);
}
示例6: ToBlurred
public static Bitmap ToBlurred(Bitmap source, Context context, float radius)
{
if ((int)Android.OS.Build.VERSION.SdkInt >= 17)
{
Bitmap bitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);
using (Canvas canvas = new Canvas(bitmap))
{
canvas.DrawBitmap(source, 0, 0, null);
using (Android.Renderscripts.RenderScript rs = Android.Renderscripts.RenderScript.Create(context))
{
using (Android.Renderscripts.Allocation overlayAlloc = Android.Renderscripts.Allocation.CreateFromBitmap(rs, bitmap))
{
using (Android.Renderscripts.ScriptIntrinsicBlur blur = Android.Renderscripts.ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element))
{
blur.SetInput(overlayAlloc);
blur.SetRadius(radius);
blur.ForEach(overlayAlloc);
overlayAlloc.CopyTo(bitmap);
rs.Destroy();
return bitmap;
}
}
}
}
}
return ToLegacyBlurred(source, context, (int)radius);
}
示例7: DrawBackground
void DrawBackground()
{
if (background != null) {
background.Dispose ();
}
background = Bitmap.CreateBitmap(screen_size.Width, screen_size.Height, Bitmap.Config.Argb8888);
Canvas c = new Canvas (background);
//Paint black = new Paint();
//black.SetARGB(255, 0, 0, 0);
//black.SetStyle (Paint.Style.Stroke);
//Bitmap plaatje = blokken[2].DrawBlok (MainActivity.context);
//DrawBitmap werkt niet voor scaling bitmaps in xamarin
//c.DrawBitmap (plaatje, new Rect (0, 0, plaatje.Width, plaatje.Height), new RectF (blokken[2].X, blokken[2].Y, blokken[2].Width, blokken[2].Height), null);
//c.DrawBitmap(plaatje,96,0,null);
foreach (Blok b in blokken)
{
Bitmap plaatje = b.DrawBlok (MainActivity.context);
c.DrawBitmap (plaatje, b.X, b.Y, null);
plaatje.Dispose ();
}
c.Dispose ();
//black.Dispose ();
}
示例8: Draw
public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
{
try
{
if (!feature.RenderedGeometry.ContainsKey(style)) feature.RenderedGeometry[style] = ToAndroidBitmap(feature.Geometry);
var bitmap = (AndroidGraphics.Bitmap)feature.RenderedGeometry[style];
var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
dest = new BoundingBox(
dest.MinX,
dest.MinY,
dest.MaxX,
dest.MaxY);
var destination = RoundToPixel(dest);
using (var paint = new Paint())
{
canvas.DrawBitmap(bitmap, new Rect(0, 0, bitmap.Width, bitmap.Height), destination, paint);
}
DrawOutline(canvas, style, destination);
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}
示例9: OnDraw
protected override void OnDraw(Canvas canvas) {
base.OnDraw (canvas);
if (mBlurredView != null) {
if (prepare()) {
// If the background of the blurred view is a color drawable, we use it to clear
// the blurring canvas, which ensures that edges of the child views are blurred
// as well; otherwise we clear the blurring canvas with a transparent color.
if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){
mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color);
}else {
mBitmapToBlur.EraseColor(Color.Transparent);
}
mBlurredView.Draw(mBlurringCanvas);
blur();
canvas.Save();
canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY());
canvas.Scale(mDownsampleFactor, mDownsampleFactor);
canvas.DrawBitmap(mBlurredBitmap, 0, 0, null);
canvas.Restore();
}
canvas.DrawColor(mOverlayColor);
}
}
示例10: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
DrawPaint.Color = CurrentLineColor;
canvas.DrawBitmap(CanvasBitmap, 0, 0, CanvasPaint);
canvas.DrawPath(DrawPath, DrawPaint);
}
示例11: Evaluate
public Java.Lang.Object Evaluate (float fraction, Java.Lang.Object startValue, Java.Lang.Object endValue)
{
var bmp1 = startValue as Bitmap;
var bmp2 = endValue as Bitmap;
if (cacheBitmap == null)
cacheBitmap = Bitmap.CreateBitmap (bmp1.Width, bmp1.Height, Bitmap.Config.Argb8888);
if (blendPaint == null) {
blendPaint = new Paint ();
blendPaint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcOver));
}
using (var canvas = new Canvas (cacheBitmap)) {
canvas.DrawBitmap (bmp1, 0, 0, null);
blendPaint.Alpha = (int)((1 - fraction) * 255);
canvas.DrawBitmap (bmp2, 0, 0, blendPaint);
}
return cacheBitmap;
}
示例12: ScaleUpBitmap
public static Bitmap ScaleUpBitmap(Bitmap originalImage, int wantedWidth, int wantedHeight)
{
Bitmap output = Bitmap.CreateBitmap(wantedWidth, wantedHeight, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Matrix m = new Matrix();
m.SetScale((float)wantedWidth / originalImage.Width, (float)wantedHeight / originalImage.Height);
canvas.DrawBitmap(originalImage, m, new Paint());
canvas.Dispose ();
originalImage.Dispose ();
return output;
}
示例13: ConvertConfig
public static Bitmap ConvertConfig(Bitmap bitmap, Bitmap.Config config)
{
if (bitmap.GetConfig().Equals(config))
return Bitmap.CreateBitmap(bitmap);
Bitmap convertedBitmap = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, config);
Canvas canvas = new Canvas(convertedBitmap);
Android.Graphics.Paint paint = new Android.Graphics.Paint();
paint.Color = Android.Graphics.Color.Black;
canvas.DrawBitmap(bitmap, 0, 0, paint);
return convertedBitmap;
}
示例14: Overlay
public static Bitmap Overlay(IEnumerable<Bitmap> bmps, Bitmap.Config config = null)
{
int width = bmps.Max<Bitmap>(x => x.Width);
int height = bmps.Max<Bitmap>(x => x.Height);
Bitmap bmOverlay = Bitmap.CreateBitmap(width, height, config == null ? Bitmap.Config.Argb8888 : config);
Canvas canvas = new Canvas(bmOverlay);
foreach (var bmp in bmps)
canvas.DrawBitmap(bmp, 0, 0, null);
canvas.Dispose();
return bmOverlay;
}
示例15: Draw
public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
{
var point = feature.Geometry as Point;
var dest = viewport.WorldToScreen(point);
var symbolSize = (float)SymbolStyle.DefaultHeight;
var symbolType = SymbolType.Ellipse;
var symbolStyle = style as SymbolStyle;
if (symbolStyle != null)
{
if (symbolStyle.BitmapId >= 0)
{
// Bitmap
if (!feature.RenderedGeometry.ContainsKey(style))
{
var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
imageStream.Position = 0;
var androidBitmap = BitmapFactory.DecodeStream(imageStream);
feature.RenderedGeometry[style] = androidBitmap;
}
var bitmap = (Bitmap)feature.RenderedGeometry[style];
var halfWidth = bitmap.Width / 2;
var halfHeight = bitmap.Height / 2;
var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
return;
}
symbolType = symbolStyle.SymbolType;
if (symbolStyle.SymbolScale > 0) symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
}
// Drawing
var paints = style.ToAndroid();
if (symbolType == SymbolType.Ellipse)
{
foreach (var paint in paints)
{
canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
paint.Dispose();
}
}
else
{
foreach (var paint in paints)
{
canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
paint.Dispose();
}
}
}