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


C# Paint.Dispose方法代码示例

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


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

示例1: InitializeImages

        private void InitializeImages()
        {
            if(_pressedImage != null)
            {
                _pressedImage.Recycle();
                _pressedImage.Dispose();
            }
            if(_unpressedImage != null)
            {
                _unpressedImage.Recycle();
                _unpressedImage.Dispose();
            }

            _unpressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            _pressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            Canvas unpressedCanvas = new Canvas(_unpressedImage);
            Canvas pressedCanvas = new Canvas(_pressedImage);

            Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize == 0f ? Height * Settings.TextSizeRatio : Settings.TextSize);
            Settings.StrokeBorderWidth = Height * Settings.StrokeBorderWidthRatio;
            Settings.StrokeTextWidth = Height * Settings.StrokeTextWidthRatio;

            // Background fill paint
            Paint fillBackPaint = new Paint();
            fillBackPaint.Color = Settings.FillColor;
            fillBackPaint.AntiAlias = true;

            // Background stroke paint
            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Settings.StrokeColor;
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = Settings.StrokeBorderWidth;
            strokeBackPaint.AntiAlias = true;

            // Text paint
            Paint textPaint = new Paint();
            textPaint.Color = Settings.IsTextStroked ? Settings.FillColor : Settings.StrokeColor;
            textPaint.TextAlign = Paint.Align.Center;
            textPaint.TextSize = Settings.TextSize;
            textPaint.SetTypeface(Settings.Typeface);
            textPaint.AntiAlias = true;

            // Text stroke paint
            Paint strokePaint = new Paint();
            strokePaint.Color = Settings.StrokeColor;
            strokePaint.TextAlign = Paint.Align.Center;
            strokePaint.TextSize = Settings.TextSize;
            strokePaint.SetTypeface(Settings.Typeface);
            strokePaint.SetStyle(Paint.Style.Stroke);
            strokePaint.StrokeWidth = Settings.StrokeTextWidth;
            strokePaint.AntiAlias = true;

            // Background bounds
            Rect local = new Rect();
            this.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Top += Settings.StrokeBorderWidth/2;
            bounds.Left += Settings.StrokeBorderWidth/2;
            bounds.Right -= Settings.StrokeBorderWidth/2;
            bounds.Bottom -= Settings.StrokeBorderWidth/2;

            while(bounds.Top > Height)
            {
                bounds.Top -= Height;
            }
            while(bounds.Bottom > Height)
            {
                bounds.Bottom -= Height;
            }
            while(bounds.Left > Width)
            {
                bounds.Left -= Width;
            }
            while(bounds.Right > Width)
            {
                bounds.Right -= Width;
            }

            // Text location
            Rect r = new Rect();
            strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            while(r.Width() + Settings.StrokeTextWidth >= bounds.Width())
            {
                Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize-1);
                textPaint.TextSize = Settings.TextSize;
                strokePaint.TextSize = Settings.TextSize;
                strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            }

            float x=0, y=0;
            switch (Settings.Gravity)
            {
            case GravityFlags.Top:
                y = PaddingTop + r.Height()/2;
                break;
            case GravityFlags.Bottom:
                y = Height - r.Height()/2 - PaddingBottom;
                break;
            default:
                y = Height / 2f + r.Height() / 2f - r.Bottom;
//.........这里部分代码省略.........
开发者ID:lea-and-anthony,项目名称:Tetrim,代码行数:101,代码来源:ButtonStroked.cs


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