Exemplo n.º 1
0
		/// <summary>
		/// Attempts to find a bitmap suitable for reuse based on the given dimensions.
		/// Note that any returned instance will have SetIsRetained(true) called on it
		/// to ensure that it does not release its resources prematurely as it is leaving
		/// cache management. This means you must call SetIsRetained(false) when you no
		/// longer need the instance.
		/// </summary>
		/// <returns>A SelfDisposingBitmapDrawable that has been retained. You must call SetIsRetained(false)
		/// when finished using it.</returns>
		/// <param name="options">Bitmap creation options.</param>
		public SelfDisposingBitmapDrawable GetBitmapDrawableFromReusableSet(BitmapFactory.Options options)
		{
			if (_cache.Count == 0)
				return null;

			return _cache.GetReusableBitmapDrawable(options.OutWidth, options.OutHeight, options.InPreferredConfig, options.InSampleSize);
		}
Exemplo n.º 2
0
		internal async static Task<Bitmap> LoadScaledDownBitmapForDisplayAsync(string strFileName, BitmapFactory.Options options, int reqWidth, int reqHeight)
		{
			// Calculate inSampleSize
			options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
			// Decode bitmap with inSampleSize set
			options.InJustDecodeBounds = false; //to let memory allocation during decoding 
			return await BitmapFactory.DecodeFileAsync(strFileName, options);
		}
Exemplo n.º 3
0
		public Bitmap LoadScaledDownBitmapForDisplay(BitmapFactory.Options options, int reqWidth, int reqHeight)
		{
			// Calculate inSampleSize
			options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
			// Decode bitmap with inSampleSize set
			options.InJustDecodeBounds = false;
			return BitmapFactory.DecodeResource(Resources, itemData, options);
		}
Exemplo n.º 4
0
        public async Task<Bitmap> LoadScaledDownBitmapForDisplayAsync(Resources res, BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            // Calculate inSampleSize
            options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);

            // Decode bitmap with inSampleSize set
			options.InJustDecodeBounds = false;

            return await BitmapFactory.DecodeResourceAsync(res, Resource.Drawable.samoyed, options);
        }
		private static void scaleImage(int width, int height, BitmapFactory.Options bmOptions) {
			if (width > 0 && height > 0) {
				int photoW = bmOptions.OutWidth;
				int photoH = bmOptions.OutHeight;

				int scaleFactor = Math.Min(photoW / width, photoH / height);
				bmOptions.InSampleSize = scaleFactor;
			}

			bmOptions.InJustDecodeBounds = false;
			bmOptions.InPurgeable = true;
		}
Exemplo n.º 6
0
        public static int CalculateInSampleSize (BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            // Raw height and width of image
            float height = (float) options.OutHeight;
            float width = (float) options.OutWidth;
            double inSampleSize = 1D;

            if (height > reqHeight || width > reqWidth) {
                inSampleSize = width > height ? height / reqHeight : width / reqWidth;
            }

            return (int) inSampleSize;
        }
 public static int calculateInputSample(BitmapFactory.Options options, int reqHeight, int reqWidth)
 {
     int outHeight = options.OutHeight;
     int outWidth = options.OutWidth;
     int inputSample = 1;
     while (reqHeight < outHeight || reqWidth < outWidth) {
         int halfHeight = outHeight / 2;
         int halfWidth = outWidth / 2;
         while ((halfHeight / 2) > reqHeight || (halfWidth / 2) > reqWidth) {
             inputSample *= 2;
         }
     }
     return inputSample;
 }
Exemplo n.º 8
0
        private static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            int height = options.OutHeight;
            int width = options.OutWidth;
            int inSampleSize = 1;
            if (height > reqHeight || width > reqWidth)
            {
                double heightRatio = Math.Round((float)height / reqHeight);
                double widthRatio = Math.Round((float)width / reqWidth);

                inSampleSize = (int)(heightRatio < widthRatio ? heightRatio : widthRatio);

            }
            return inSampleSize;
        }
Exemplo n.º 9
0
        public static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            int width = options.OutWidth;
            int height = options.OutHeight;
            int inSampleSize = 1;

            if (width > reqWidth || height > reqHeight)
            {
                int widthRatio = (int)Math.Round((double)width / (double)reqWidth);
                int heightRatio = (int)Math.Round((double)height / (double)reqHeight);

                inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
            }

            return inSampleSize;
        }
Exemplo n.º 10
0
        int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            var height = options.OutHeight;
            var width = options.OutWidth;
            var inSampleSize = 1D;

            if (height > reqHeight || width > reqWidth)
            {
                var halfHeight = (int)(height / 2);
                var halfWidth = (int)(width / 2);

                while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth)
                {
                    inSampleSize *= 2;
                }
            }

            return (int)inSampleSize;
        }
        public static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            // Raw height and width of image
            float height = options.OutHeight;
            float width = options.OutWidth;
            double inSampleSize = 1D;

            if (height > reqHeight || width > reqWidth) {
                int halfHeight = (int)(height / 2);
                int halfWidth = (int)(width / 2);

                // Calculate a inSampleSize that is a power of 2 - the decoder will use a value that is a power of two anyway.
                while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
                    inSampleSize *= 2;
                }
            }

            return (int)inSampleSize;
        }
Exemplo n.º 12
0
        private int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            float height = options.OutHeight;
            float width = options.OutWidth;
            double inSampleSize = 1D;

            if (height > reqHeight || width > reqWidth)
            {
                int halfHeight = (int)(height / 2);
                int halfWidth = (int)(width / 2);

                while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth)
                {
                    inSampleSize *= 2;
                }

            }

            return (int)inSampleSize;
        }
Exemplo n.º 13
0
        /// <summary>
        ///   This method will calculate a scaling factor that must be applied to get the image down
        ///   to the dimensions specified.
        /// </summary>
        /// <param name="options"></param>
        /// <param name="reqWidth"></param>
        /// <param name="reqHeight"></param>
        /// <returns>A scaling factor to reduce the size of the image.</returns>
        static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
        {
            float height = options.OutHeight;
            float width = options.OutWidth;
            double inSampleSize = 1d;

            if (height > reqHeight || width > reqWidth)
            {
                if (width > height)
                {
                    inSampleSize = Math.Round(height / reqHeight);
                }
                else
                {
                    inSampleSize = Math.Round(width / reqWidth);
                }
            }

            return (int)inSampleSize;
        }
Exemplo n.º 14
0
        private int CalculateInSampleSize(BitmapFactory.Options options, int requestedWidth, int requestedHeight)
        {
            //Raw height and widht of image
            int height = options.OutHeight;
            int width = options.OutWidth;
            int inSampleSize = 1;

            if (height > requestedHeight || width > requestedWidth)
            {
                //the image is bigger than we want it to be
                int halfHeight = height / 2;
                int halfWidth = width / 2;

                while((halfHeight / inSampleSize) > requestedHeight && (halfWidth / inSampleSize) > requestedWidth)
                {
                    inSampleSize *= 2;
                }

            }

            return inSampleSize;
        }
		public static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
		{
			//_____________________________
			// Raw height and width of image
			int height = options.OutHeight;
			int width = options.OutWidth;
			int inSampleSize = 1;

			if (height > reqHeight || width > reqWidth)
			{
				if (width > height)
				{
					inSampleSize = (int)System.Math.Round((float)height / (float)reqHeight);
				}
				else
				{
					inSampleSize = (int)System.Math.Round((float)width / (float)reqWidth);
				}
			}

			return inSampleSize;

		}
Exemplo n.º 16
0
		public async Task<Bitmap> LoadInternal (BitmapFactory.Options o = null, int scaleWidth = -1,
		                                        int scaleHeight = -1, BitmapCompressOptions compressOptions = null)
		{
			if (String.IsNullOrEmpty (_url)) {
				return null;
			}

			Bitmap bmp = null;

			if (compressOptions == null) {
				compressOptions = new BitmapCompressOptions ();
			}

			try {
				var uri = new Uri (_url);
				var client = new WebClient ();
				var stringme = String.Format ("{0}{1}{2}", _url, scaleWidth, scaleHeight);
				var urlHash = GetMD5 (new Java.Lang.String (stringme));

				var path = Application.Context.CacheDir.AbsolutePath + "/" + urlHash;
				var fileInfo = new FileInfo (path);

				if (o == null) {
					o = new BitmapFactory.Options () { InPurgeable = true };
				}

				if (_staticRAMCache.ContainsKey (urlHash)) {
					return _staticRAMCache [urlHash];
				}

				if (fileInfo.Exists) {
					using (var file = File.Open (path, FileMode.Open, FileAccess.Read)) {
						byte[] buff = new byte[file.Length];
						await file.ReadAsync (buff, 0, (int)file.Length);
						bmp = await BitmapFactory.DecodeByteArrayAsync (buff, 0, buff.Length, o);
						_staticRAMCache [urlHash] = bmp;

						return bmp;
					}
				} else {
					try {
						Log.Debug ("Loading " + uri.ToString ());
						var response = await client.DownloadDataTaskAsync (uri);

						if (response == null || response.Length <= 0)
							return null;

						if (scaleWidth > 0 && scaleHeight > 0) {
							o.InSampleSize = CalculateInSampleSize (o, scaleWidth, scaleHeight);
						}

						bmp = await BitmapFactory.DecodeByteArrayAsync (response, 0, response.Length, o);
						if (fileInfo.Directory != null) {
							fileInfo.Directory.Create ();
						}

						var fileStream = new FileStream (path,
							                 FileMode.OpenOrCreate,
							                 FileAccess.ReadWrite,
							                 FileShare.ReadWrite);

						await bmp.CompressAsync (compressOptions.Format, compressOptions.Quality, fileStream);

						fileStream.Close ();

						_staticRAMCache [urlHash] = bmp;

						return bmp;

					} catch (WebException ex) {
						Log.Debug (TAG, ex.StackTrace);
						return null;
					}
				}
			} catch (System.UriFormatException ex) {
				Log.Debug (TAG, ex.StackTrace);
				return null;
			}
		}
Exemplo n.º 17
0
 private Task<Bitmap> LoadScaledDownBitmapForDisplayAsync(BitmapFactory.Options options, int resourceId, int reqWidth, int reqHeight)
 {
     return Task.Run(() => LoadScaledDownBitmapForDisplay(options, resourceId, reqWidth, reqHeight));
 }
Exemplo n.º 18
0
		static int CalculateSampleSize(BitmapFactory.Options options, int rHeight, int rWidth)
		{
			// from http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
			int height = options.OutHeight;
			int width = options.OutWidth;
			int inSampleSize = 1;

			if (height > rHeight || width > rWidth) {

				int halfHeight = height / 2;
				int halfWidth = width / 2;

				// Calculate the largest inSampleSize value that is a power of 2 and keeps both
				// height and width larger than the requested height and width.
				while ((halfHeight / inSampleSize) > rHeight
					&& (halfWidth / inSampleSize) > rWidth) {
					inSampleSize *= 2;
				}
			}
			return inSampleSize;
		}
Exemplo n.º 19
0
 /// Author:	Guy Spronck
 /// Date:	23-06-2015
 /// <summary>
 /// Draws the spawn.
 /// </summary>
 /// <param name="res">Res.</param>
 /// <param name="opt">Opt.</param>
 /// <param name="spawn">Spawn.</param>
 /// <param name="tempCanvas">Temp canvas.</param>
 /// <param name="imgWidth">Image width.</param>
 /// <param name="imgHeight">Image height.</param>
 private void DrawSpawn(Android.Content.Res.Resources res, BitmapFactory.Options opt, Spawn spawn, Canvas tempCanvas, int imgWidth, int imgHeight)
 {
     tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.SpawnFlag01, opt), (float)spawn.x * imgWidth, (float)spawn.y * imgHeight, null);
 }
Exemplo n.º 20
0
 /// Author:	Guy Spronck
 /// Date:	09-06-2015
 /// <summary>
 /// Draws the tile
 /// </summary>
 /// <param name="map">Map.</param>
 /// <param name="iX">x.</param>
 /// <param name="iY">y.</param>
 /// <param name="tempCanvas">Temp canvas.</param>
 /// <param name="imgWidth">Image width.</param>
 /// <param name="imgHeight">Image height.</param>
 /// <param name="res">Res.</param>
 /// <param name="opt">Opt.</param>
 private void DrawTile(Map map, int iX, int iY, Canvas tempCanvas, int imgWidth, int imgHeight, Android.Content.Res.Resources res, BitmapFactory.Options opt)
 {
     switch (map.map [iY, iX].TileId) {
     case 0:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile1, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 1:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile2, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 2:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile3, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 3:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile4, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 4:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile5, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 5:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile6, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 6:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile7, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 7:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile8, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 8:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile9, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 9:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile10, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 10:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile11, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 11:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile12, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 12:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile13, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 13:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile14, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 14:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile15, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 15:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile16, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 16:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile17, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 17:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile18, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 18:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile19, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 19:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile20, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 20:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile21, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 21:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile22, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 22:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile23, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 23:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile24, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 24:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile25, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 25:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile26, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 26:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.roadTile27, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 27:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile1, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 28:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile2, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 29:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile3, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 30:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile4, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 31:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile5, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 32:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile6, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 33:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile1, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 34:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile2, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 35:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile3, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 36:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile4, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 37:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile5, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 38:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile6, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 39:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile7, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 40:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile8, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 41:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile9, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 42:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile10, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 43:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile11, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 44:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile12, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 45:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile13, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 46:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile14, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 47:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile15, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 48:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile16, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 49:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile17, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 50:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile18, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 51:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile19, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 52:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile20, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 53:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile21, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 54:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile22, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 55:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile23, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 56:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile24, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 57:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile25, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 58:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile26, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 59:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile27, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 60:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile28, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 61:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile29, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 62:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile30, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 63:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile31, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 64:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile32, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 65:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile33, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 66:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile34, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 67:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile35, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 68:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile36, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 69:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile37, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 70:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile38, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 71:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile39, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 72:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile40, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 73:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile41, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 74:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile42, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 75:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile43, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 76:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile44, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 77:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile45, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 78:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.waterTile46, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 79:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.StoreApple, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     case 80:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.StoreSausage, opt), (float)iX * imgWidth, (float)iY * imgHeight, null);
         break;
     default:
         tempCanvas.DrawBitmap (BitmapFactory.DecodeResource (res, Resource.Drawable.terrainTile3, opt), (float)iX * 64, (float)iY * imgHeight, null);
         break;
     }
 }
Exemplo n.º 21
0
 protected Bitmap CreateFromThumbnailService(long id, Context context, BitmapFactory.Options opt)
 {
     Bitmap bm = MediaStore.Images.Thumbnails.GetThumbnail(context.ContentResolver, id, ThumbnailKind.MiniKind, opt);
     return bm;
 }
Exemplo n.º 22
0
        /// Author:	Guy Spronck
        /// Date:	09-06-2015
        /// <summary>
        /// Draws the robot.
        /// </summary>
        /// <param name="tempCanvas">Temp canvas.</param>
        /// <param name="res">Res.</param>
        /// <param name="opt">Opt.</param>
        /// <param name="robotX">Robot x.</param>
        /// <param name="robotY">Robot y.</param>
        /// <param name="imgHeight">Image height.</param>
        /// <param name="imgWidth">Image width.</param>
        private void DrawRobot(Canvas tempCanvas, Android.Content.Res.Resources res, BitmapFactory.Options opt, int robotX, int robotY, int imgHeight, int imgWidth)
        {
            float rotation = 0f;
            switch (GlobalSupport.CurrentRobotOrientation)
            {
            case EOrientation.North:
                rotation = 270f;
                break;
            case EOrientation.East:
                rotation = 0f;
                break;
            case EOrientation.South:
                rotation = 90f;
                break;
            case EOrientation.West:
                rotation = 180f;
                break;
            }

            tempCanvas.DrawBitmap (RotateBitmap(BitmapFactory.DecodeResource(res, Resource.Drawable.blue, opt), rotation), (float)robotX * imgHeight, (float)robotY * imgHeight, null);
        }
Exemplo n.º 23
0
		private void AddInBitmapOptions(BitmapFactory.Options options)
		{
			// inBitmap only works with mutable bitmaps so force the decoder to
			// return mutable bitmaps.
			options.InMutable = true;


			// Try and find a bitmap to use for inBitmap
			var inBitmap = ImageCache.Instance.GetBitmapFromReusableSet(options);

			if (inBitmap != null)
			{
				options.InBitmap = inBitmap;
			}
		}
Exemplo n.º 24
0
        private Bitmap LoadScaledDownBitmapForDisplay(BitmapFactory.Options options, int resourceId, int reqWidth, int reqHeight)
        {
            options.InSampleSize = CalculateInSampleSize(options, reqWidth, reqHeight);
            options.InJustDecodeBounds = false;

            var bitmap = BitmapFactory.DecodeResource(_resources, resourceId, options);

            return bitmap;
        }
Exemplo n.º 25
0
		public async static void LoadImageFromUrl (ImageView iv, string url, BitmapFactory.Options options = null, int scaleWidth = -1, int scaleHeight = -1, BitmapCompressOptions compressOptions = null)
		{
			await _loadQueueSemaphore.WaitAsync ();

			if (_loadedImageViews.Contains (iv))
				_loadedImageViews.Remove (iv);
			var l = new CachedImageLoader (url);

			var bitmap = await l.LoadInternal (options, scaleWidth, scaleHeight, compressOptions);
			_loadQueueSemaphore.Release ();
			if (bitmap != null && !_loadedImageViews.Contains (iv)) {

				iv.SetImageBitmap (bitmap);
				_loadedImageViews.Add (iv);
			}


		}
	    /**
	     * Only call this method from the main (UI) thread. The {@link OnFetchCompleteListener} callback
	     * be invoked on the UI thread, but image fetching will be done in an {@link AsyncTask}.
	     *
	     * @param cookie An arbitrary object that will be passed to the callback.
	     */
	    public static void FetchImage(Context context, Java.Lang.String url, BitmapFactory.Options decodeOptions, Java.Lang.Object cookie, Action<Bitmap> callback) 
		{
			
			Task.Factory.StartNew(() => {
				if(TextUtils.IsEmpty(url))
				{
					result = null;
					return;
				}
				
				File cacheFile = null;
				try
				{
					MessageDigest mDigest = MessageDigest.GetInstance("SHA-1");
					mDigest.Update(url.GetBytes());
					string cacheKey = BytesToHexString(mDigest.Digest());
					if(Environment.MediaMounted.Equals(Environment.ExternalStorageState))
					{
						cacheFile = new File(Environment.ExternalStorageDirectory +
						                     File.Separator + "Android " + 
						                     File.Separator + "data" +
						                     File.Separator + context.PackageName + 
						                     File.Separator + "cache" +
						                     File.Separator + "bitmap_" + cacheKey + ".tmp");
					}
				}
				catch (Exception e) 
				{
					// NoSuchAlgorithmException
					// Oh well, SHA-1 not available (weird), don't cache bitmaps.
				}
				
				if (cacheFile != null && cacheFile.Exists()) 
				{
	                Bitmap cachedBitmap = BitmapFactory.DecodeFile(cacheFile.ToString(), decodeOptions);
                    if (cachedBitmap != null) {
                        result = cachedBitmap;
						return;
                    }
                }
				
				try 
				{
				    // TODO: check for HTTP caching headers
					var client = new System.Net.WebClient();
					var image = client.DownloadData(new Uri(url.ToString()));
					if (image != null)
					{
						result = null;
						return;
					}
				
				    // Write response bytes to cache.
				    if (cacheFile != null) {
				        try {
				            cacheFile.ParentFile.Mkdirs();
				            cacheFile.CreateNewFile();
				            FileOutputStream fos = new FileOutputStream(cacheFile);
				            fos.Write(image);
				            fos.Close();
				        } catch (FileNotFoundException e) {
				            Log.Warn(TAG, "Error writing to bitmap cache: " + cacheFile.ToString(), e);
				        } catch (IOException e) {
				            Log.Warn(TAG, "Error writing to bitmap cache: " + cacheFile.ToString(), e);
				        }
				    }
				
				    // Decode the bytes and return the bitmap.
				    result = (BitmapFactory.DecodeByteArray(image, 0, image.Length, decodeOptions));
					return;
				} catch (Exception e) {
				    Log.Warn(TAG, "Problem while loading image: " + e.ToString(), e);
				}
                result = null;
			})
			.ContinueWith(task =>
				callback(result)
        	);
			
	    }
    public static int CalculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight)
    {
        // Raw height and width of image
        int height = options.OutHeight;
        int width = options.OutWidth;
        int inSampleSize = 1;
        if (height > reqHeight || width > reqWidth)
        {

            int halfHeight = height/2;
            int halfWidth = width/2;

            // Calculate the largest inSampleSize value that is a power of 2 and
            // keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight/inSampleSize) > reqHeight
                   && (halfWidth/inSampleSize) > reqWidth)
            {
                inSampleSize *= 2;
            }
        }
        return inSampleSize;
    }
Exemplo n.º 28
0
        /// <summary>
        /// Gets the sample size for  specified width and height
        /// </summary>
        public static int GetSampleSize(BitmapFactory.Options options, int viewWidth, int viewHeight)
        {
            // Raw height and width of image
            int height = options.OutHeight;
            int width = options.OutWidth;
            int inSampleSize = 1;

            if (height > viewHeight || width > viewWidth) {

                // Calculate ratios of height and width to requested height and width
                int heightRatio = (int)Math.Round((float) height / (float) viewHeight);
                int widthRatio = (int)Math.Round((float) width / (float) viewWidth);

                // Choose the smallest ratio as inSampleSize value, this will guarantee
                // a final image with both dimensions larger than or equal to the
                // requested height and width.
                inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
            }

            return inSampleSize;
        }
Exemplo n.º 29
0
		private void AddInBitmapOptions(BitmapFactory.Options options)
		{
			// inBitmap only works with mutable bitmaps so force the decoder to
			// return mutable bitmaps.
			options.InMutable = true;


			// Try and find a bitmap to use for inBitmap
			SelfDisposingBitmapDrawable bitmapDrawable = null;
			try
			{
				bitmapDrawable = ImageCache.Instance.GetBitmapDrawableFromReusableSet(options);
				var bitmap = bitmapDrawable == null ? null : bitmapDrawable.Bitmap;

				if (bitmap != null && bitmap.Handle != IntPtr.Zero && !bitmap.IsRecycled)
				{
					options.InBitmap = bitmapDrawable.Bitmap;
				}
			}
			finally
			{
				if (bitmapDrawable != null)
				{
					bitmapDrawable.SetIsRetained(false);
				}
			}
		}