• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Graphics.Bitmap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Bitmap类属于Android.Graphics命名空间,在下文中一共展示了Bitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetResizedBitmapAsync

        public async Task<Bitmap> GetResizedBitmapAsync(string path, int width, int height)
        {
            if (_originalBitmap != null)
            {
                return _originalBitmap;
            }

            #region Get some some information about the bitmap so we can resize it
            BitmapFactory.Options options = new BitmapFactory.Options
                                            {
                                                InJustDecodeBounds = true
                                            };

            using (Stream stream = _context.Assets.Open(path))
            {
                await BitmapFactory.DecodeStreamAsync(stream);
            }
            await BitmapFactory.DecodeFileAsync(path, options);
            #endregion

            // Calculate the factor by which we should reduce the image by
            options.InSampleSize = CalculateInSampleSize(options, width, height);

            #region Go and load the image and resize it at the same time.
            options.InJustDecodeBounds = false;

            using (Stream inputSteam = _context.Assets.Open(path))
            {
                _originalBitmap = await BitmapFactory.DecodeStreamAsync(inputSteam);
            }
            #endregion

            return _originalBitmap;
        }
开发者ID:4lenz1,项目名称:recipes,代码行数:34,代码来源:ImageHelper.cs


示例2: SaveFromMemory

        private static void SaveFromMemory(PixelBuffer[] pixelBuffers, int count, ImageDescription description, Stream imageStream, Bitmap.CompressFormat imageFormat)
        {
            var colors = pixelBuffers[0].GetPixels<int>();

            using (var bitmap = Bitmap.CreateBitmap(description.Width, description.Height, Bitmap.Config.Argb8888))
            {
                var pixelData = bitmap.LockPixels();
                var sizeToCopy = colors.Length * sizeof(int);

                unsafe
                {
                    fixed (int* pSrc = colors)
                    {
                        // Copy the memory
                        if (description.Format == PixelFormat.R8G8B8A8_UNorm || description.Format == PixelFormat.R8G8B8A8_UNorm_SRgb)
                        {
                            CopyMemoryBGRA(pixelData, (IntPtr)pSrc, sizeToCopy);
                        }
                        else if (description.Format == PixelFormat.B8G8R8A8_UNorm || description.Format == PixelFormat.B8G8R8A8_UNorm_SRgb)
                        {
                            Utilities.CopyMemory(pixelData, (IntPtr)pSrc, sizeToCopy);
                        }
                        else
                        {
                            throw new NotSupportedException(string.Format("Pixel format [{0}] is not supported", description.Format));
                        }
                    }
                }

                bitmap.UnlockPixels();
                bitmap.Compress(imageFormat, 100, imageStream);
            }
        }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:StandardImageHelper.Android.cs


示例3: ToRounded

		public static Bitmap ToRounded(Bitmap source, float rad, double cropWidthRatio, double cropHeightRatio, double borderSize, string borderHexColor)
		{
			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);

			float cropX = (float)((sourceWidth - desiredWidth) / 2d);
			float cropY = (float)((sourceHeight - desiredHeight) / 2d);

			if (rad == 0)
				rad = (float)(Math.Min(desiredWidth, desiredHeight) / 2d);
			else
				rad = (float)(rad * (desiredWidth + desiredHeight) / 2d / 500d);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			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 = true;

				RectF rectF = new RectF(0f, 0f, (float)desiredWidth, (float)desiredHeight);
				canvas.DrawRoundRect(rectF, rad, rad, paint);

				if (borderSize > 0d) 
				{
					borderSize = (borderSize * (desiredWidth + desiredHeight) / 2d / 500d);
					paint.Color = borderHexColor.ToColor(); ;
					paint.SetStyle(Paint.Style.Stroke);
					paint.StrokeWidth = (float)borderSize;
					paint.SetShader(null);

					RectF borderRectF = new RectF((float)(0d + borderSize/2d), (float)(0d + borderSize/2d), 
						(float)(desiredWidth - borderSize/2d), (float)(desiredHeight - borderSize/2d));

					canvas.DrawRoundRect(borderRectF, rad, rad, paint);
				}

				return bitmap;				
			}
		}
开发者ID:CaLxCyMru,项目名称:FFImageLoading,代码行数:60,代码来源:RoundedTransformation.cs


示例4: AchievementElement

 public AchievementElement(string caption = null, string description = null, int percentageComplete = 0, Bitmap achievementImage = null)
     : base(caption, "dialog_achievements")
 {
     Description = description;
     PercentageComplete = percentageComplete;
     AchievementImage = achievementImage;
 }
开发者ID:talisqualis,项目名称:MvvmCross-Build,代码行数:7,代码来源:AchievementElement.cs


示例5: decodeByteArray

        public static Bitmap decodeByteArray(byte[] buffer, int offset, int length)
        {
            JNIFind();

            if (_jcBitmapFactory == IntPtr.Zero)
            {
                Debug.LogError("_jcBitmapFactory is not initialized");
                return null;
            }
            if (_jmDecodeByteArray == IntPtr.Zero)
            {
                Debug.LogError("_jmDecodeByteArray is not initialized");
                return null;
            }
            IntPtr arg1 = AndroidJNI.ToByteArray(buffer);
            IntPtr retVal = AndroidJNI.CallStaticObjectMethod(_jcBitmapFactory, _jmDecodeByteArray, new jvalue[] { new jvalue() { l = arg1 }, new jvalue() { i = offset }, new jvalue() { i = length } });
            AndroidJNI.DeleteLocalRef(arg1);

            if (retVal == IntPtr.Zero)
            {
                Debug.LogError("decodeByteArray returned null bitmap");
                return null;
            }

            IntPtr globalRef = AndroidJNI.NewGlobalRef(retVal);
            AndroidJNI.DeleteLocalRef(retVal);

            Bitmap result = new Bitmap(globalRef);
            return result;
        }
开发者ID:thoniorf,项目名称:ouya-sdk-examples,代码行数:30,代码来源:BitmapFactory.cs


示例6: CreateTask

 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public static Couchbase.Lite.Document CreateTask(Database database, string title, 
     Bitmap image, string listId)
 {
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
         );
     Calendar calendar = GregorianCalendar.GetInstance();
     string currentTimeString = dateFormatter.Format(calendar.GetTime());
     IDictionary<string, object> properties = new Dictionary<string, object>();
     properties.Put("type", DocType);
     properties.Put("title", title);
     properties.Put("checked", false);
     properties.Put("created_at", currentTimeString);
     properties.Put("list_id", listId);
     Couchbase.Lite.Document document = database.CreateDocument();
     UnsavedRevision revision = document.CreateRevision();
     revision.SetUserProperties(properties);
     if (image != null)
     {
         ByteArrayOutputStream @out = new ByteArrayOutputStream();
         image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
         ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
         revision.SetAttachment("image", "image/jpg", @in);
     }
     revision.Save();
     return document;
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:27,代码来源:Task.cs


示例7: BitmapToByteArray

 public static byte[] BitmapToByteArray(Bitmap bitmap)
 {
     ByteBuffer byteBuffer = ByteBuffer.Allocate(bitmap.ByteCount);
     bitmap.CopyPixelsToBuffer(byteBuffer);
     byte[] bytes = byteBuffer.ToArray<byte>();
     return bytes;
 }
开发者ID:chikerenda,项目名称:Android-labs,代码行数:7,代码来源:BitmapConverter.cs


示例8: LoadFromResource

        public void LoadFromResource(string assemblyName,MvxResourcePath resourcePath)
        {
            var resourceName = resourcePath.GetResourcePath (".",true);
            var strm = Assembly.Load (new AssemblyName(assemblyName)).GetManifestResourceStream(resourceName);

            bitmap = BitmapFactory.DecodeStream (strm);
        }
开发者ID:hugoterelle,项目名称:mvvmcross-bitmap-plugin,代码行数:7,代码来源:MvxAndroidBitmap.cs


示例9: putBitmap

		public void putBitmap (string key, Bitmap bitmap)
		{
			Put (key, bitmap);

			// An entry has been added, so invalidate the snapshot
			mLastSnapshot = null;
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:7,代码来源:ImageMemoryCache.cs


示例10: DrawBackground

        void DrawBackground()
        {
            if (background != null) {
                background.Dispose ();
            }
            background = Bitmap.CreateBitmap(screen_size.Width, screen_size.Height, Bitmap.Config.Argb8888);
            Canvas c = new Canvas (background);
            //Paint black = new Paint();
            //black.SetARGB(255, 0, 0, 0);
            //black.SetStyle (Paint.Style.Stroke);
            //Bitmap plaatje = blokken[2].DrawBlok (MainActivity.context);

            //DrawBitmap werkt niet voor scaling bitmaps in xamarin
            //c.DrawBitmap (plaatje, new Rect (0, 0, plaatje.Width, plaatje.Height), new RectF (blokken[2].X, blokken[2].Y, blokken[2].Width, blokken[2].Height), null);
            //c.DrawBitmap(plaatje,96,0,null);

            foreach (Blok b in blokken)
            {
                Bitmap plaatje = b.DrawBlok (MainActivity.context);
                c.DrawBitmap (plaatje, b.X, b.Y, null);
                plaatje.Dispose ();
            }
            c.Dispose ();
            //black.Dispose ();
        }
开发者ID:Z3R0X92,项目名称:XAMARIN,代码行数:25,代码来源:BKE_Activity.cs


示例11: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            //SetTheme(Resource.Style.Theme_Sherlock_Light);
            SetTheme(Resource.Style.Theme_Example);
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.IndeterminateProgress);
            SetSupportProgressBarIndeterminateVisibility(false);
            Sherlock.ActionBar.SetDisplayHomeAsUpEnabled(true);

            SetContentView(Resource.Layout.Main);
            // Show tabs
            ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
            
            // attach adapter to the viewpager
            _pageAdapter = new ArtistPagerAdapter(SupportFragmentManager);
            _viewPager = FindViewById<ViewPager>(Resource.Id.myViewPager);
            _viewPager.Adapter = _pageAdapter;
            _viewPager.SetOnPageChangeListener(this);
            // startindex
            _viewPager.SetCurrentItem(0, true);

            var jsonArtist = Intent.GetStringExtra("Artist");
            _artist = JsonConvert.DeserializeObject<Artist>(jsonArtist);
            var jsonTopTracks = Intent.GetStringExtra("TopTracks");
            _topTracks = JsonConvert.DeserializeObject<TopTracks>(jsonTopTracks);
            var jsonTopAlbums = Intent.GetStringExtra("TopAlbums");
            _topAlbums = JsonConvert.DeserializeObject<TopAlbums>(jsonTopAlbums);

            _bitmapExtension = new BitmapExtension();
            try
            {
                _imageBitmap = _bitmapExtension.GetImageBitmapFromUrl(_artist.GetImageUrlOfSize("large"));
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, "Error: " + ex.Message, ToastLength.Short).Show();
            }

            //TABS
            var tab1 = Sherlock.ActionBar.NewTab();
            tab1.SetText("Artist");
            tab1.SetTabListener(this);

            var tab2 = Sherlock.ActionBar.NewTab();
            tab2.SetText("Similar Artists");
            tab2.SetTabListener(this);

            var tab3 = Sherlock.ActionBar.NewTab();
            tab3.SetText("Top 15 Tracks");
            tab3.SetTabListener(this);

            var tab4 = Sherlock.ActionBar.NewTab();
            tab4.SetText("Top 5 Albums");
            tab4.SetTabListener(this);

            Sherlock.ActionBar.AddTab(tab1);
            Sherlock.ActionBar.AddTab(tab2);
            Sherlock.ActionBar.AddTab(tab3);
            Sherlock.ActionBar.AddTab(tab4);
        }
开发者ID:jonteho,项目名称:last.fm-appcrossplat,代码行数:60,代码来源:ArtistActivity.cs


示例12: OnTouchEvent

        public override bool OnTouchEvent(MotionEvent e)
        {
            _Paint = new Paint ();
            _Paint.Color = new Android.Graphics.Color (255, 0, 0);
            _Paint.StrokeWidth = 20;
            _Paint.StrokeCap = Paint.Cap.Round;
            var imageView = FindViewById<ImageView> (Resource.Id.myImageView);
            Bitmap immutableBitmap = MediaStore.Images.Media.GetBitmap(this.ContentResolver, imageUri);
            _Bmp = immutableBitmap.Copy(Bitmap.Config.Argb8888, true);
            _Canvas = new Canvas(_Bmp);
            imageView.SetImageBitmap (_Bmp);
                switch (e.Action)
                {

                default:
                {
                    _StartPt.X=e.RawX;
                    _StartPt.Y=e.RawY;
                    Console.WriteLine ("inside default:{0}","default");
                    DrawPoint (_Canvas);
                    break;
                }
                }

            return true;
        }
开发者ID:sdhakal,项目名称:imageProject,代码行数:26,代码来源:MainActivity.cs


示例13: 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


示例14: getRoundedCroppedBitmap

		public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
			Bitmap finalBitmap;
			if (bitmap.Width != radius || bitmap.Height!= radius)
				finalBitmap = Bitmap.CreateScaledBitmap(bitmap, radius, radius,
					false);
			else
				finalBitmap = bitmap;
			Bitmap output = Bitmap.CreateBitmap(finalBitmap.Width,
				finalBitmap.Height, Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas(output);

			 Paint paint = new Paint();
			Rect rect = new Rect(0, 0, finalBitmap.Width,
				finalBitmap.Height);

			paint.AntiAlias=true;
			paint.FilterBitmap=true;
			paint.Dither=true;
			canvas.DrawARGB(0, 0, 0, 0);
			paint.Color=Color.ParseColor("#BAB399");
			canvas.DrawCircle(finalBitmap.Width / 2 + 0.7f,
				finalBitmap.Height / 2 + 0.7f,
				finalBitmap.Width / 2 + 0.1f, paint);
			paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
			canvas.DrawBitmap(finalBitmap, rect, rect, paint);

			return output;
		}	
开发者ID:IanLeatherbury,项目名称:tryfsharpforms,代码行数:28,代码来源:RoundedImageView.cs


示例15: OnFrameAvailable

        public Bitmap OnFrameAvailable(Bitmap bitmap)
        {
            if (shouldBlur)
                return blur.BlurImage(bitmap);

            return bitmap;
        }
开发者ID:rui-moreira,项目名称:GifImageView-Xamarin.Android,代码行数:7,代码来源:MainActivity.cs


示例16: Save

        /// <summary>
        /// Saves the specified surface as an image with the specified format.
        /// </summary>
        /// <param name="renderTarget">The surface to save.</param>
        /// <param name="stream">The stream to which to save the surface data.</param>
        /// <param name="format">The format with which to save the image.</param>
        private void Save(Surface2D surface, Stream stream, Bitmap.CompressFormat format)
        {
            var data = new Color[surface.Width * surface.Height];
            surface.GetData(data);

            Save(data, surface.Width, surface.Height, stream, format);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:13,代码来源:AndroidSurfaceSaver.cs


示例17: AchievementElement

		public AchievementElement(string caption, string description, int percentageComplete, Bitmap achievementImage)
            : base(caption, (int)DroidResources.ElementLayout.dialog_achievements)
        {
			Description = description;
			PercentageComplete = percentageComplete;
			AchievementImage = achievementImage;
        }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:7,代码来源:AchievementElement.cs


示例18: 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


示例19: GetRoundedCornerBitmap

		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
开发者ID:suchithm,项目名称:SampleImageBitMap,代码行数:31,代码来源:ImageHelper.cs


示例20: OnSizeChanged

		protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
		{
			base.OnSizeChanged(w, h, oldw, oldh);

			CanvasBitmap = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
			DrawCanvas = new Canvas(CanvasBitmap);
		}
开发者ID:kimuraeiji214,项目名称:Keys,代码行数:7,代码来源:DrawView.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BitmapFactory.Options类代码示例发布时间:2022-05-24
下一篇:
C# Model.MarkerOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap