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


C# Bitmap.Copy方法代码示例

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


在下文中一共展示了Bitmap.Copy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
        }
开发者ID:SansSkill,项目名称:Introproject,代码行数:28,代码来源:BitmapHelpers.cs

示例2: 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;
		}
开发者ID:tmkhanh,项目名称:FFImageLoading,代码行数:89,代码来源:BlurredTransformation.cs

示例3: drawFaceRectanglesOnBitmap

        /// <summary>
        /// Mark bitmap with given face information
        /// </summary>
        /// <param name="originalBitmap"></param>
        /// <param name="faces"></param>
        /// <returns></returns>
        private static Bitmap drawFaceRectanglesOnBitmap(Bitmap originalBitmap, Face[] faces)
        {
            Bitmap bitmap = originalBitmap.Copy(Bitmap.Config.Argb8888, true);
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.Color = StrokeColor;
            paint.StrokeWidth = strokeWidth;
            paint.TextSize = textSize;
            if (faces != null)
            {
                foreach(Face face in faces)
                {
                    FaceRectangle faceRectangle = face.FaceRectangle;

                    paint.SetStyle(Paint.Style.Stroke);
                    canvas.DrawRect(
                            faceRectangle.Left,
                            faceRectangle.Top,
                            faceRectangle.Left + faceRectangle.Width,
                            faceRectangle.Top + faceRectangle.Height,
                            paint);

                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawText(face.Attributes.Gender + ", " + 
                        face.Attributes.Age + " y/o", 
                        faceRectangle.Left, faceRectangle.Top - textSize, paint);
                }
            }
            return bitmap;
        }
开发者ID:aweeesome,项目名称:faceit,代码行数:36,代码来源:MainActivity.cs

示例4: 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;
            }
        }
开发者ID:jmmortega,项目名称:NSUtils,代码行数:54,代码来源:ExtensionMethodsDrawable.cs


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