Esempio n. 1
0
 /// <summary>
 /// Synonym for opening the given resource and calling
 /// <see cref="decodeResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, Rect, Options)
 ///     ">decodeResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, Rect, Options)
 ///     </see>
 /// .
 /// </summary>
 /// <param name="res">The resources object containing the image data</param>
 /// <param name="id">The resource id of the image data</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 decodeResource(android.content.res.Resources
                                                      res, int id, android.graphics.BitmapFactory.Options opts)
 {
     android.graphics.Bitmap bm  = null;
     java.io.InputStream     @is = null;
     try
     {
         android.util.TypedValue value = new android.util.TypedValue();
         @is = res.openRawResource(id, value);
         bm  = decodeResourceStream(res, value, @is, null, opts);
     }
     catch (System.Exception)
     {
     }
     finally
     {
         try
         {
             if (@is != null)
             {
                 @is.close();
             }
         }
         catch (System.IO.IOException)
         {
         }
     }
     // Ignore
     if (bm == null && opts != null && opts.inBitmap != null)
     {
         throw new System.ArgumentException("Problem decoding into existing bitmap");
     }
     return(bm);
 }
Esempio n. 2
0
        public override void inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser
                                     parser, android.util.AttributeSet attrs)
        {
            base.inflate(r, parser, attrs);
            android.content.res.TypedArray a = r.obtainAttributes(attrs, [email protected].
                                                                  styleable.NinePatchDrawable);
            int id = a.getResourceId([email protected]_src, 0);

            if (id == 0)
            {
                throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
                                                                ": <nine-patch> requires a valid src attribute");
            }
            bool dither = a.getBoolean([email protected]_dither
                                       , DEFAULT_DITHER);

            android.graphics.BitmapFactory.Options options = new android.graphics.BitmapFactory
                                                             .Options();
            if (dither)
            {
                options.inDither = false;
            }
            options.inScreenDensity = android.util.DisplayMetrics.DENSITY_DEVICE;
            android.graphics.Rect   padding = new android.graphics.Rect();
            android.graphics.Bitmap bitmap  = null;
            try
            {
                android.util.TypedValue value = new android.util.TypedValue();
                java.io.InputStream     @is   = r.openRawResource(id, value);
                bitmap = android.graphics.BitmapFactory.decodeResourceStream(r, value, @is, padding
                                                                             , options);
                @is.close();
            }
            catch (System.IO.IOException)
            {
            }
            // Ignore
            if (bitmap == null)
            {
                throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
                                                                ": <nine-patch> requires a valid src attribute");
            }
            else
            {
                if (bitmap.getNinePatchChunk() == null)
                {
                    throw new org.xmlpull.v1.XmlPullParserException(parser.getPositionDescription() +
                                                                    ": <nine-patch> requires a valid 9-patch source image");
                }
            }
            setNinePatchState(new android.graphics.drawable.NinePatchDrawable.NinePatchState(
                                  new android.graphics.NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"
                                                                 ), padding, dither), r);
            mNinePatchState.mTargetDensity = mTargetDensity;
            a.recycle();
        }