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


C# Bitmap.Recycle方法代码示例

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


在下文中一共展示了Bitmap.Recycle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Transform

        public Bitmap Transform(Bitmap source)
        {
            int size = Math.Min(source.Width, source.Height);

            int width = (source.Width - size) / 2;
            int height = (source.Height - size) / 2;

            var bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb4444);

            var canvas = new Canvas(bitmap);
            var paint = new Paint();
            var shader =
                new BitmapShader(source, BitmapShader.TileMode.Clamp, BitmapShader.TileMode.Clamp);
            if (width != 0 || height != 0)
            {
                // source isn't square, move viewport to center
                var matrix = new Matrix();
                matrix.SetTranslate(-width, -height);
                shader.SetLocalMatrix(matrix);
            }
            paint.SetShader(shader);
            paint.AntiAlias = true;

            float r = size / 2f;
            canvas.DrawCircle(r, r, r, paint);

            source.Recycle();

            return bitmap;
        }
开发者ID:nepula-h-okuyama,项目名称:DroidKaigi2016Xamarin,代码行数:30,代码来源:CropCircleTransformation.cs

示例2: Transform

		protected override Bitmap Transform(IBitmapPool bitmapPool, Bitmap source, int outWidth, int outHeight)
		{
			int size = Math.Min(source.Width, source.Height);

			int width = (source.Width - size) / 2;
			int height = (source.Height - size) / 2;

			Bitmap squaredBitmap = Bitmap.CreateBitmap(source, width, height, size, size);
			if (squaredBitmap != source)
			{
				source.Recycle();
			}

			Bitmap bitmap = Bitmap.CreateBitmap(size, size, Bitmap.Config.Argb8888);

			Canvas canvas = new Canvas(bitmap);
			Paint paint = new Paint();
			BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.Clamp,
					BitmapShader.TileMode.Clamp);
			paint.SetShader(shader);
			paint.AntiAlias = true;

			float r = size / 2f;
			canvas.DrawCircle(r, r, r, paint);

			squaredBitmap.Recycle();

			return BitmapResource.Obtain(bitmap, bitmapPool).Get();
		}
开发者ID:thanhdatbkhn,项目名称:GlideXamarinBinding,代码行数:29,代码来源:CircleTransform.cs

示例3: rotateImage

        // Rotates the bitmap by the specified degree.
        // If a new bitmap is created, the original bitmap is recycled.
        internal static Bitmap rotateImage(Bitmap b, int degrees)
        {
            if (degrees != 0 && b != null)
            {
                Matrix m = new Matrix();
                m.SetRotate(degrees,
                        (float)b.Width / 2, (float)b.Height / 2);
                try
                {
                    Bitmap b2 = Bitmap.CreateBitmap(
                            b, 0, 0, b.Width, b.Height, m, true);
                    if (b != b2)
                    {
                        b.Recycle();
                        b = b2;
                    }
                }
                catch (Java.Lang.OutOfMemoryError)
                {
                    // We have no memory to rotate. Return the original bitmap.
                }
            }

            return b;
        }
开发者ID:nielscup,项目名称:ImageCrop,代码行数:27,代码来源:Util.cs

示例4: Recycle

 public static void Recycle(Bitmap bitmap)
 {
     if (bitmap != null && !bitmap.IsRecycled)
     {
         bitmap.Recycle();
         System.GC.Collect();
     }
 }
开发者ID:fawuser,项目名称:IRMGARD,代码行数:8,代码来源:MemoryHelper.cs

示例5: DisposeBitmap

 private static void DisposeBitmap(Bitmap bitmap)
 {
     if (bitmap != null)
     {
         if (!bitmap.IsRecycled)
         {
             bitmap.Recycle();
         }
         bitmap.Dispose();
     }
 }
开发者ID:mattleibow,项目名称:Genetics,代码行数:11,代码来源:BitmapGene.cs

示例6: Transform

		public Bitmap Transform (Bitmap bitmap)
		{
			int size = Math.Min(bitmap.Width, bitmap.Height);
			int x = (bitmap.Width - size) / 2;
			int y = (bitmap.Height - size) / 2;
			Bitmap result = Bitmap.CreateBitmap(bitmap, x, y, size, size);
			if (result != bitmap) {
				bitmap.Recycle();
			}
			return result;
		}
开发者ID:kktanpiya,项目名称:kimuraHazuki048,代码行数:11,代码来源:CropSquareTransformation.cs

示例7: Transform

 public Bitmap Transform(Bitmap source)
 {
     int size = Math.Min(source.Width / 3, source.Height);
     int x = (source.Width - size) / 3;
     int y = (source.Height - size) / 2;
     Bitmap result = Bitmap.CreateBitmap(source, x, y, size, size);
     if (result != source) {
         source.Recycle();
     }
     return result;
 }
开发者ID:Clancey,项目名称:XamBindings,代码行数:11,代码来源:MainActivity.cs

示例8: 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.SetShader(new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp));
            canvas.DrawRoundRect(new RectF(margin, margin, width - margin, height - margin), radius, radius, paint);
            source.Recycle();

            return bitmap;
        }
开发者ID:dbeattie71,项目名称:FFImageLoading,代码行数:16,代码来源:RoundedCornersTransformation.cs

示例9: 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;
        }
开发者ID:dbeattie71,项目名称:FFImageLoading,代码行数:16,代码来源:ColorFilterTransformation.cs

示例10: 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;
        }
开发者ID:dbeattie71,项目名称:FFImageLoading,代码行数:17,代码来源:GrayscaleTransformation.cs

示例11: 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;
        }
开发者ID:fitzhex,项目名称:testrepo,代码行数:36,代码来源:GrayscaleTransformation.cs

示例12: DismissBitmap

        private void DismissBitmap(Bitmap bitmap)
        {
            if (bitmap != null)
            {
                bitmap.Recycle();
                bitmap.Dispose();

                GC.Collect();
            }
        }
开发者ID:baitun,项目名称:BGUEP-Journal,代码行数:10,代码来源:EasyPagerAdapter.cs

示例13: 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;
        }
开发者ID:makeout,项目名称:MonoGame,代码行数:59,代码来源:ESTexture2D.cs

示例14: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            if (mixerValue == null) // don't do anything if we're not connected to a mixervalue
                return;

            if (bmp == null) {
                bmp = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Fader_Knob);
                Bitmap scaled = Bitmap.CreateScaledBitmap (bmp, 25, 55, true);
                bmp.Recycle();
                bmp = scaled;
            }

            int margin = 60;
            float radius = 4;
            int center = (Width / 2) + 5;
            int minY1 = margin - (bmp.Height / 2);
            int maxY1 = Height - margin - (bmp.Height / 2);
            rangeY = maxY1 - minY1;
            float factor = (float)mixerValue.GetValue() / (float)maxValue;

            bitmapX1 = center - bmp.Width / 2;
            bitmapY1 = maxY1 - (int)(factor * (float)rangeY);

            base.OnDraw (canvas);

            var paint = new Paint ();
            paint.Color = Color.White;
            paint.TextAlign = Paint.Align.Center;
            paint.TextSize = (float)12.0;
            paint.SetTypeface(Typeface.DefaultBold);

            if (channel_name != null)
                canvas.DrawText (channel_name, center - 5, 14, paint); // align with pan control

            int levelX1 = center - (bmp.Width / 2) - 2;
            int levelX2 = center + (bmp.Width / 2);

            paint.TextSize = (float)10.0;
            paint.TextAlign = Paint.Align.Right;

            foreach (var level in faderLevels) {
                float factorLevel = (float)level.Key / (float)maxValue;
                int levelY = maxY1 - (int)(factorLevel * (float)rangeY) + (bmp.Height / 2);

                canvas.DrawRect (levelX1, levelY - 1, levelX2, levelY, paint);
                canvas.DrawText (level.Value, levelX1 - 4, levelY + 3, paint);
            }

            paint.Color = Color.DarkGray;
            RectF rect = new RectF (center - 2, margin, center + 2, Height - margin);
            canvas.DrawRoundRect(rect, radius, radius, paint);
            paint.Color = Color.Black;
            rect = new RectF (center - 1, margin + 1, center + 1, Height - margin - 1);
            canvas.DrawRoundRect(rect, radius, radius, paint);

            bitmapX2 = bitmapX1 + bmp.Width;
            bitmapY2 = bitmapY1 + bmp.Height;

            if (isActive) {
                paint.Alpha = 255;
            } else {
                paint.Alpha = 180;
            }

            canvas.DrawBitmap (bmp, bitmapX1, bitmapY1, paint);

            //bmp.Recycle ();
        }
开发者ID:GeorgeWieggers,项目名称:QuMixDroid_xamarin,代码行数:68,代码来源:Fader.cs

示例15: SaveOutput

        /// <summary>
        /// Saves the cropped image
        /// </summary>
        /// <param name="croppedImage">the cropped image</param>
        /// <param name="saveUri"> the uri to save the cropped image to</param>
        internal void SaveOutput(Bitmap croppedImage, Android.Net.Uri saveUri)
        {
            if (saveUri == null)
            {
                Log.Error(this.GetType().Name, "invalid image url");
                return;
            }

            using (var outputStream = context.ContentResolver.OpenOutputStream(saveUri))
            {
                if (outputStream != null)
                {
                    croppedImage.Compress(outputFormat, 75, outputStream);
                }
            }

            croppedImage.Recycle();
        }
开发者ID:nielscup,项目名称:ImageCrop,代码行数:23,代码来源:ImageCropView.cs


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