Search in sources :

Example 1 with MyBitmap

use of org.aisen.android.component.bitmaploader.core.MyBitmap in project AisenWeiBo by wangdan.

the class TimelineThumbBitmapCompress method compress.

@Override
public MyBitmap compress(byte[] bitmapBytes, File file, String url, ImageConfig config, int origW, int origH) throws Exception {
    boolean isGif = url.toLowerCase().endsWith("gif");
    if (config instanceof TimelinePicsView.TimelineImageConfig) {
        TimelinePicsView.TimelineImageConfig timelineImageConfig = (TimelinePicsView.TimelineImageConfig) config;
        if (timelineImageConfig.getSize() > 1) {
            if (isGif) {
            } else {
                float maxRadio = 6 * 1.0f / 16;
                // 图片的宽高比过小,不截gif图
                if (origW * 1.0f / origH < maxRadio) {
                    // Logger.v(String.format("原始尺寸, width = %d, height = %d", origW, origH));
                    // 根据比例截取图片
                    int width = origW;
                    int height = width * (timelineImageConfig.getShowHeight() / timelineImageConfig.getShowWidth());
                    Bitmap bitmap = BitmapUtil.decodeRegion(bitmapBytes, width, height);
                    // Logger.v(String.format("截取后的尺寸, width = %d, height = %d", bitmap.getWidth(), bitmap.getHeight()));
                    return new MyBitmap(bitmap, url);
                }
            }
        }
    }
    // 高度比较高时,截图部分显示
    if (!isGif && origW <= 440 && origH > maxHeight) {
        float outHeight = origW * 1.0f * (cutHeight * 1.0f / cutWidth);
        return new MyBitmap(BitmapUtil.decodeRegion(bitmapBytes, origW, Math.round(outHeight)), url);
    }
    return super.compress(bitmapBytes, file, url, config, origW, origH);
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) Bitmap(android.graphics.Bitmap) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TimelinePicsView(org.aisen.weibo.sina.ui.widget.TimelinePicsView)

Example 2 with MyBitmap

use of org.aisen.android.component.bitmaploader.core.MyBitmap in project AisenWeiBo by wangdan.

the class VideoHintImageView method display.

public void display(BitmapOwner owner, UrlBean urlBean) {
    setOnClickListener(null);
    this.urlBean = urlBean;
    if (videoBean != null && !TextUtils.isEmpty(videoBean.getShortUrl()) && videoBean.getShortUrl().equals(urlBean.getUrl_short())) {
    } else {
        videoBean = null;
    }
    ImageConfig config = new ImageConfig();
    config.setCompressCacheEnable(false);
    config.setDownloaderClass(VideoDownloader.class);
    config.setBitmapCompress(VideoCompress.class);
    config.setLoadingRes(R.drawable.bg_timeline_loading);
    MyBitmap myBitmap = BitmapLoader.getInstance().getMyBitmapFromMemory(urlBean.getUrl_short(), config);
    // 内存缓存存在图片,且未释放
    if (myBitmap != null) {
        setImageDrawable(new MyDrawable(getResources(), myBitmap, config, null));
    } else {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
        if (params != null && params.height != minHeight) {
            params.height = minHeight;
        }
        setLayoutParams(params);
        BitmapLoader.getInstance().display(owner, urlBean.getUrl_short(), this, config);
    }
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) LinearLayout(android.widget.LinearLayout)

Example 3 with MyBitmap

use of org.aisen.android.component.bitmaploader.core.MyBitmap in project AisenWeiBo by wangdan.

the class VideoHintImageView method setImageDrawable.

@Override
public void setImageDrawable(Drawable drawable) {
    super.setImageDrawable(drawable);
    MyDrawable myDrawable = null;
    if (drawable instanceof MyDrawable) {
        myDrawable = (MyDrawable) drawable;
    } else if (drawable instanceof TransitionDrawable) {
        myDrawable = (MyDrawable) ((TransitionDrawable) drawable).getDrawable(1);
    }
    if (myDrawable != null) {
        MyBitmap myBitmap = myDrawable.getMyBitmap();
        if (myBitmap instanceof VideoBitmap) {
            setOnClickListener(this);
            videoBean = ((VideoBitmap) myBitmap).getVideoBean();
            if (getWidth() > 0) {
                int width = myBitmap.getBitmap().getWidth();
                int height = myBitmap.getBitmap().getHeight();
                float scale = getWidth() * 1.0f / width;
                height = (int) (height * scale);
                if (height > getWidth() * 4 / 5) {
                    height = getWidth() * 4 / 5;
                }
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) getLayoutParams();
                if (params != null) {
                    params.height = height;
                } else {
                    params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
                }
                setLayoutParams(params);
            }
            Logger.d(VideoHintImageView.class.getSimpleName(), videoBean);
        }
    }
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) Paint(android.graphics.Paint) LinearLayout(android.widget.LinearLayout)

Example 4 with MyBitmap

use of org.aisen.android.component.bitmaploader.core.MyBitmap in project AisenWeiBo by wangdan.

the class BitmapLoader method getLoadingDrawable.

public static Drawable getLoadingDrawable(Context context, ImageView imageView) {
    Drawable drawable = imageView.getDrawable();
    if (drawable != null && context != null) {
        if (drawable instanceof TransitionDrawable) {
            TransitionDrawable transitionDrawable = (TransitionDrawable) drawable;
            drawable = transitionDrawable.getDrawable(1);
        }
        if (drawable instanceof MyDrawable) {
            MyDrawable myDrawable = (MyDrawable) drawable;
            ImageConfig config = myDrawable.getConfig();
            if (config != null) {
                if (config.getLoadingRes() > 0)
                    return new BitmapDrawable(context.getResources(), new MyBitmap(context, config.getLoadingRes()).getBitmap());
            }
        }
    }
    return new ColorDrawable(Color.parseColor("#fff2f2f2"));
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) MyDrawable(org.aisen.android.component.bitmaploader.view.MyDrawable)

Example 5 with MyBitmap

use of org.aisen.android.component.bitmaploader.core.MyBitmap in project AisenWeiBo by wangdan.

the class TimelineBitmapCompress method compress.

@Override
public MyBitmap compress(byte[] bitmapBytes, File file, String url, ImageConfig config, int origW, int origH) throws Exception {
    Logger.v("ATimeline", "压缩小图片");
    Bitmap bitmap = null;
    int maxWidth = config.getMaxWidth() == 0 ? SystemUtils.getScreenWidth(GlobalContext.getInstance()) : config.getMaxWidth();
    int maxHeight = config.getMaxHeight() == 0 ? SystemUtils.getScreenHeight(GlobalContext.getInstance()) : config.getMaxHeight();
    // 如果高度比宽度在2倍以上,取高度的一部分
    if (origH * 1.0f / origW > 2) {
        int reqHeight = maxHeight;
        // 截取局部图片
        BitmapRegionDecoder bitmapDecoder = BitmapRegionDecoder.newInstance(bitmapBytes, 0, bitmapBytes.length, true);
        Rect rect = new Rect(0, 0, origW, reqHeight);
        bitmap = bitmapDecoder.decodeRegion(rect, null).copy(Config.ARGB_8888, true);
    } else {
        bitmap = BitmapDecoder.decodeSampledBitmapFromByte(bitmapBytes, maxWidth, maxHeight);
    }
    Logger.d(TAG, String.format("bitmap width = %d, height = %d", bitmap.getWidth(), bitmap.getHeight()));
    return new MyBitmap(bitmap, url);
}
Also used : MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) Bitmap(android.graphics.Bitmap) MyBitmap(org.aisen.android.component.bitmaploader.core.MyBitmap) Rect(android.graphics.Rect) BitmapRegionDecoder(android.graphics.BitmapRegionDecoder)

Aggregations

MyBitmap (org.aisen.android.component.bitmaploader.core.MyBitmap)8 MyDrawable (org.aisen.android.component.bitmaploader.view.MyDrawable)4 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)3 Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 TransitionDrawable (android.graphics.drawable.TransitionDrawable)2 LinearLayout (android.widget.LinearLayout)2 BitmapRegionDecoder (android.graphics.BitmapRegionDecoder)1 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 WeakReference (java.lang.ref.WeakReference)1 BitmapCompress (org.aisen.android.component.bitmaploader.core.BitmapCompress)1 IBitmapCompress (org.aisen.android.component.bitmaploader.core.IBitmapCompress)1 DefaultDisplayer (org.aisen.android.component.bitmaploader.display.DefaultDisplayer)1 VideoBean (org.aisen.weibo.sina.support.bean.VideoBean)1 TimelinePicsView (org.aisen.weibo.sina.ui.widget.TimelinePicsView)1