本文整理汇总了Java中android.graphics.Bitmap类的典型用法代码示例。如果您正苦于以下问题:Java Bitmap类的具体用法?Java Bitmap怎么用?Java Bitmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bitmap类属于android.graphics包,在下文中一共展示了Bitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPicWH
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* 获取图片文件的宽高,宽高封装在Point的X和Y中
*
* @param filePath 文件路径
*/
public static Point getPicWH(String filePath) {
Point point = new Point();
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
point.x = options.outWidth;
point.y = options.outHeight;
options.inJustDecodeBounds = false;
} catch (Exception e) {
e.printStackTrace();
}
return point;
}
示例2: onActivityResult
import android.graphics.Bitmap; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case GET_PHOTO:
if (resultCode == RESULT_OK) {
crop(data.getData());
}
break;
case TAKE_PHOTO:
if (resultCode == RESULT_OK) {
crop(headImgUri);
}
break;
case CROP_PHOTO:
if (resultCode == RESULT_OK) {
Bitmap cropBitmap = data.getParcelableExtra("data");
String path = mUriFile.getPath();
watermarkUrl = path;
pickDirectory.setImageBitmap(cropBitmap);
mCustomPopupWindow.dismiss();
}
break;
default:
break;
}
}
示例3: saveImg
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* @param b Bitmap
* @return 图片存储的位置
*/
public static File saveImg(Bitmap b, String name) throws Exception {
String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "test/headImg/";
File mediaFile = new File(path + File.separator + name + ".jpg");
if (mediaFile.exists()) {
mediaFile.delete();
}
if (!new File(path).exists()) {
new File(path).mkdirs();
}
mediaFile.createNewFile();
FileOutputStream fos = new FileOutputStream(mediaFile);
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
b.recycle();
b = null;
System.gc();
// return mediaFile.getPath();
return mediaFile;
}
示例4: getBitmapByView
import android.graphics.Bitmap; //导入依赖的package包/类
public Bitmap getBitmapByView(View v) {
Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
v.draw(canvas);
return bitmap;
}
示例5: testDetFace
import android.graphics.Bitmap; //导入依赖的package包/类
@Test
public void testDetFace() {
Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/test.jpg");
assertThat(bitmap, notNullValue());
FaceDet faceDet = new FaceDet(Constants.getFaceShapeModelPath());
List<VisionDetRet> results = faceDet.detect("/sdcard/test.jpg");
for (final VisionDetRet ret : results) {
String label = ret.getLabel();
int rectLeft = ret.getLeft();
int rectTop = ret.getTop();
int rectRight = ret.getRight();
int rectBottom = ret.getBottom();
assertThat(label, is("face"));
Assert.assertTrue(rectLeft > 0);
}
faceDet.release();
}
示例6: getCircleBitmap
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* 获取圆形图片方法
* @param bitmap
* @param pixels
* @return Bitmap
* @author caizhiming
*/
private Bitmap getCircleBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
int x = bitmap.getWidth();
canvas.drawCircle(x / 2, x / 2, x / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例7: decodeFileDescriptorAsPurgeable
import android.graphics.Bitmap; //导入依赖的package包/类
protected Bitmap decodeFileDescriptorAsPurgeable(
CloseableReference<PooledByteBuffer> bytesRef,
int inputLength,
byte[] suffix,
BitmapFactory.Options options) {
MemoryFile memoryFile = null;
try {
memoryFile = copyToMemoryFile(bytesRef, inputLength, suffix);
FileDescriptor fd = getMemoryFileDescriptor(memoryFile);
Bitmap bitmap = sWebpBitmapFactory.decodeFileDescriptor(fd, null, options);
return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
if (memoryFile != null) {
memoryFile.close();
}
}
}
示例8: takeScreenShot
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* 对Activity截图
*
* @param activity
* @return Bitmap对象。
*/
public static Bitmap takeScreenShot(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap b1 = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay()
.getHeight();
Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
view.destroyDrawingCache();
return b;
}
示例9: processPicture
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* Compress bitmap using jpeg, convert to Base64 encoded string, and return to JavaScript.
*
* @param bitmap
*/
public void processPicture(Bitmap bitmap) {
ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream();
try {
if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) {
byte[] code = jpeg_data.toByteArray();
byte[] output = Base64.encode(code, Base64.NO_WRAP);
String js_out = new String(output);
this.callbackContext.success(js_out);
js_out = null;
output = null;
code = null;
}
} catch (Exception e) {
this.failPicture("Error compressing image.");
}
jpeg_data = null;
}
示例10: blur
import android.graphics.Bitmap; //导入依赖的package包/类
public static void blur(Bitmap bkg, View view) {
long startMs = System.currentTimeMillis();
float radius = 15;
float scaleFactor = 8;
//放大到整个view的大小
bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
, (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
canvas.scale(1 / scaleFactor, 1 / scaleFactor);
Paint paint = new Paint();
paint.setFlags(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(bkg, 0, 0, paint);
overlay = FastBlur.doBlur(overlay, (int) radius, true);
view.setBackgroundDrawable(new BitmapDrawable(UiUtils.getResources(), overlay));
Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
示例11: updateUserInfo
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* 上传用户信息,首先上传头像,上传成功后赶回头像地址,然后上传其他信息
*/
private void updateUserInfo(Bitmap avatar) {
//如果头像为空,也就是用户没有上传头像,则使用之前的头像地址
if (avatar == null) {
} else {
final AVFile avatarFile = new AVFile("user_avatar.jpeg", ImageUtil.bitmap2Bytes(avatar));
avatarFile.saveInBackground(new SaveCallback() {
@Override
public void done(AVException e) {
if (e == null) {
Log.i("lin", "----lin----> imgUrl" + avatarFile.getUrl());
_cardView = avatarFile.getUrl();
}
}
});
}
}
示例12: update
import android.graphics.Bitmap; //导入依赖的package包/类
public void update(Following following, boolean fling) {
tvName.setText(following.screenName);
ivCheck.setImageBitmap(following.checked ? bmChd : bmUnch);
if (aivIcon != null) {
if (fling) {
Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
if (bm != null && !bm.isRecycled()) {
aivIcon.setImageBitmap(bm);
} else {
aivIcon.execute(null, 0);
}
} else {
aivIcon.execute(following.icon, 0);
}
}
}
示例13: decodeSampled
import android.graphics.Bitmap; //导入依赖的package包/类
public static Bitmap decodeSampled(InputStream is, int reqWidth, int reqHeight) {
BitmapFactory.Options options = new BitmapFactory.Options();
// RGB_565
options.inPreferredConfig = Bitmap.Config.RGB_565;
// sample size
options.inSampleSize = getSampleSize(is, reqWidth, reqHeight);
try {
return BitmapFactory.decodeStream(is, null, options);
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return null;
}
示例14: onClientMetadataUpdate
import android.graphics.Bitmap; //导入依赖的package包/类
@Override
public void onClientMetadataUpdate(RemoteController.MetadataEditor metadataEditor) {
meta=metadataEditor;
StandardWidget.currentArt=metadataEditor.getBitmap(MediaMetadataEditor.BITMAP_KEY_ARTWORK,null);
StandardWidget.currentSquareArt = StandardWidget.currentArt;
if(StandardWidget.currentArt!=null) {
int cah = StandardWidget.currentArt.getHeight();
int caw = StandardWidget.currentArt.getWidth();
if (caw > cah * 1.02) {
StandardWidget.currentSquareArt = Bitmap.createBitmap(StandardWidget.currentArt,
(int) (caw / 2 - cah * 0.51), 0, (int) (cah * 1.02), cah);
}
}
StandardWidget.currentArtist=metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_ARTIST,"");
StandardWidget.currentSong=metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_TITLE,"");
StandardWidget.currentAlbum=metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_ALBUM,"");
if(StandardWidget.currentArtist==null||StandardWidget.currentArtist.equals("")){
StandardWidget.currentArtist = metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST,"");
}
if(StandardWidget.currentArtist==null||StandardWidget.currentArtist.equals("")){
StandardWidget.currentArtist = metadataEditor.getString(MediaMetadataRetriever.METADATA_KEY_AUTHOR,"");
}
sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
示例15: generateLowResIcon
import android.graphics.Bitmap; //导入依赖的package包/类
/**
* Generates a new low-res icon given a high-res icon.
*/
private Bitmap generateLowResIcon(Bitmap icon, int lowResBackgroundColor) {
if (lowResBackgroundColor == Color.TRANSPARENT) {
return Bitmap.createScaledBitmap(icon,
icon.getWidth() / LOW_RES_SCALE_FACTOR,
icon.getHeight() / LOW_RES_SCALE_FACTOR, true);
} else {
Bitmap lowResIcon = Bitmap.createBitmap(icon.getWidth() / LOW_RES_SCALE_FACTOR,
icon.getHeight() / LOW_RES_SCALE_FACTOR, Bitmap.Config.RGB_565);
synchronized (this) {
mLowResCanvas.setBitmap(lowResIcon);
mLowResCanvas.drawColor(lowResBackgroundColor);
mLowResCanvas.drawBitmap(icon, new Rect(0, 0, icon.getWidth(), icon.getHeight()),
new Rect(0, 0, lowResIcon.getWidth(), lowResIcon.getHeight()),
mLowResPaint);
mLowResCanvas.setBitmap(null);
}
return lowResIcon;
}
}