本文整理汇总了C#中Android.Graphics.Canvas.DrawARGB方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawARGB方法的具体用法?C# Canvas.DrawARGB怎么用?C# Canvas.DrawARGB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.DrawARGB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw(Canvas canvas)
{
Android.Graphics.Drawable.Drawable drawable = GetDrawable();
if (drawable is BitmapDrawable)
{
RectF rectF = new RectF(drawable.GetBounds());
int restoreCount = canvas.SaveLayer(rectF, null, Canvas.AllSaveFlag);
GetImageMatrix().MapRect(rectF);
Paint paint = ((BitmapDrawable)drawable).GetPaint();
paint.SetAntiAlias(true);
paint.SetColor(unchecked((int)(0xff000000)));
canvas.DrawARGB(0, 0, 0, 0);
canvas.DrawRoundRect(rectF, Radius, Radius, paint);
Xfermode restoreMode = paint.GetXfermode();
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
base.OnDraw(canvas);
// Restore paint and canvas
paint.SetXfermode(restoreMode);
canvas.RestoreToCount(restoreCount);
}
else
{
base.OnDraw(canvas);
}
}
示例2: getRoundedCroppedBitmap
public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.Width != radius || bitmap.Height!= radius)
finalBitmap = Bitmap.CreateScaledBitmap(bitmap, radius, radius,
false);
else
finalBitmap = bitmap;
Bitmap output = Bitmap.CreateBitmap(finalBitmap.Width,
finalBitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, finalBitmap.Width,
finalBitmap.Height);
paint.AntiAlias=true;
paint.FilterBitmap=true;
paint.Dither=true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color=Color.ParseColor("#BAB399");
canvas.DrawCircle(finalBitmap.Width / 2 + 0.7f,
finalBitmap.Height / 2 + 0.7f,
finalBitmap.Width / 2 + 0.1f, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(finalBitmap, rect, rect, paint);
return output;
}
示例3: 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;
}
示例4: 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;
}
示例5: GetRoundedCornerBitmap
public static Bitmap GetRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.CreateBitmap(bitmap.Width,
bitmap.Height,Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
//int color = 0xff424242;
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
RectF rectF = new RectF(rect);
float roundPx = 12.0f;
paint.AntiAlias=true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color = Color.Red; //color;//Color.Transparent;
canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(bitmap, rect, rect, paint);
return output;
}
示例6: InitWithBitmap
public void InitWithBitmap(Bitmap imageSource, ALL11 filter, ALL11 wrap)
{
//TODO: Android.Opengl.GLUtils.GetInternalFormat()
try
{
_format = SurfaceFormat.Color;
if (imageSource.HasAlpha)
_format = SurfaceFormat.Color;
if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0)
{
_width = imageSource.Width;
_height = imageSource.Height;
// There are rules for npot textures that we must abide by (wrap = ClampToEdge and filter = Nearest or Linear)
if (!MathHelper.IsPowerOfTwo(_width) || !MathHelper.IsPowerOfTwo(_height))
{
filter = ALL11.Linear;
wrap = ALL11.ClampToEdge;
}
}
else
{
//scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024.
//Note: may not have to do this with OpenGL 2+
_width = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2))));
_height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2))));
}
_size.Width = _width;
_size.Height = _height;
if (GraphicsDevice.OpenGLESVersion ==
OpenTK.Graphics.GLContextVersion.Gles2_0)
{
GL20.GenTextures(1, ref _name);
}
else
{
GL11.GenTextures(1, ref _name);
}
if (_name == 0)
{
_originalBitmap = imageSource;
_originalFilter = filter;
_originalWrap = wrap;
PrimaryThreadLoader.AddToList(this);
_textureCreated = false;
}
else
{
_originalBitmap = null;
_textureCreated = true;
using (
Bitmap imagePadded = Bitmap.CreateBitmap(_width, _height,
Bitmap.Config.Argb8888)
)
{
using(Canvas can = new Canvas(imagePadded))
{
can.DrawARGB(0, 0, 0, 0);
if(AndroidCompatibility.ScaleImageToPowerOf2)
can.DrawBitmap(imageSource, new Rect(0, 0, imageSource.Width, imageSource.Height), new Rect(0, 0, _width, _height), null); //Scale to texture
else
can.DrawBitmap(imageSource, 0, 0, null);
if (GraphicsDevice.OpenGLESVersion ==
OpenTK.Graphics.GLContextVersion.Gles2_0)
{
GL20.BindTexture(ALL20.Texture2D, _name);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter,
(int)filter);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter,
(int)filter);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapS, (int)wrap);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureWrapT, (int)wrap);
Android.Opengl.GLUtils.TexImage2D((int)ALL20.Texture2D, 0,
imagePadded, 0);
// error checking
//int errAndroidGL = Android.Opengl.GLES20.GlGetError();
//ALL20 errGenericGL = GL20.GetError();
//if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != ALL20.NoError)
// Console.WriteLine(string.Format("OpenGL ES 2.0:\n\tAndroid error: {0,10:X}\n\tGeneric error: {1, 10:X}", errAndroidGL, errGenericGL));
}
else
{
GL11.BindTexture(ALL11.Texture2D, _name);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter,
(int)filter);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter,
(int)filter);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapS, (int)wrap);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureWrapT, (int)wrap);
GL11.TexParameter(ALL11.Texture2D, ALL11.GenerateMipmap, 1);
Android.Opengl.GLUtils.TexImage2D((int)ALL11.Texture2D, 0,
//.........这里部分代码省略.........
示例7: InitWithBitmap
public void InitWithBitmap(Bitmap imageSource, ALL11 filter)
{
//TODO: Android.Opengl.GLUtils.GetInternalFormat()
_format = SurfaceFormat.Color;
if (imageSource.HasAlpha)
_format = SurfaceFormat.Color;
if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0)
{
_width = imageSource.Width;
_height = imageSource.Height;
}
else
{
// scale up bitmap to be power of 2 dimensions but dont exceed 1024x1024.
// Note: may not have to do this with OpenGL 2+
_width = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Width) / Math.Log10(2))));
_height = (int)Math.Pow(2, Math.Min(10, Math.Ceiling(Math.Log10(imageSource.Height) / Math.Log10(2))));
}
_size.Width = _width;
_size.Height = _height;
using (Bitmap imagePadded = Bitmap.CreateBitmap(_width, _height, Bitmap.Config.Argb8888))
{
Canvas can = new Canvas(imagePadded);
can.DrawARGB(0, 0, 0, 0);
can.DrawBitmap(imageSource, 0, 0, null);
if (GraphicsDevice.OpenGLESVersion == OpenTK.Graphics.GLContextVersion.Gles2_0)
{
GL11.GenTextures(1, ref _name);
GL11.BindTexture(ALL11.Texture2D, _name);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMinFilter, (int)filter);
GL11.TexParameter(ALL11.Texture2D, ALL11.TextureMagFilter, (int)filter);
Android.Opengl.GLUtils.TexImage2D((int)ALL11.Texture2D, 0, imagePadded, 0);
// free bitmap
imageSource.Recycle();
// error checking
int errAndroidGL = Android.Opengl.GLES20.GlGetError();
ALL20 errGenericGL = GL20.GetError();
if (errAndroidGL != Android.Opengl.GLES20.GlNoError || errGenericGL != ALL20.NoError)
Console.WriteLine(string.Format("OpenGL ES 2.0:\n\tAndroid error: {0,10:X}\n\tGeneric error: {1, 10:X}", errAndroidGL, errGenericGL));
}
else
{
GL20.GenTextures(1, ref _name);
GL20.BindTexture(ALL20.Texture2D, _name);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMinFilter, (int)filter);
GL20.TexParameter(ALL20.Texture2D, ALL20.TextureMagFilter, (int)filter);
Android.Opengl.GLUtils.TexImage2D((int)ALL20.Texture2D, 0, imagePadded, 0);
}
}
_maxS = _size.Width / (float)_width;
_maxT = _size.Height / (float)_height;
}
示例8: GetRoundedCornerBitmap
private static Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width,
int height)
{
Bitmap output = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
RectF destRectF = new RectF(destRect);
paint.AntiAlias = true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color = Color.Argb(0xFF, 0x00, 0x00, 0x00);
canvas.DrawRoundRect(destRectF, roundPixels, roundPixels, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(bitmap, srcRect, destRectF, paint);
return output;
}
示例9: OnZoomThumbnailClicked
void OnZoomThumbnailClicked (object sender, EventArgs e)
{
View v = (View)sender;
// Create a thumbnail animation. We are going to build our thumbnail
// just from the view that was pressed. We make sure the view is
// not selected, because by the time the animation starts we will
// have finished with the selection of the tap.
v.DrawingCacheEnabled = true;
v.Pressed = false;
v.RefreshDrawableState ();
Bitmap bm = v.DrawingCache;
Canvas c = new Canvas (bm);
c.DrawARGB (255, 255, 0, 0);
ActivityOptions opts = ActivityOptions.MakeThumbnailScaleUpAnimation (v, bm, 0, 0);
// Request the activity be started, using the custom animation options.
StartActivity (new Intent (this, typeof (AlertDialogSamples)), opts.ToBundle ());
v.DrawingCacheEnabled = false;
}
示例10: OnCreate
protected override void OnCreate(Bundle bundle)
{
//Set Display/Interactions/Counter Vars
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
Button clear = FindViewById<Button> (Resource.Id.ClearButton);
Button save = FindViewById<Button> (Resource.Id.SaveButton);
int CountX = -7, CountY = -7;
var IV = FindViewById<ImageView> (Resource.Id.DisplayView);
float x1=0, y1=0, x2=0, y2=0;
Bitmap BM = Bitmap.CreateBitmap (760, 800, Bitmap.Config.Argb8888);
//Set up Paint
var P = new Paint();
P.Color = Color.White;
P.StrokeWidth = 15;
Canvas C = new Canvas(BM);
//Draw on Bitmap When Touched
IV.Touch += (s, e) => {
if (e.Event.Action == MotionEventActions.Down)
{
x1 = e.Event.GetX();
y1 = e.Event.GetY();
x2 = e.Event.GetX();
y2 = e.Event.GetY();
Console.WriteLine ("Touched at X:"+x1+" Y:"+y1);
BM.SetPixel ((int)x1, (int)y1, Color.White);
IV.SetImageBitmap (BM);
}
if (e.Event.Action == MotionEventActions.Move)
{
x1 = e.Event.GetX();
y1 = e.Event.GetY();
while(CountY<=7){
while(CountX<=7){
BM.SetPixel ((int)x1+CountX, (int)y1+CountY, Color.White);
CountX++;
}
CountX=-7;
CountY++;
}
Console.WriteLine ("Touched at X:"+x1+" Y:"+y1);
C.DrawLine(x1, y1, x2, y2, P);
IV.SetImageBitmap(BM);
x2 = x1;
y2 = y1;
}
};
//Clear
clear.Click += delegate {
C.DrawARGB(255,0,0,0);
IV.SetImageBitmap (BM);
};
//Save
save.Click += delegate {
ExportBitmapAsPNG(BM);
};
}
示例11: GetOvalBitmap
/// <summary>
/// Gets the oval bitmap.
/// </summary>
/// <returns>The oval bitmap.</returns>
/// <param name="bitmap">Bitmap.</param>
private Bitmap GetOvalBitmap(Bitmap bitmap)
{
Bitmap output = null;
if(bitmap != null)
{
output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
RectF rectF = new RectF(rect);
paint.AntiAlias = true;
canvas.DrawARGB(0, 0, 0, 0);
paint.Color = Color.Red;
canvas.DrawOval(rectF, paint);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
canvas.DrawBitmap(bitmap, rect, rect, paint);
}
return output;
}
示例12: GetRoundedCornerBitmap
public static Bitmap GetRoundedCornerBitmap (Bitmap bitmap, int cornerRadius)
{
Bitmap output = Bitmap.CreateBitmap (bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(output);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
RectF rectF = new RectF(rect);
float roundPx = cornerRadius;
paint.AntiAlias = true;
canvas.DrawARGB(0, 0, 0, 0);
paint.SetColorFilter (new ColorFilter ());
canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
canvas.DrawBitmap (bitmap, rect, rect, paint);
return output;
}
示例13: GetCircleBitmap
private Bitmap GetCircleBitmap(int radius)
{
var output = Bitmap.CreateBitmap (_originBitmap.Width, _originBitmap.Height, Bitmap.Config.Argb8888);
using (var canvas = new Canvas (output))
using (var paint = new Paint (PaintFlags.AntiAlias))
using (var rect = new Rect ((int)(_x - radius), (int)(_y - radius), (int)(_x + radius), (int)(_y + radius))) {
canvas.DrawARGB (0, 0, 0, 0);
canvas.DrawCircle (_x, _y, radius, paint);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
canvas.DrawBitmap (_originBitmap, rect, rect, paint);
return output;
}
}
示例14: getCircleBitmap
public static Bitmap getCircleBitmap(Context context, Bitmap input, int w , int h)
{
//CREAMOS UN BITMAP TEMP CON LAS DIMENSIONES QUE LE PASAMOS
Bitmap output = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
//CRAMOS UN CANVAS EL CUAL NOS PERMITIRA DIBUJAR EL CIRCULO QUE NOS SERVIRA COMO MASCARA Y LE ASIGNAMOS EL BITMAP
Canvas canvas = new Canvas(output);
canvas.DrawARGB(0, 255, 0, 0);
//DEFINIMOS UNA BROCHA YA QUE ES NECESARIA PARA DIBUJAR EL CIRCULO
Paint paint = new Paint();
paint.AntiAlias=true;
//string color = "#ff0002";
//paint.Color=Color.ParseColor (color);
//DIBUJAMOS EL CIRCULO DENTRO DEL CANVAS
canvas.DrawCircle(canvas.Height /2,canvas.Height /2,canvas.Height /2, paint);
//LE APLICAMOS UN FILTRO A NUESTRA BROCHA PARA QUE CUANDO SE CONBINEN LOS ELEMENTOS DE LA IMAGEN ORIGINAL CON LA DIBUJADA EN EL CANVAS
//ESTA APLIQUE EL RECORTE DE LA MASCARA
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
//LE ASIGNAMOS AL FONDO DE NUESTRO CANVAS LA IMAGEN QUE QUEREMOS QUE SE APLIQUE LA MASCARA, EN ESTE CASO ES LA IMAGEN
//QUE SE LE ASIGNO AL CONTROL
canvas.DrawBitmap(input, 0,0, paint);
//REGRESAMOS LA IMAGEN YA RECOTADA
return output;
}
示例15: MakeImageRound
private static Bitmap MakeImageRound (Bitmap bitmap)
{
Bitmap output = Bitmap.CreateBitmap (bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
var canvas = new Canvas (output);
var rect = new Rect (0, 0, bitmap.Width, bitmap.Height);
var rectF = new RectF (rect);
var paint = new Paint ();
paint.AntiAlias = true;
paint.Color = Color.Black;
canvas.DrawARGB (0, 0, 0, 0);
canvas.DrawRoundRect (rectF, bitmap.Width, bitmap.Height, paint);
paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
canvas.DrawBitmap (bitmap, rect, rect, paint);
return output;
}