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

C# BitmapFactory.Options类代码示例

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

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



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

示例1: DecodeBitmap

 public static Bitmap DecodeBitmap(string path, int desiredSize)
 {
     var options = new BitmapFactory.Options { InJustDecodeBounds = true };
     BitmapFactory.DecodeFile(path, options);
     options = new BitmapFactory.Options { InSampleSize = desiredSize };
     return BitmapFactory.DecodeFile(path, options);
 }
开发者ID:okrotowa,项目名称:Mosigra.Yorsh,代码行数:7,代码来源:BitmapExtensions.cs


示例2: DecodeSampleBitmapFromFile

		public static Bitmap DecodeSampleBitmapFromFile(string path, int reqWidth, int reqHeight)
		{

			try
			{
				//______________________________________________________________
				// First decode with inJustDecodeBounds=true to check dimensions
				BitmapFactory.Options options = new BitmapFactory.Options();
				options.InJustDecodeBounds = true;
				BitmapFactory.DecodeFile(path, options);
				//BitmapFactory.DecodeStream(url.OpenConnection().InputStream, null, options);

				//______________________
				// Calculate inSampleSize
				options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);

				//____________________________________
				// Decode bitmap with inSampleSize set
				options.InJustDecodeBounds = false;
				return BitmapFactory.DecodeFile(path, options);
			}
			catch (System.Exception ex)
			{
				Log.Debug("DecodeBitmapFromFile: ", ex.Message);
				return null;
			}
			finally
			{
				//
			}
		}
开发者ID:WFoundation,项目名称:WF.Player.Android,代码行数:31,代码来源:BitmapHelpersAndroid.cs


示例3: OnElementPropertyChanged

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var largeImage = (CustomImage)Element;

            if ((Element.Width > 0 && Element.Height > 0 && !isDecoded) || (e.PropertyName == "ImageSource" && largeImage.ImageSource != null))
            {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.InJustDecodeBounds = true;

                //Get the resource id for the image
                if (largeImage.ImageSource != null)
                {
                    var field = typeof(Resource.Drawable).GetField(largeImage.ImageSource.Split('.').First());
                    var value = (int)field.GetRawConstantValue();

                    BitmapFactory.DecodeResource(Context.Resources, value, options);

                    var width = (int)Element.Width;
                    var height = (int)Element.Height;
                    options.InSampleSize = CalculateInSampleSize(options, width, height);

                    options.InJustDecodeBounds = false;
                    var bitmap = BitmapFactory.DecodeResource(Context.Resources, value, options);

                    Control.SetImageBitmap(bitmap);

                    isDecoded = true;
                }
            }

        }
开发者ID:nodoid,项目名称:gridview,代码行数:33,代码来源:CustomImageRenderer.cs


示例4: SimulationView

		public SimulationView (Context context, SensorManager sensorManager, IWindowManager window)
			: base (context)
		{
			Bounds = new PointF ();

			// Get an accelorometer sensor
			sensor_manager = sensorManager;
			accel_sensor = sensor_manager.GetDefaultSensor (SensorType.Accelerometer);

			// Calculate screen size and dpi
			var metrics = new DisplayMetrics ();
			window.DefaultDisplay.GetMetrics (metrics);

			meters_to_pixels_x = metrics.Xdpi / 0.0254f;
			meters_to_pixels_y = metrics.Ydpi / 0.0254f;

			// Rescale the ball so it's about 0.5 cm on screen
			var ball = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Ball);
			var dest_w = (int)(BALL_DIAMETER * meters_to_pixels_x + 0.5f);
			var dest_h = (int)(BALL_DIAMETER * meters_to_pixels_y + 0.5f);
			ball_bitmap = Bitmap.CreateScaledBitmap (ball, dest_w, dest_h, true);

			// Load the wood background texture
			var opts = new BitmapFactory.Options ();
			opts.InDither = true;
			opts.InPreferredConfig = Bitmap.Config.Rgb565;
			wood_bitmap = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);
			wood_bitmap2 = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Wood, opts);

			display = window.DefaultDisplay;
			particles = new ParticleSystem (this);
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:32,代码来源:SimulationView.cs


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


示例6: GetScaledDrawable

        // Get a bitmap drawable from a local file that is scaled down
        // to fit the current window size
        public static BitmapDrawable GetScaledDrawable(Activity a, string path)
        {
            Display display = a.WindowManager.DefaultDisplay;
            float destWidth = display.Width;
            float destHeight = display.Height;

            // Read in the dimensions of the image on disk
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            BitmapFactory.DecodeFile(path, options);

            float srcWidth = options.OutWidth;
            float srcHeight = options.OutHeight;

            double inSampleSize = 1.0;
            if (srcHeight > destHeight || srcWidth > destWidth) {
                if (srcWidth > srcHeight) {
                    inSampleSize = Math.Round(srcHeight / destHeight);
                }
                else {
                    inSampleSize = Math.Round(srcWidth / destWidth);
                }
            }

            options = new BitmapFactory.Options();
            options.InSampleSize = (int)inSampleSize;

            Bitmap bitmap = BitmapFactory.DecodeFile(path, options);
            var bDrawable= new BitmapDrawable(a.Resources, bitmap);
            bitmap = null;

            return bDrawable;
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:35,代码来源:PictureUtils.cs


示例7: Scale

		public static Bitmap Scale (int scaleFactor, Stream iStream)
		{
			var bmOptions = new BitmapFactory.Options ();
			bmOptions.InJustDecodeBounds = false;
			bmOptions.InSampleSize = scaleFactor;
			return BitmapFactory.DecodeStream (iStream, null, bmOptions);
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:7,代码来源:BitmapHelper.cs


示例8: OnElementPropertyChanged

        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            var largeImage = (XLargeImage.SourceCode.Controls.XLargeImage)Element;

            if ((!(Element.Width > 0) || !(Element.Height > 0) || _isDecoded) &&
                (e.PropertyName != "ImageSource" || largeImage.ImageSource == null)) return;
            var options = new BitmapFactory.Options {InJustDecodeBounds = true};

            //Get the resource id for the image
            var field = typeof(Resource.Drawable).GetField(largeImage.ImageSource.Split('.').First());
            if(field == null) return;
            var value = (int)field.GetRawConstantValue();

            BitmapFactory.DecodeResource(Context.Resources, value, options);

            //The with and height of the elements (XLargeImage) will be used to decode the image
            var width = (int)Element.Width;
            var height = (int)Element.Height;
            options.InSampleSize = CalculateInSampleSize(options, width, height);

            options.InJustDecodeBounds = false;
            var bitmap = BitmapFactory.DecodeResource(Context.Resources, value, options);

            //Set the bitmap to the native control
            Control.SetImageBitmap(bitmap);

            _isDecoded = true;
        }
开发者ID:xamarindevelopervietnam,项目名称:XLargeImage,代码行数:30,代码来源:XLargeImageRenderer.cs


示例9: SetValue

        public override void SetValue(object value)
        {
            var imageView = ImageView;
            if (imageView == null)
            {
                // weak reference is garbage collected - so just return
                return;
            }

            try
            {
                var assetStream = GetStream(value);
                if (assetStream == null)
                    return;

                var options = new BitmapFactory.Options {InPurgeable = true};
                var bitmap = BitmapFactory.DecodeStream(assetStream, null, options);
                var drawable = new BitmapDrawable(Resources.System, bitmap);
                imageView.SetImageDrawable(drawable);
            }
            catch (Exception ex)
            {
                MvxTrace.Error(ex.ToLongString());
                throw;
            }
        }
开发者ID:darkice-matt-crombie,项目名称:MvxSpinnerTest,代码行数:26,代码来源:MvxBaseImageViewTargetBinding.cs


示例10: LoadAndResizeBitmap

		public static Bitmap LoadAndResizeBitmap(this string fileName, int width, int height)
		{
			// First we get the the dimensions of the file on disk
			BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
			BitmapFactory.DecodeFile(fileName, options);

			// Next we calculate the ratio that we need to resize the image by
			// in order to fit the requested dimensions.
			int outHeight = options.OutHeight;
			int outWidth = options.OutWidth;
			int inSampleSize = 1;

			if (outHeight > height || outWidth > width)
			{
				inSampleSize = outWidth > outHeight
					? outHeight / height
					: outWidth / width;
			}

			// Now we will load the image and have BitmapFactory resize it for us.
			options.InSampleSize = inSampleSize;
			options.InJustDecodeBounds = false;
			Bitmap resizedBitmap = BitmapFactory.DecodeFile(fileName, options);

			return resizedBitmap;
		}
开发者ID:MishaGubsky,项目名称:studies,代码行数:26,代码来源:BitmapHelpers.cs


示例11: GetImageSize

        public static AccidentMediaViewModel GetImageSize(string fileName)
        {

            var options = new BitmapFactory.Options
            {
                InJustDecodeBounds = true
            };

            File file = new File(fileName);
            long lengthMB = file.Length() / 1024;

            BitmapFactory.DecodeFile(fileName, options);
            int width = options.OutWidth;
            int height = options.OutHeight;
            string type = options.OutMimeType;

           
            file.Dispose();
            return new AccidentMediaViewModel
            {
                Height = height,
                MimeType = type,
                Filename = fileName,
                SizeKb = lengthMB,
                Width = width
            };

        }
开发者ID:Railgun-it,项目名称:autoresolve-app,代码行数:28,代码来源:ImageExtensions.cs


示例12: DecodeSampledBitmapFromResource

 public static Bitmap DecodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight)
 {
     BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
     BitmapFactory.DecodeResource(res, resId, options);
     options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
     options.InJustDecodeBounds = false;
     return BitmapFactory.DecodeResource(res, resId, options);
 }
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:BitmapHelper.cs


示例13: DragObject

        private Bitmap img; // The object bitmap

        #endregion Fields

        #region Constructors

        public DragObject(Resources res, int drawableIntID)
        {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InJustDecodeBounds = true;
            img = BitmapFactory.DecodeResource(res, drawableIntID);
            id = count;
            count++;
        }
开发者ID:rondelrosario,项目名称:DragAndDrop,代码行数:14,代码来源:DragObject.cs


示例14: DecodeFromByteArray

 public static Bitmap DecodeFromByteArray(byte[] bytes, int reqWidth, int reqHeight)
 {
     BitmapFactory.Options options = new BitmapFactory.Options { InJustDecodeBounds = true };
     BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length, options);
     options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
     options.InJustDecodeBounds = false;
     return BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length, options);
 }    
开发者ID:pascalfr,项目名称:MPfm,代码行数:8,代码来源:BitmapHelper.cs


示例15: ToSampleSize

 /// <summary>
 /// Helper method to get the sample size of the image for resampling.
 /// </summary>
 public static int ToSampleSize (this byte [] bytes)
 {
     var sampleSize = 0;
     BitmapFactory.Options options = new BitmapFactory.Options ();
     options.InJustDecodeBounds = true;
     BitmapFactory.DecodeByteArray (bytes, 0, bytes.Length, options);
     sampleSize = (int)Math.Ceiling ((double)Math.Max (options.OutWidth / Constants.MaxWidth, options.OutHeight / Constants.MaxHeight));
     return sampleSize;
 }
开发者ID:harouny,项目名称:prebuilt-apps,代码行数:12,代码来源:AndroidExtensions.cs


示例16: FindScaleFactor

		public static int FindScaleFactor (int targetWidth, int targetHeight, Stream iStream)
		{
			var bmOptions = new BitmapFactory.Options ();
			bmOptions.InJustDecodeBounds = true;
			BitmapFactory.DecodeStream (iStream, null, bmOptions);
			int actualWidth = bmOptions.OutWidth;
			int actualHeight = bmOptions.OutHeight;
			return Math.Min (actualWidth / targetWidth, actualHeight / targetHeight);
		}
开发者ID:CHANDAN145,项目名称:monodroid-samples,代码行数:9,代码来源:BitmapHelper.cs


示例17: DecodeBitmapFromStream

		public Bitmap DecodeBitmapFromStream (Android.Net.Uri url)
		{			
			using (Stream stream = _context.ContentResolver.OpenInputStream ( url )) {
				BitmapFactory.Options options = new BitmapFactory.Options ();
				options.InJustDecodeBounds = false;
				Bitmap bitmap = BitmapFactory.DecodeStream (stream, null, options);
				return bitmap;
			}
		}
开发者ID:dtimyr,项目名称:xamarin,代码行数:9,代码来源:PlatformConverterService.cs


示例18: Base64StringtoBitmap

		public static Bitmap Base64StringtoBitmap (string base64)
		{
			byte[] decodedByte = Base64.Decode (base64, 0);
			var option = new BitmapFactory.Options();
			option.InPurgeable = true;
			option.InScaled = false;
			
			Bitmap image = BitmapFactory.DecodeByteArray(decodedByte, 0, decodedByte.Length, option);
			return image;
		}
开发者ID:sourcefile,项目名称:OrdinaCompetitie,代码行数:10,代码来源:ImageUtil.cs


示例19: downloadAsync

		public async Task<Bitmap> downloadAsync (string uri)
		{
		 
			if (uri == null)
				return null;

			int index = uri.LastIndexOf ("/");
			string localFilename = uri.Substring (index + 1);
			webClient = new WebClient ();
			var url = new Uri (uri);
			byte[] bytes = null;


			try {

				bytes = await webClient.DownloadDataTaskAsync (url);
			} catch (TaskCanceledException Ex) {
				Log.Error ("downloadAsync:", Ex.Message);
				return null;
			} catch (Exception Ex) {
			
				Log.Error ("downloadAsync:", Ex.Message);

				return null;
			}

			string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);	

			string localPath = System.IO.Path.Combine (documentsPath, localFilename);
		

			//Sive the Image using writeAsync
			FileStream fs = new FileStream (localPath, FileMode.OpenOrCreate);
			await fs.WriteAsync (bytes, 0, bytes.Length);

			//Console.WriteLine("localPath:"+localPath);
			fs.Close ();


			BitmapFactory.Options options = new BitmapFactory.Options ();
			options.InJustDecodeBounds = true;
			await BitmapFactory.DecodeFileAsync (localPath, options);

			//	options.InSampleSize = options.OutWidth > options.OutHeight ? options.OutHeight / imageview.Height : options.OutWidth / imageview.Width;
			options.InJustDecodeBounds = false;

			Bitmap bitmap = await BitmapFactory.DecodeFileAsync (localPath, options);



			return (bitmap);

		
		}
开发者ID:jhondiaz,项目名称:Viewwin,代码行数:54,代码来源:ImgDownloadAsync.cs


示例20: GetSmallestDimensionOfImage

        private static int GetSmallestDimensionOfImage(ContentResolver cr, Uri uri)
        {
            using (var inputStream = cr.OpenInputStream(uri))
            {
                var justSizeOptions = new BitmapFactory.Options();
                justSizeOptions.InJustDecodeBounds = true;

                BitmapFactory.DecodeStream(inputStream, new Rect(), justSizeOptions);

                return Math.Min(justSizeOptions.OutHeight, justSizeOptions.OutWidth);
            }
        }
开发者ID:adbk,项目名称:spikes,代码行数:12,代码来源:BitmapFactory.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Graphics.Canvas类代码示例发布时间:2022-05-24
下一篇:
C# Graphics.Bitmap类代码示例发布时间: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