use of android.graphics.Bitmap in project cw-omnibus by commonsguy.
the class TextIconGenerator method makeIcon.
/**
* Creates an icon with the current content and style.
* <p/>
* This method is useful if a custom view has previously been set, or if text content is not
* applicable.
*/
public Bitmap makeIcon() {
ViewGroup container = getContainer();
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
container.measure(measureSpec, measureSpec);
int measuredWidth = container.getMeasuredWidth();
int measuredHeight = container.getMeasuredHeight();
container.layout(0, 0, measuredWidth, measuredHeight);
if (mRotation == 1 || mRotation == 3) {
measuredHeight = container.getMeasuredWidth();
measuredWidth = container.getMeasuredHeight();
}
Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
r.eraseColor(Color.TRANSPARENT);
Canvas canvas = new Canvas(r);
if (mRotation == 0) {
// do nothing
} else if (mRotation == 1) {
canvas.translate(measuredWidth, 0);
canvas.rotate(90);
} else if (mRotation == 2) {
canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
} else {
canvas.translate(0, measuredHeight);
canvas.rotate(270);
}
container.draw(canvas);
return r;
}
use of android.graphics.Bitmap in project Launcher3 by chislon.
the class BitmapUtils method resizeAndCropCenter.
public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
if (w == size && h == size)
return bitmap;
// scale the image so that the shorter side equals to the target;
// the longer side will be center-cropped.
float scale = (float) size / Math.min(w, h);
Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
int width = Math.round(scale * bitmap.getWidth());
int height = Math.round(scale * bitmap.getHeight());
Canvas canvas = new Canvas(target);
canvas.translate((size - width) / 2f, (size - height) / 2f);
canvas.scale(scale, scale);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
canvas.drawBitmap(bitmap, 0, 0, paint);
if (recycle)
bitmap.recycle();
return target;
}
use of android.graphics.Bitmap in project Launcher3 by chislon.
the class BitmapUtils method createVideoThumbnail.
public static Bitmap createVideoThumbnail(String filePath) {
// MediaMetadataRetriever is available on API Level 8
// but is hidden until API Level 10
Class<?> clazz = null;
Object instance = null;
try {
clazz = Class.forName("android.media.MediaMetadataRetriever");
instance = clazz.newInstance();
Method method = clazz.getMethod("setDataSource", String.class);
method.invoke(instance, filePath);
// The method name changes between API Level 9 and 10.
if (Build.VERSION.SDK_INT <= 9) {
return (Bitmap) clazz.getMethod("captureFrame").invoke(instance);
} else {
byte[] data = (byte[]) clazz.getMethod("getEmbeddedPicture").invoke(instance);
if (data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if (bitmap != null)
return bitmap;
}
return (Bitmap) clazz.getMethod("getFrameAtTime").invoke(instance);
}
} catch (IllegalArgumentException ex) {
// Assume this is a corrupt video file
} catch (RuntimeException ex) {
// Assume this is a corrupt video file.
} catch (InstantiationException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (ClassNotFoundException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (NoSuchMethodException e) {
Log.e(TAG, "createVideoThumbnail", e);
} catch (IllegalAccessException e) {
Log.e(TAG, "createVideoThumbnail", e);
} finally {
try {
if (instance != null) {
clazz.getMethod("release").invoke(instance);
}
} catch (Exception ignored) {
}
}
return null;
}
use of android.graphics.Bitmap in project philm by chrisbanes.
the class PinnedSectionListView method createPinnedShadow.
/**
* Create shadow wrapper with a pinned view for a view at given position
*/
void createPinnedShadow(int position) {
// try to recycle shadow
PinnedSection pinnedShadow = mRecycleSection;
mRecycleSection = null;
// create new shadow, if needed
if (pinnedShadow == null) {
pinnedShadow = new PinnedSection();
}
// request new view using recycled view, if such
View pinnedView;
final int childIndex = position - getFirstVisiblePosition();
final View sectionView = getChildAt(childIndex);
if (sectionView != null) {
Bitmap b = Bitmap.createBitmap(sectionView.getWidth(), sectionView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.drawColor(getThemeBackgroundColor());
sectionView.draw(c);
pinnedView = new ImageView(getContext());
((ImageView) pinnedView).setImageBitmap(b);
} else {
pinnedView = getAdapter().getView(position, null, PinnedSectionListView.this);
}
// read layout parameters
LayoutParams layoutParams = (LayoutParams) pinnedView.getLayoutParams();
if (layoutParams == null) {
// create default layout params
layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
int heightMode = MeasureSpec.getMode(layoutParams.height);
int heightSize = MeasureSpec.getSize(layoutParams.height);
if (heightMode == MeasureSpec.UNSPECIFIED) {
heightMode = MeasureSpec.EXACTLY;
}
int maxHeight = getHeight() - getListPaddingTop() - getListPaddingBottom();
if (heightSize > maxHeight) {
heightSize = maxHeight;
}
// measure & layout
int ws = MeasureSpec.makeMeasureSpec(getWidth() - getListPaddingLeft() - getListPaddingRight(), MeasureSpec.EXACTLY);
int hs = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
pinnedView.measure(ws, hs);
pinnedView.layout(0, 0, pinnedView.getMeasuredWidth(), pinnedView.getMeasuredHeight());
mTranslateY = 0;
// initialize pinned shadow
pinnedShadow.view = pinnedView;
pinnedShadow.position = position;
pinnedShadow.id = getAdapter().getItemId(position);
// store pinned shadow
mPinnedSection = pinnedShadow;
}
use of android.graphics.Bitmap in project SimplifyReader by chentao0707.
the class CaptureActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}
if (requestCode == IMAGE_PICKER_REQUEST_CODE) {
String imagePath = data.getStringExtra(CommonImagePickerDetailActivity.KEY_BUNDLE_RESULT_IMAGE_PATH);
if (!CommonUtils.isEmpty(imagePath)) {
ImageLoader.getInstance().loadImage("file://" + imagePath, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
String resultZxing = new DecodeUtils(DecodeUtils.DECODE_DATA_MODE_ALL).decodeWithZxing(loadedImage);
String resultZbar = new DecodeUtils(DecodeUtils.DECODE_DATA_MODE_ALL).decodeWithZbar(loadedImage);
if (!CommonUtils.isEmpty(resultZbar)) {
Bundle extras = new Bundle();
extras.putInt(DecodeThread.DECODE_MODE, DecodeUtils.DECODE_MODE_ZBAR);
handleDecode(resultZbar, extras);
} else if (!CommonUtils.isEmpty(resultZxing)) {
Bundle extras = new Bundle();
extras.putInt(DecodeThread.DECODE_MODE, DecodeUtils.DECODE_MODE_ZXING);
handleDecode(resultZxing, extras);
} else {
showToast(getResources().getString(R.string.tips_decode_null));
}
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
}
}
}
Aggregations