Ejemplo n.º 1
0
 /// <summary>Decode an input stream into a bitmap.</summary>
 /// <remarks>
 /// Decode an input stream into a bitmap. If the input stream is null, or
 /// cannot be used to decode a bitmap, the function returns null.
 /// The stream's position will be where ever it was after the encoded data
 /// was read.
 /// </remarks>
 /// <param name="is">
 /// The input stream that holds the raw data to be decoded into a
 /// bitmap.
 /// </param>
 /// <param name="outPadding">
 /// If not null, return the padding rect for the bitmap if
 /// it exists, otherwise set padding to [-1,-1,-1,-1]. If
 /// no bitmap is returned (null) then padding is
 /// unchanged.
 /// </param>
 /// <param name="opts">
 /// null-ok; Options that control downsampling and whether the
 /// image should be completely decoded, or just is size returned.
 /// </param>
 /// <returns>
 /// The decoded bitmap, or null if the image data could not be
 /// decoded, or, if opts is non-null, if opts requested only the
 /// size be returned (in opts.outWidth and opts.outHeight)
 /// </returns>
 public static android.graphics.Bitmap decodeStream(java.io.InputStream @is, android.graphics.Rect
                                                    outPadding, android.graphics.BitmapFactory.Options opts)
 {
     // we don't throw in this case, thus allowing the caller to only check
     // the cache, and not force the image to be decoded.
     if (@is == null)
     {
         return(null);
     }
     // we need mark/reset to work properly
     if ([email protected]())
     {
         @is = new java.io.BufferedInputStream(@is, 16 * 1024);
     }
     // so we can call reset() if a given codec gives up after reading up to
     // this many bytes. FIXME: need to find out from the codecs what this
     // value should be.
     @is.mark(1024);
     android.graphics.Bitmap bm;
     if (@is is android.content.res.AssetManager.AssetInputStream)
     {
         bm = nativeDecodeAsset(((android.content.res.AssetManager.AssetInputStream)@is).mAsset
                                , outPadding, opts);
     }
     else
     {
         // pass some temp storage down to the native code. 1024 is made up,
         // but should be large enough to avoid too many small calls back
         // into is.read(...) This number is not related to the value passed
         // to mark(...) above.
         byte[] tempStorage = null;
         if (opts != null)
         {
             tempStorage = opts.inTempStorage;
         }
         if (tempStorage == null)
         {
             tempStorage = new byte[16 * 1024];
         }
         bm = nativeDecodeStream(@is, tempStorage, outPadding, opts);
     }
     if (bm == null && opts != null && opts.inBitmap != null)
     {
         throw new System.ArgumentException("Problem decoding into existing bitmap");
     }
     return(finishDecode(bm, outPadding, opts));
 }
Ejemplo n.º 2
0
		/// <summary>Decode an input stream into a bitmap.</summary>
		/// <remarks>
		/// Decode an input stream into a bitmap. If the input stream is null, or
		/// cannot be used to decode a bitmap, the function returns null.
		/// The stream's position will be where ever it was after the encoded data
		/// was read.
		/// </remarks>
		/// <param name="is">
		/// The input stream that holds the raw data to be decoded into a
		/// bitmap.
		/// </param>
		/// <param name="outPadding">
		/// If not null, return the padding rect for the bitmap if
		/// it exists, otherwise set padding to [-1,-1,-1,-1]. If
		/// no bitmap is returned (null) then padding is
		/// unchanged.
		/// </param>
		/// <param name="opts">
		/// null-ok; Options that control downsampling and whether the
		/// image should be completely decoded, or just is size returned.
		/// </param>
		/// <returns>
		/// The decoded bitmap, or null if the image data could not be
		/// decoded, or, if opts is non-null, if opts requested only the
		/// size be returned (in opts.outWidth and opts.outHeight)
		/// </returns>
		public static android.graphics.Bitmap decodeStream(java.io.InputStream @is, android.graphics.Rect
			 outPadding, android.graphics.BitmapFactory.Options opts)
		{
			// we don't throw in this case, thus allowing the caller to only check
			// the cache, and not force the image to be decoded.
			if (@is == null)
			{
				return null;
			}
			// we need mark/reset to work properly
			if ([email protected]())
			{
				@is = new java.io.BufferedInputStream(@is, 16 * 1024);
			}
			// so we can call reset() if a given codec gives up after reading up to
			// this many bytes. FIXME: need to find out from the codecs what this
			// value should be.
			@is.mark(1024);
			android.graphics.Bitmap bm;
			if (@is is android.content.res.AssetManager.AssetInputStream)
			{
				bm = nativeDecodeAsset(((android.content.res.AssetManager.AssetInputStream)@is).mAsset
					, outPadding, opts);
			}
			else
			{
				// pass some temp storage down to the native code. 1024 is made up,
				// but should be large enough to avoid too many small calls back
				// into is.read(...) This number is not related to the value passed
				// to mark(...) above.
				byte[] tempStorage = null;
				if (opts != null)
				{
					tempStorage = opts.inTempStorage;
				}
				if (tempStorage == null)
				{
					tempStorage = new byte[16 * 1024];
				}
				bm = nativeDecodeStream(@is, tempStorage, outPadding, opts);
			}
			if (bm == null && opts != null && opts.inBitmap != null)
			{
				throw new System.ArgumentException("Problem decoding into existing bitmap");
			}
			return finishDecode(bm, outPadding, opts);
		}