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);
}
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);
}
}
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);
}
}
}
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"));
}
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);
}
Aggregations