Java 类android.graphics.BitmapFactory 实例源码
项目:PaoMovie
文件:SendPaoPaoPic.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
paoPaoQuan.setSelection(paoPaoState);
// requestCode标示请求的标示 resultCode表示有数据
Log.d("js", requestCode + "//" + resultCode + "**" + data);
if (requestCode==4||data != null) {
int childCount = imageGrid.getChildCount();
if (childCount > 9) {
Toast.makeText(this, "最多选择9张图片", 1).show();
} else {
imageId++;
String fPath = null;
if (requestCode == 4) {
fPath = mCurrentPhotoPath;
}else{
Uri uri = data.getData(); // 得到Uri
if((uri!=null&&!uri.equals(""))){
fPath = StaticMethod.getImageAbsolutePath(this, uri); // 转化为路径
}
}
Bitmap b = BitmapFactory.decodeFile(fPath);
b = StaticMethod.getThumImg(b, 100);
ImageView image = new ImageView(this);
image.setLayoutParams(new LayoutParams(130, 130));
image.setScaleType(ScaleType.FIT_XY);
image.setId(imageId);
image.setTag(fPath);
image.setImageBitmap(b);
image.setOnClickListener(this);
imageGrid.addView(image, childCount - 1);
}
}
}
项目:cordova-plugin-image-picker
文件:MultiImageChooserActivity.java
private Bitmap tryToGetBitmap(File file, BitmapFactory.Options options, int rotate, boolean shouldScale) throws IOException, OutOfMemoryError {
Bitmap bmp;
if (options == null) {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
} else {
bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
}
if (bmp == null) {
throw new IOException("The image file could not be opened.");
}
if (options != null && shouldScale) {
float scale = calculateScale(options.outWidth, options.outHeight);
bmp = this.getResizedBitmap(bmp, scale);
}
if (rotate != 0) {
Matrix matrix = new Matrix();
matrix.setRotate(rotate);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
return bmp;
}
项目:GitHub
文件:MyApplication.java
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
AndroidNetworking.initialize(getApplicationContext());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
AndroidNetworking.setBitmapDecodeOptions(options);
AndroidNetworking.enableLogging();
AndroidNetworking.setConnectionQualityChangeListener(new ConnectionQualityChangeListener() {
@Override
public void onChange(ConnectionQuality currentConnectionQuality, int currentBandwidth) {
Log.d(TAG, "onChange: currentConnectionQuality : " + currentConnectionQuality + " currentBandwidth : " + currentBandwidth);
}
});
}
项目:ForeverLibrary
文件:PictureUtil.java
/**
* 质量压缩
*
* @param image
* @return
*/
public static Bitmap compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
int options = 100;
while (baos.toByteArray().length / 1024 > MAXSIZEKB) { //循环判断如果压缩后图片是否大于300kb,大于继续压缩
// Log.i("-----", "compressImage: options="+options+"--baos.toByteArray().length="+baos.toByteArray().length);
baos.reset();//重置baos即清空baos
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
options -= 10;//每次都减少10
}
Log.e("压缩之后的图片大小", "compressImage: 111111options= " + options + "--baos.toByteArray().length= " + baos.toByteArray().length);
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片
return bitmap;
}
项目:DisplayingBitmaps
文件:ImageResizer.java
/**
* Decode and sample down a bitmap from resources to the requested width and height.
*
* @param res The resources object containing the image data
* @param resId The resource id of the image data
* @param reqWidth The requested width of the resulting bitmap
* @param reqHeight The requested height of the resulting bitmap
* @param cache The ImageCache used to find candidate bitmaps for use with inBitmap
* @return A bitmap sampled down from the original with the same aspect ratio and dimensions
* that are equal to or greater than the requested width and height
*/
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight, ImageCache cache) {
// BEGIN_INCLUDE (read_bitmap_dimensions)
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// END_INCLUDE (read_bitmap_dimensions)
// If we're running on Honeycomb or newer, try to use inBitmap
if (Utils.hasHoneycomb()) {
addInBitmapOptions(options, cache);
}
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
项目:Huochexing12306
文件:ShareUtil.java
/**
* 根据磁盘路径取得
* @param pathString
* @return
*/
public Bitmap getDiskBitmap(String pathString)
{
Bitmap bitmap = null;
try
{
File file = new File(pathString);
if(file.exists())
{
bitmap = BitmapFactory.decodeFile(pathString);
}
} catch (Exception e)
{
e.printStackTrace();
return null;
}
return bitmap;
}
项目:Watermark
文件:CropPresenter.java
private int calculateSampleSize(BitmapFactory.Options options) {
int outHeight = options.outHeight;
int outWidth = options.outWidth;
int sampleSize = 1;
int destHeight = 1000;
int destWidth = 1000;
if (outHeight > destHeight || outWidth > destHeight) {
if (outHeight > outWidth) {
sampleSize = outHeight / destHeight;
} else {
sampleSize = outWidth / destWidth;
}
}
if (sampleSize < 1) {
sampleSize = 1;
}
return sampleSize;
}
项目:editor-sql
文件:FeThumbUtils.java
private static int computeInitialSampleSize(BitmapFactory.Options options,
int minSideLength, int maxNumOfPixels) {
double w = options.outWidth;
double h = options.outHeight;
int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 : (int) Math
.ceil(Math.sqrt(w * h / maxNumOfPixels));
int upperBound = (minSideLength == UNCONSTRAINED) ? 128 : (int) Math
.min(Math.floor(w / minSideLength),
Math.floor(h / minSideLength));
if (upperBound < lowerBound) {
// return the larger one when there is no overlapping zone.
return lowerBound;
}
if ((maxNumOfPixels == UNCONSTRAINED)
&& (minSideLength == UNCONSTRAINED)) {
return 1;
} else if (minSideLength == UNCONSTRAINED) {
return lowerBound;
} else {
return upperBound;
}
}
项目:Mobike
文件:QrUtils.java
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is getUrl power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
项目:BluetoothAPP
文件:DialogUtil.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_define);
setCanceledOnTouchOutside(true);
ImageView img =findViewById(R.id.dialog_img);
pro =findViewById(R.id.dialog_progress);
ContentResolver cr = context.getContentResolver();
try {
Bitmap bitmap = BitmapFactory.decodeStream(cr.openInputStream(path));
img.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
Log.e("Exception", e.getMessage(),e);
}
pro.setMax(progreesmax);
new SendSocketService() .setProgressListener(new SendSocketService.setProgessIml() {
@Override
public void setProgress(int size) {
pro.setMax(size);
}
});
pro.setProgress(getProgrees);
}
项目:Resizer
文件:ImageUtils.java
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(sourceImage.getAbsolutePath(), options);
// Get the dimensions of the original bitmap
int originalWidth = options.outWidth;
int originalHeight = options.outHeight;
float aspectRatio = (float) originalWidth / originalHeight;
// Calculate the target dimensions
int targetWidth, targetHeight;
if (originalWidth > originalHeight) {
targetWidth = targetLength;
targetHeight = Math.round(targetWidth / aspectRatio);
} else {
aspectRatio = 1 / aspectRatio;
targetHeight = targetLength;
targetWidth = Math.round(targetHeight / aspectRatio);
}
return Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
}
项目:Phoenix-for-VK
文件:NotificationHelper.java
public void buildNotification(Context context, final String albumName, final String artistName,
final String trackName, final Long albumId, final Bitmap albumArt,
final boolean isPlaying, MediaSessionCompat.Token mediaSessionToken) {
if (Utils.hasOreo()){
mNotificationManager.createNotificationChannel(AppNotificationChannels.getAudioChannel(context));
}
// Notification Builder
mNotificationBuilder = new NotificationCompat.Builder(mService, AppNotificationChannels.AUDIO_CHANNEL_ID)
.setShowWhen(false)
.setSmallIcon(R.drawable.itunes)
.setContentTitle(artistName)
.setContentText(trackName)
.setContentIntent(getOpenIntent(context))
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.cover))
.setPriority(Notification.PRIORITY_MAX)
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionToken)
.setShowCancelButton(true)
.setShowActionsInCompactView(0, 1, 2)
.setCancelButtonIntent(retreivePlaybackActions(4)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_first, ""
, retreivePlaybackActions(3)))
.addAction(new android.support.v4.app.NotificationCompat.Action(isPlaying ? R.drawable.pause : R.drawable.play, ""
, retreivePlaybackActions(1)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_last, ""
, retreivePlaybackActions(2)));
mService.startForeground(APOLLO_MUSIC_SERVICE, mNotificationBuilder.build());
}
项目:GongXianSheng
文件:ImageUtils.java
/**
* 根据宽高路径返回图片
*/
public static Bitmap decodeScaleImage(String paramString, int width, int height)
{
BitmapFactory.Options localOptions = getBitmapOptions(paramString);
int i = calculateInSampleSize(localOptions, width, height);
localOptions.inSampleSize = i;
localOptions.inJustDecodeBounds = false;
Bitmap localBitmap1= null;
try{
localBitmap1 = BitmapFactory.decodeFile(paramString, localOptions);
}
catch (Exception e){
e.printStackTrace();
}
int j = readPictureDegree(paramString); //获取旋转角度
Bitmap localBitmap2 = null;
if ((localBitmap1 != null) && (j != 0))
{
localBitmap2 = rotaingImageView(j, localBitmap1);
localBitmap1.recycle();
localBitmap1 = null;
return localBitmap2;
}
return localBitmap1;
}
项目:BatteryModPercentage
文件:NotifService.java
@Override
protected void onPreExecute() {
b = new NotificationCompat.Builder(context);
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(context, MainActivity.class);
resultPendingIntent =
PendingIntent.getActivity(
context,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
b.setAutoCancel(false)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon))
.setSmallIcon(R.drawable.ic_battery_mgr_mod)
.setPriority(NotificationCompat.PRIORITY_MIN)
.setContentIntent(resultPendingIntent)
.setOngoing(true)
;
}
项目:android-slideshow
文件:FileItemHelper.java
/**
* Returns the mime type of the given item.
*/
public String getImageMimeType(FileItem item){
String mime = "";
try {
mime = URLConnection.guessContentTypeFromName(item.getPath());
} catch (StringIndexOutOfBoundsException e){
// Not sure the cause of this issue but it occurred on production so handling as blank mime.
}
if (mime == null || mime.isEmpty()){
// Test mime type by loading the image
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(item.getPath(), opt);
mime = opt.outMimeType;
}
return mime;
}
项目:com.ruuvi.station
文件:ScannerService.java
public void startFG() {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
NotificationCompat.Builder notification;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
notification
= new NotificationCompat.Builder(getApplicationContext())
.setContentTitle(this.getString(R.string.scanner_notification_title))
.setSmallIcon(R.mipmap.ic_launcher_small)
.setTicker(this.getString(R.string.scanner_notification_ticker))
.setStyle(new NotificationCompat.BigTextStyle().bigText(this.getString(R.string.scanner_notification_message)))
.setContentText(this.getString(R.string.scanner_notification_message))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setLargeIcon(bitmap)
.setContentIntent(pendingIntent);
startForeground(notificationId, notification.build());
}
项目:letv
文件:ImageActivity.java
private Bitmap a(String str) throws IOException {
int i = 1;
Options options = new Options();
options.inJustDecodeBounds = true;
Uri parse = Uri.parse(str);
InputStream openInputStream = getContentResolver().openInputStream(parse);
if (openInputStream == null) {
return null;
}
BitmapFactory.decodeStream(openInputStream, null, options);
openInputStream.close();
int i2 = options.outWidth;
int i3 = options.outHeight;
while (i2 * i3 > 4194304) {
i2 /= 2;
i3 /= 2;
i *= 2;
}
options.inJustDecodeBounds = false;
options.inSampleSize = i;
return BitmapFactory.decodeStream(getContentResolver().openInputStream(parse), null, options);
}
项目:android-lite-utils
文件:BitmapUtils.java
/**
* 计算采样率
*
* @param options
* @param reqWidth
* @param reqHeight
* @return
*/
public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
项目:fancydownloader
文件:MainActivity.java
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) >= reqHeight
&& (halfWidth / inSampleSize) >= reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
项目:GxIconAndroid
文件:IconDialog.java
private void returnPickIcon() {
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeResource(getResources(), iconBean.getId());
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent();
if (bitmap != null) {
intent.putExtra("icon", bitmap);
intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", iconBean.getId());
intent.setData(Uri.parse("android.resource://" + getContext().getPackageName()
+ "/" + String.valueOf(iconBean.getId())));
getActivity().setResult(Activity.RESULT_OK, intent);
} else {
getActivity().setResult(Activity.RESULT_CANCELED, intent);
}
getActivity().finish();
}
项目:GitHub
文件:ImageLoader.java
/**
* From Assets
*
* @param imageUri
* @param imageView
* @throws java.io.IOException
*/
protected void displayImageFromAssets(String imageUri, ImageView imageView) throws IOException {
String filePath = Scheme.ASSETS.crop(imageUri);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(context.getAssets().open(filePath));
} catch (IOException e) {
e.printStackTrace();
return;
}
if (imageView != null) {
// imageView.setImageBitmap(bitmap);
Glide.with(context).load(inputStreamToByte(context.getAssets().open(filePath))).into(imageView);
// Log.i("杭鹏伟", " " + imageUri + " " + filePath);
}
}
项目:AndroidBookTest
文件:DownloadService.java
private Notification getNotification(String title,int progress){
Intent intent=new Intent(this,MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(this,0,intent,0);
NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));
builder.setContentIntent(pi);
builder.setContentTitle(title);
if (progress>=0){
//当progress大于等于0时才显示下载进度
builder.setContentText(progress+"%");
builder.setProgress(100,progress,false);
}
return builder.build();
}
项目:SmartMath
文件:FlatChart.java
public void initialize() {
// mcontext should be always not null.
mcfgImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_24);
mcfgImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_32);
mcfgImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_48);
mcfgImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.setting_gear_64);
mzoomInImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_24);
mzoomInImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_32);
mzoomInImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_48);
mzoomInImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_in_64);
mzoomOutImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_24);
mzoomOutImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_32);
mzoomOutImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_48);
mzoomOutImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_out_64);
mxy1To1ZoomImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_24);
mxy1To1ZoomImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_32);
mxy1To1ZoomImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_48);
mxy1To1ZoomImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_1_64);
mfitZoomImage_24 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_24);
mfitZoomImage_32 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_32);
mfitZoomImage_48 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_48);
mfitZoomImage_64 = BitmapFactory.decodeResource(mcontext.getResources(), R.drawable.zoom_fit_64);
}
项目:pc-android-controller-android
文件:ImageCompressUtil.java
private static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}
项目:GitHub
文件:WebpBitmapFactoryImpl.java
@DoNotStrip
private static byte[] getInTempStorageFromOptions(@Nullable final BitmapFactory.Options options) {
if (options != null && options.inTempStorage != null) {
return options.inTempStorage;
} else {
return new byte[IN_TEMP_BUFFER_SIZE];
}
}
项目:PhotoApp
文件:ImageUtil.java
/**
* Decodifica a imagem para o tamanho especificado
*/
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
// Primeiro decodifica para verificar as dimensões
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calcula inSampleSize - O valor correspondende para a imagem ser redimensionada
options.inSampleSize = ImageUtil.calculateInSampleSize(options, reqWidth, reqHeight);
// Decodifica imagem usando o valor calculado
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}
项目:BBSSDK-for-Android
文件:ImageUtils.java
/**
* 获取bitmap
*
* @param fd 文件描述
* @param maxWidth 最大宽度
* @param maxHeight 最大高度
* @return bitmap
*/
public static Bitmap getBitmap(final FileDescriptor fd, final int maxWidth, final int maxHeight) {
if (fd == null) {
return null;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
options.inSampleSize = calculateInSampleSize(options, maxWidth, maxHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(fd, null, options);
}
项目:rental-calc
文件:PictureViewActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.picture_view_menu, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.action_share);
// Fetch ShareActionProvider
ShareActionProvider shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
if (shareActionProvider == null)
{
Log.w(TAG, "Failed to find share action provider");
return false;
}
if(imageFilename == null)
{
Log.w(TAG, "No receipt to share");
return false;
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
// Determine mimetype of image
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imageFilename, opt);
shareIntent.setType(opt.outMimeType);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imageFilename)));
shareActionProvider.setShareIntent(shareIntent);
return super.onCreateOptionsMenu(menu);
}
项目:Cable-Android
文件:ScribbleActivity.java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_STICKER_REQUEST_CODE) {
if (data != null) {
toolbar.setStickerSelected(true);
final String stickerFile = data.getStringExtra(StickerSelectActivity.EXTRA_STICKER_FILE);
new AsyncTask<Void, Void, Bitmap>() {
@Override
protected @Nullable
Bitmap doInBackground(Void... params) {
try {
return BitmapFactory.decodeStream(getAssets().open(stickerFile));
} catch (IOException e) {
Log.w(TAG, e);
return null;
}
}
@Override
protected void onPostExecute(@Nullable Bitmap bitmap) {
addSticker(bitmap);
}
}.execute();
}
}
}
}
项目:Clipcon-AndroidClient
文件:RetrofitDownloadData.java
/**
* Download Captured Image Data
* Change to Image object from file form of Image data
*/
private void downloadCapturedImageData(InputStream inputStream) {
// inputStream -> bitmap -> file
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
Bitmap imageBitmapData = BitmapFactory.decodeStream(bufferedInputStream);
imageToGallery(imageBitmapData);
}
项目:buildAPKsSamples
文件:Bouncer.java
private void setupShape() {
mBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.electricsheep);
mShapeW = mBitmap.getWidth();
mShapeH = mBitmap.getHeight();
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startAnimation();
}
});
}
项目:QrCode
文件:CaptureHandler.java
@Override
public void handleMessage(Message message) {
switch (message.what) {
case AUTO_FOCUS:
if (state == State.PREVIEW) {
cameraManager.requestAutoFocus(this, AUTO_FOCUS);
}
break;
case RESTART_PREVIEW:
restartPreviewAndDecode();
break;
case DECODE_SUCCEEDED:
state = State.SUCCESS;
Bundle bundle = message.getData();
Bitmap barcode = null;
float scaleFactor = 1.0f;
if (bundle != null) {
byte[] compressedBitmap = bundle.getByteArray(DecodeThread.BARCODE_BITMAP);
if (compressedBitmap != null) {
barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null);
// Mutable copy:
barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
}
scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
}
mIScanCallback.handleDecode((Result) message.obj, barcode, scaleFactor);
break;
case DECODE_FAILED:
// We're decoding as fast as possible, so when one decode fails, start another.
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(), DECODE);
break;
case RETURN_SCAN_RESULT:
break;
}
}
项目:RLibrary
文件:ImageUtils.java
/**
* 获取bitmap
*
* @param data 数据
* @param offset 偏移量
* @param maxWidth 最大宽度
* @param maxHeight 最大高度
* @return bitmap
*/
public static Bitmap getBitmap(byte[] data, int offset, int maxWidth, int maxHeight) {
if (data.length == 0) return null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, offset, data.length, options);
options.inSampleSize = calculateInSampleSize(options, maxWidth, maxHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeByteArray(data, offset, data.length, options);
}
项目:chromium-for-android-56-debug-video
文件:LogoView.java
/**
* @return The default logo.
*/
private Bitmap getDefaultLogo() {
Bitmap defaultLogo = sDefaultLogo == null ? null : sDefaultLogo.get();
if (defaultLogo == null) {
defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.google_logo);
sDefaultLogo = new WeakReference<Bitmap>(defaultLogo);
}
return defaultLogo;
}
项目:com.ruuvi.station
文件:AlarmChecker.java
private static void sendAlert(int stringResId, int _id, String name, Context context) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
int notificationid = _id + stringResId;
boolean isShowing = isNotificationVisible(context, notificationid);
NotificationCompat.Builder notification;
if (!isShowing) {
notification
= new NotificationCompat.Builder(context)
.setContentTitle(name)
.setSmallIcon(R.mipmap.ic_launcher_small)
.setTicker(name + " " + context.getString(stringResId))
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(stringResId)))
.setContentText(context.getString(stringResId))
.setDefaults(Notification.DEFAULT_ALL)
.setOnlyAlertOnce(true)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setLargeIcon(bitmap);
NotificationManager NotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
NotifyMgr.notify(notificationid, notification.build());
}
}
项目:xlight_android_native
文件:RangeSeekBar.java
/**
* 计算每个按钮的位置和尺寸
* Calculates the position and size of each button
*
* @param x
* @param y
* @param hSize
* @param parentLineWidth
* @param cellsMode
* @param bmpResId
* @param context
*/
protected void onSizeChanged(int x, int y, int hSize, int parentLineWidth, boolean cellsMode, int bmpResId, Context context) {
heightSize = hSize;
widthSize = heightSize ;
left = x - widthSize / 2;
right = x + widthSize / 2;
top = y - heightSize / 2;
bottom = y + heightSize / 2;
if (cellsMode) {
lineWidth = parentLineWidth;
} else {
lineWidth = parentLineWidth ;
}
if (bmpResId > 0) {
Bitmap original = BitmapFactory.decodeResource(context.getResources(), bmpResId);
if (original != null) {
Matrix matrix = new Matrix();
float scaleHeight = mThumbSize * 1.0f / original.getHeight();
float scaleWidth = scaleHeight;
matrix.postScale(scaleWidth, scaleHeight);
bmp = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);
}
} else {
defaultPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
int radius = (int) (widthSize * DEFAULT_RADIUS);
int barShadowRadius = (int) (radius * 0.95f);
int mShadowCenterX = widthSize/2;
int mShadowCenterY = heightSize/2;
shadowGradient = new RadialGradient(mShadowCenterX, mShadowCenterY, barShadowRadius, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);
}
}
项目:Android-Practice
文件:ImageResizer.java
/**
* Calculate an inSampleSize for use in a {@link android.graphics.BitmapFactory.Options} object when decoding
* bitmaps using the decode* methods from {@link android.graphics.BitmapFactory}. This implementation calculates
* the closest inSampleSize that is a power of 2 and will result in the final decoded bitmap
* having a width and height equal to or larger than the requested width and height.
*
* @param options An options object with out* params already populated (run through a decode*
* method with inJustDecodeBounds==true
* @param reqWidth The requested width of the resulting bitmap
* @param reqHeight The requested height of the resulting bitmap
* @return The value to be used for inSampleSize
*/
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// BEGIN_INCLUDE (calculate_sample_size)
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
// This offers some additional logic in case the image has a strange
// aspect ratio. For example, a panorama may have a much larger
// width than height. In these cases the total pixels might still
// end up being too large to fit comfortably in memory, so we should
// be more aggressive with sample down the image (=larger inSampleSize).
long totalPixels = width * height / inSampleSize;
// Anything more than 2x the requested pixels we'll sample down further
final long totalReqPixelsCap = reqWidth * reqHeight * 2;
while (totalPixels > totalReqPixelsCap) {
inSampleSize *= 2;
totalPixels /= 2;
}
}
return inSampleSize;
// END_INCLUDE (calculate_sample_size)
}
项目:codedemos
文件:BitmapUtil.java
public static Bitmap getRotatedImg(String path) {
int angle = getBitmapRotation(path);
Matrix matrix = new Matrix();
matrix.postRotate(angle);
Bitmap bitmap = BitmapFactory.decodeFile(path);
try {
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
项目:AndroidBackendlessChat
文件:CircleImageView.java
public void loadFromFile(final String path){
new Thread(new Runnable() {
@Override
public void run() {
Bitmap bitmap = BitmapFactory.decodeFile(path);
Message message = new Message();
message.obj = bitmap;
handler.sendMessage(message);
}
}).start();
}
项目:custode
文件:CustodeUtils.java
/** Restituisce l'immagine del contatto per un numero di telefono. */
public static Bitmap getContactPhoto(Context context, String phoneNumber) {
ContentResolver contentResolver = context.getContentResolver();
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
String[] projection = new String[] {ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup._ID};
Cursor cursor = contentResolver.query(uri, projection, null, null, null);
String contactId;
if (cursor != null && cursor.moveToFirst()) {
contactId = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
cursor.close();
}
else
return null;
Bitmap photo = null;
try {
InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(),
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.valueOf(contactId)));
if (inputStream != null) {
photo = BitmapFactory.decodeStream(inputStream);
inputStream.close();
}
} catch (IOException ignored) {
}
return photo;
}