本文整理汇总了C#中Android.Graphics.Bitmap.GetConfig方法的典型用法代码示例。如果您正苦于以下问题:C# Bitmap.GetConfig方法的具体用法?C# Bitmap.GetConfig怎么用?C# Bitmap.GetConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.GetConfig方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Binarize
public static Bitmap Binarize(Bitmap bm, double threshhold)
{
//Binarize
int size = bm.Width * bm.Height;
int[] pixels = new int[size];
bm.GetPixels( pixels, 0, bm.Width, 0, 0, bm.Width, bm.Height );
// Calculate overall lightness of image
int c;
for (int i = 0; i < size; i++)
{
c = pixels[i];
double whiteDist = Math.Sqrt(Math.Pow(0xff - ((c&0x00FF0000 )>>16),2) + Math.Pow(0xff - ((c & 0x0000FF00 )>>8), 2) + Math.Pow(0xff - (c&0x000000FF), 2));
double blackDist = Math.Sqrt(Math.Pow(0x00 - ((c&0x00FF0000 )>>16),2) + Math.Pow(0x00 - ((c & 0x0000FF00 )>>8), 2) + Math.Pow(0x00 - (c&0x000000FF), 2));
double distance = blackDist + whiteDist;
if (whiteDist / distance > threshhold / 30.0) {
pixels [i] = Color.Black;
} else {
pixels [i] = Color.White;
}
}
Bitmap newBitmap = bm.Copy (bm.GetConfig (), true);
newBitmap.SetPixels (pixels, 0, bm.Width, 0, 0, bm.Width, bm.Height);
return newBitmap;
}
示例2: ToCropped
public static Bitmap ToCropped(Bitmap source, double zoomFactor, double xOffset, double yOffset, double cropWidthRatio, double cropHeightRatio)
{
double sourceWidth = source.Width;
double sourceHeight = source.Height;
double desiredWidth = sourceWidth;
double desiredHeight = sourceHeight;
double desiredRatio = cropWidthRatio / cropHeightRatio;
double currentRatio = sourceWidth / sourceHeight;
if (currentRatio > desiredRatio)
desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
else if (currentRatio < desiredRatio)
desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
xOffset = xOffset * desiredWidth;
yOffset = yOffset * desiredHeight;
desiredWidth = desiredWidth / zoomFactor;
desiredHeight = desiredHeight / zoomFactor;
float cropX = (float)(((sourceWidth - desiredWidth) / 2) + xOffset);
float cropY = (float)(((sourceHeight - desiredHeight) / 2) + yOffset);
if (cropX < 0)
cropX = 0;
if (cropY < 0)
cropY = 0;
if (cropX + desiredWidth > sourceWidth)
cropX = (float)(sourceWidth - desiredWidth);
if (cropY + desiredHeight > sourceHeight)
cropY = (float)(sourceHeight - desiredHeight);
Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, source.GetConfig());
using (Canvas canvas = new Canvas(bitmap))
using (Paint paint = new Paint())
using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
using (Matrix matrix = new Matrix())
{
if (cropX != 0 || cropY != 0)
{
matrix.SetTranslate(-cropX, -cropY);
shader.SetLocalMatrix(matrix);
}
paint.SetShader(shader);
paint.AntiAlias = false;
RectF rectF = new RectF(0, 0, (int)desiredWidth, (int)desiredHeight);
canvas.DrawRect(rectF, paint);
return bitmap;
}
}
示例3: 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;
}
示例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: CreateOverlayedBitmap
private static Bitmap CreateOverlayedBitmap(Bitmap bitmap, int width, int height)
{
int[] originalPixels = new int[bitmap.Width * bitmap.Height];
bitmap.GetPixels(originalPixels, 0, bitmap.Width, 0, 0, bitmap.Width, bitmap.Height);
int[] pixels = new int[width * height];
int xStart = (width - bitmap.Width) / 2;
int xEnd = (width + bitmap.Width) / 2;
for (int y = 0; y < height; y++)
{
int rowStart = y*width;
int originalRowStart = y*bitmap.Width;
for (int ox = 0, x = xStart; x < xEnd; x++, ox++)
{
pixels[rowStart + x] = originalPixels[originalRowStart + ox];
}
}
return Bitmap.CreateBitmap(pixels, width, height, bitmap.GetConfig());
}
示例6: OnActivityResult
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Ok && requestCode == 1)
{
_imageSelected = true;
Android.Net.Uri selectedImageUri = data.Data;
_originalBitmap = BitmapFactory.DecodeStream(ContentResolver.OpenInputStream(selectedImageUri));
//Create a new mutable Bitmap from original
_canvasBitmap = Bitmap.CreateBitmap(_originalBitmap.Width, _originalBitmap.Height, _originalBitmap.GetConfig());
//Initialize the canvas assigning the mutable Bitmap to it
_canvas = new Canvas(_canvasBitmap);
SetBitmapToImageViewer();
}
}
示例7: Blur
public static Bitmap Blur(Context context, Bitmap input)
{
try {
var rsScript = RenderScript.Create (context);
var alloc = Allocation.CreateFromBitmap (rsScript, input);
var blur = ScriptIntrinsicBlur.Create (rsScript, alloc.Element);
blur.SetRadius (25);
blur.SetInput (alloc);
var result = Bitmap.CreateBitmap (input.Width, input.Height, input.GetConfig ());
var outAlloc = Allocation.CreateFromBitmap (rsScript, result);
blur.ForEach (outAlloc);
outAlloc.CopyTo (result);
rsScript.Destroy ();
return result;
} catch (Exception e) {
Log.Error ("Blurrer", "Error while trying to blur, fallbacking. " + e.ToString ());
return Bitmap.CreateBitmap (input);
}
}
示例8: 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;
}
示例9: ToLegacyBlurred
// Source: http://incubator.quasimondo.com/processing/superfast_blur.php
public static Bitmap ToLegacyBlurred(Bitmap source, Context context, int radius)
{
Bitmap img = source.Copy(source.GetConfig(), true);
int w = img.Width;
int h = img.Height;
int wm = w-1;
int hm = h-1;
int wh = w*h;
int div = radius+radius+1;
int[] r = new int[wh];
int[] g = new int[wh];
int[] b = new int[wh];
int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
int[] vmin = new int[Math.Max(w,h)];
int[] vmax = new int[Math.Max(w,h)];
int[] pix= new int[w*h];
img.GetPixels(pix, 0, w, 0,0,w, h);
int[] dv = new int[256*div];
for (i=0;i<256*div;i++){
dv[i]=(i/div);
}
yw=yi=0;
for (y=0;y<h;y++){
rsum=gsum=bsum=0;
for(i=-radius;i<=radius;i++){
p=pix[yi+Math.Min(wm,Math.Max(i,0))];
rsum+=(p & 0xff0000)>>16;
gsum+=(p & 0x00ff00)>>8;
bsum+= p & 0x0000ff;
}
for (x=0;x<w;x++){
r[yi]=dv[rsum];
g[yi]=dv[gsum];
b[yi]=dv[bsum];
if(y==0){
vmin[x]=Math.Min(x+radius+1,wm);
vmax[x]=Math.Max(x-radius,0);
}
p1=pix[yw+vmin[x]];
p2=pix[yw+vmax[x]];
rsum+=((p1 & 0xff0000)-(p2 & 0xff0000))>>16;
gsum+=((p1 & 0x00ff00)-(p2 & 0x00ff00))>>8;
bsum+= (p1 & 0x0000ff)-(p2 & 0x0000ff);
yi++;
}
yw+=w;
}
for (x=0;x<w;x++){
rsum=gsum=bsum=0;
yp=-radius*w;
for(i=-radius;i<=radius;i++){
yi=Math.Max(0,yp)+x;
rsum+=r[yi];
gsum+=g[yi];
bsum+=b[yi];
yp+=w;
}
yi=x;
for (y=0;y<h;y++){
// Preserve alpha channel: ( 0xff000000 & pix[yi] )
pix[yi] = (int)((0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]);
if(x==0){
vmin[y]=Math.Min(y+radius+1,hm)*w;
vmax[y]=Math.Max(y-radius,0)*w;
}
p1=x+vmin[y];
p2=x+vmax[y];
rsum+=r[p1]-r[p2];
gsum+=g[p1]-g[p2];
bsum+=b[p1]-b[p2];
yi+=w;
}
}
img.SetPixels(pix,0, w,0,0,w,h);
return img;
}
示例10: 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;
}
}
示例11: CreateBlurredImage
private Bitmap CreateBlurredImage(Bitmap inputBitmap)
{
try
{
var rs = RenderScript.Create(m_Context);
var theInstrinsic = ScriptIntrinsicBlur.Create(rs, Element.U8_4(rs));
var outputBitmap = Bitmap.CreateBitmap(inputBitmap.Width, inputBitmap.Height, inputBitmap.GetConfig());
var tmpIn = Allocation.CreateFromBitmap(rs, inputBitmap);
var tmpOut = Allocation.CreateFromBitmap(rs, outputBitmap);
theInstrinsic.SetRadius(m_BlurRadius);
theInstrinsic.SetInput(tmpIn);
theInstrinsic.ForEach(tmpOut);
tmpOut.CopyTo(outputBitmap);
rs.Destroy();
return outputBitmap;
}
catch (Exception)
{
}
return null;
}
示例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;
}
示例13: ChangeColor
private static Bitmap ChangeColor(Bitmap bitmap, Color fromColor, Color targetColor, float tolerance = 20)
{
int width = bitmap.Width;
int height = bitmap.Height;
int[] pixels = new int[width * height];
float[] redRange = new float[2]{
(float)Math.Max(fromColor.R - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.R + (tolerance / 2), 255.0)};
float[] greenRange = new float[2]{
(float)Math.Max(fromColor.G - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.G + (tolerance / 2), 255.0)};
float[] blueRange = new float[2]{
(float)Math.Max(fromColor.B - (tolerance / 2), 0.0),
(float)Math.Min(fromColor.B + (tolerance / 2), 255.0)};
bitmap.GetPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < pixels.Length; i++)
{
if (pixels[i] == fromColor)
{
pixels[i] = new Color(targetColor.R, targetColor.G, targetColor.B, targetColor.A - 1);
}
int red = Color.GetRedComponent(pixels[i]);
int green = Color.GetGreenComponent(pixels[i]);
int blue = Color.GetBlueComponent(pixels[i]);
int alpha = Color.GetAlphaComponent(pixels[i]);
if (((red >= redRange[0]) && (red <= redRange[1])) &&
((green >= greenRange[0]) && (green <= greenRange[1])) &&
((blue >= blueRange[0]) && (blue <= blueRange[1])) &&
((alpha > 0 && alpha < 254)))
{
pixels[i] = new Color(targetColor.R, targetColor.G, targetColor.B, targetColor.A - 1);
}
}
if (bitmap.IsMutable)
{
bitmap.SetPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
else
{
var mutableBitmap = bitmap.Copy(bitmap.GetConfig(), true);
mutableBitmap.SetPixels(pixels, 0, width, 0, 0, width, height);
return mutableBitmap;
}
}