本文整理汇总了C#中Android.Graphics.Paint.SetColorFilter方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.SetColorFilter方法的具体用法?C# Paint.SetColorFilter怎么用?C# Paint.SetColorFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Paint
的用法示例。
在下文中一共展示了Paint.SetColorFilter方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.Main);
_colorMatrix = new ColorMatrix();
_colorMatrixFilter = new ColorMatrixColorFilter(_colorMatrix);
_paint = new Paint();
_paint.SetColorFilter(_colorMatrixFilter);
var contrast = FindViewById<SeekBar>(Resource.Id.contrast);
contrast.KeyProgressIncrement = 1;
contrast.ProgressChanged += ContrastChanged;
var brightness = FindViewById<SeekBar>(Resource.Id.brightness);
brightness.KeyProgressIncrement = 1;
brightness.ProgressChanged += BrightnessChanged;
var saturation = FindViewById<SeekBar>(Resource.Id.saturation);
saturation.KeyProgressIncrement = 1;
saturation.ProgressChanged += SaturationChanged;
var imageSelector = FindViewById<Button>(Resource.Id.selectImage);
imageSelector.Click += ImagesSelectorClick;
_imageViewer = FindViewById<ImageView>(Resource.Id.imageViewer);
}
示例2: Transform
public Bitmap Transform(Bitmap source)
{
Bitmap result = Bitmap.CreateBitmap(source.Width, source.Height, source.GetConfig());
Bitmap noise;
try
{
noise = picasso.Load(Resource.Drawable.noise).Get();
}
catch (Exception)
{
throw new Exception("Failed to apply transformation! Missing resource.");
}
BitmapShader shader = new BitmapShader(noise, Shader.TileMode.Repeat, Shader.TileMode.Repeat);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.SetSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
Paint paint = new Paint(PaintFlags.AntiAlias);
paint.SetColorFilter(filter);
Canvas canvas = new Canvas(result);
canvas.DrawBitmap(source, 0, 0, paint);
paint.SetColorFilter(null);
paint.SetShader(shader);
paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply));
canvas.DrawRect(0, 0, canvas.Width, canvas.Height, paint);
source.Recycle();
noise.Recycle();
return result;
}
示例3: ToGreyScale
public static Bitmap ToGreyScale(this Bitmap bmp)
{
if (bmp == null) return null;
var height = bmp.Height;
var width = bmp.Width;
var bmpGrayscale = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
var canvas = new Canvas(bmpGrayscale);
var paint = new Paint();
var cm = new ColorMatrix();
cm.SetSaturation(0);
var filter = new ColorMatrixColorFilter(cm);
paint.SetColorFilter(filter);
canvas.DrawBitmap(bmp, 0, 0, paint);
return bmpGrayscale;
}
示例4: ToColorSpace
public static Bitmap ToColorSpace(Bitmap source, ColorMatrix colorMatrix)
{
int width = source.Width;
int height = source.Height;
Bitmap bitmap = Bitmap.CreateBitmap(width, height, source.GetConfig());
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
{
paint.SetColorFilter(new ColorMatrixColorFilter(colorMatrix));
canvas.DrawBitmap(source, 0, 0, paint);
return bitmap;
}
}
示例5: Transform
protected override Bitmap Transform(Bitmap source)
{
int width = source.Width;
int height = source.Height;
Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.AntiAlias = true;
paint.SetColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SrcAtop));
canvas.DrawBitmap(source, 0, 0, paint);
source.Recycle();
return bitmap;
}
示例6: Transform
protected override Bitmap Transform(Bitmap source)
{
int width = source.Width;
int height = source.Height;
Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
Canvas canvas = new Canvas(bitmap);
ColorMatrix saturation = new ColorMatrix();
saturation.SetSaturation(0f);
Paint paint = new Paint();
paint.SetColorFilter(new ColorMatrixColorFilter(saturation));
canvas.DrawBitmap(source, 0, 0, paint);
source.Recycle();
return bitmap;
}
示例7: OnDraw
protected override void OnDraw(Canvas canvas)
{
if (_image != null && _filter != null) {
var cFilter = new ColorMatrixColorFilter (_filter);
Paint paint = new Paint ();
paint.SetColorFilter (cFilter);
Matrix matrix = new Matrix ();
canvas.Save ();
float horizotalScale = (Right - Left) / (float)_image.Width;
float verticalScale = (Bottom - Top) / (float)_image.Height;
float scale = horizotalScale < verticalScale ? horizotalScale : verticalScale;
matrix.SetScale (scale,scale);
canvas.DrawBitmap (_image, matrix, paint);
canvas.Restore ();
}
}
示例8: ToSolidColor
public static Bitmap ToSolidColor(Bitmap sourceBitmap, int r, int g, int b, int a)
{
var config = sourceBitmap?.GetConfig();
if (config == null)
{
config = Bitmap.Config.Argb8888;
}
int width = sourceBitmap.Width;
int height = sourceBitmap.Height;
Bitmap bitmap = Bitmap.CreateBitmap(width, height, config);
using (Canvas canvas = new Canvas(bitmap))
{
using (Paint paint = new Paint())
{
PorterDuffColorFilter cf = new PorterDuffColorFilter(Color.Argb(a, r, g, b), PorterDuff.Mode.SrcAtop);
paint.SetColorFilter(cf);
canvas.DrawBitmap(sourceBitmap, 0, 0, paint);
return bitmap;
}
}
}
示例9: ToColorSpace
public static Bitmap ToColorSpace(Bitmap source, ColorMatrix colorMatrix)
{
var config = source.GetConfig();
if (config == null)
config = Bitmap.Config.Argb8888; // This will support transparency
int width = source.Width;
int height = source.Height;
Bitmap bitmap = Bitmap.CreateBitmap(width, height, config);
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
{
paint.SetColorFilter(new ColorMatrixColorFilter(colorMatrix));
canvas.DrawBitmap(source, 0, 0, paint);
return bitmap;
}
}
示例10: 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;
}
示例11: GetBrushImageWithColor
private ImageView GetBrushImageWithColor(ImageView brushImage, Android.Graphics.Color color)
{
ImageView toReturn = new ImageView (context);
using (Bitmap sourceBitmap = brushImage.DrawingCache) {
if (sourceBitmap != null) {
float R = (float)color.R;
float G = (float)color.G;
float B = (float)color.B;
float[] colorTransform =
{
R / 255f ,0 ,0 ,0, 0, // R color
0, G / 255f , 0 ,0 ,0 // G color
,0 ,0 , B / 255f, 0, 0 // B color
,0 ,0 ,0 ,1f ,0f
};
ColorMatrix colorMatrix = new ColorMatrix ();
colorMatrix.SetSaturation (0f); //Remove Colour
colorMatrix.Set (colorTransform);
ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter (colorMatrix);
Paint paint = new Paint ();
paint.SetColorFilter (colorFilter);
Bitmap mutableBitmap = sourceBitmap.Copy (Bitmap.Config.Argb8888, true);
toReturn.SetImageBitmap (mutableBitmap);
Canvas canvas = new Canvas (mutableBitmap);
canvas.DrawBitmap (mutableBitmap, 0, 0, paint);
}
}
return toReturn;
}
示例12: changeBitmapContrastBrightness
public static Bitmap changeBitmapContrastBrightness (Bitmap bmp, float contrast, float brightness)
{
ColorMatrix cm = new ColorMatrix (new float[] {
contrast, 0, 0, 0, brightness,
0, contrast, 0, 0, brightness,
0, 0, contrast, 0, brightness,
0, 0, 0, 1, 0
});
cm.SetSaturation (0);
Bitmap ret = Bitmap.CreateBitmap (bmp.Width, bmp.Height, bmp.GetConfig ());
Canvas canvas = new Canvas (ret);
Paint paint = new Paint ();
paint.SetColorFilter (new ColorMatrixColorFilter (cm));
canvas.DrawBitmap (bmp, 0, 0, paint);
return ret;
}