java类android.graphics.BitmapFactory的实例源码

Bouncer.java 文件源码 项目:buildAPKsSamples 阅读 34 收藏 0 点赞 0 评论 0
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();
        }
    });
}
CaptureHandler.java 文件源码 项目:QrCode 阅读 29 收藏 0 点赞 0 评论 0
@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;
    }
}
ImageUtils.java 文件源码 项目:RLibrary 阅读 34 收藏 0 点赞 0 评论 0
/**
 * 获取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);
}
LogoView.java 文件源码 项目:chromium-for-android-56-debug-video 阅读 28 收藏 0 点赞 0 评论 0
/**
 * @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;
}
AlarmChecker.java 文件源码 项目:com.ruuvi.station 阅读 30 收藏 0 点赞 0 评论 0
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());
    }
}
RangeSeekBar.java 文件源码 项目:xlight_android_native 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 计算每个按钮的位置和尺寸
 * 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);
    }
}
ImageResizer.java 文件源码 项目:Android-Practice 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 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)
}
BitmapUtil.java 文件源码 项目:codedemos 阅读 41 收藏 0 点赞 0 评论 0
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;
}
CircleImageView.java 文件源码 项目:AndroidBackendlessChat 阅读 32 收藏 0 点赞 0 评论 0
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();
}
CustodeUtils.java 文件源码 项目:custode 阅读 29 收藏 0 点赞 0 评论 0
/** 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;
}


问题


面经


文章

微信
公众号

扫码关注公众号