ArtworkFactory.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:aos-MediaLib 作者:
public ArtworkFactory( Context context, int width, int height) {

        mContext = context;
        mRes = mContext.getResources();
        mContentResolver =  context.getContentResolver();
        mLayoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mWidth = width;
        mHeight = height;

        mContentLabelFontsize = mRes.getDimension(R.dimen.ContentLabel_fontsize);

        mBitmapOptions = new BitmapFactory.Options();
        // RGB565 is OK for the artwork, 888 will be needed only when we add the shadow
        // Also no need for dithering. OpenGL will do a good job at displaying it without.
        //TODO: check if using ARGB888 is not faster since it will be converted after anyway
        mBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
        mBitmapOptions.inDither = ARTWORK_BITMAP_DITHERING;
        mBitmapOptions.inSampleSize = 1; // no sub-sampling
        mBitmapOptions.inJustDecodeBounds = false;

        // Prepare a painter and enable filtering if showing large bitmaps to avoid ugly rendering of the rescaled bitmap
        mPaint = new Paint();
        mPaint.setFilterBitmap(ARTWORK_BITMAP_FILTERING);
        mPaint.setDither(ARTWORK_BITMAP_DITHERING);

        // ======== Now prepare the shadow stuff =========

        // Create the destination bitmap and associate a canvas to it
        // Require ARGB for the shadow effect
        mShadowBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888 );
        mShadowBitmap.eraseColor(Color.TRANSPARENT);
        mCanvas = new Canvas(mShadowBitmap);

        // Decode the shadow bitmap
        int shadowId = ArchosFeatures.isAndroidTV(mContext)|| ArchosFeatures.isLUDO()?R.drawable.cover_shadow_512:(mWidth==128) ? R.drawable.cover_shadow_128 : R.drawable.cover_shadow_256;
        InputStream is = context.getResources().openRawResource(shadowId);
        mShadow9patchPadding = new Rect();

        // We must use this version of "decode" in order to get the nine-patch padding
        Bitmap shadowNinePatchBitmap = BitmapFactory.decodeStream(is, mShadow9patchPadding, null);
        try {
            is.close();
        } catch (IOException e) {}
        mShadow9patch = new NinePatch(shadowNinePatchBitmap, shadowNinePatchBitmap.getNinePatchChunk(), null);
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号