Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

In this page you can find the example usage for android.graphics Bitmap createScaledBitmap.

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        return;/*from   w  w  w .  j  a  va  2  s.co  m*/
    }

    try {
        File storagePictureFile = getStoredMediaFile();
        if (requestCode == REQUEST_TAKE_PICTURE) {
            // die Kamera-App sollte auf temporren Cache-Speicher schreiben, wir laden das Bild von
            // dort und schreiben es in Standard-Gre in den permanenten Speicher
            File cameraRawPictureFile = getCameraMediaFile();
            if (cameraRawPictureFile == null || storagePictureFile == null) {
                throw new RuntimeException(getString(R.string.photofile_not_existing));
            }

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true; // just query the image size in the first step
            BitmapFactory.decodeFile(cameraRawPictureFile.getPath(), options);

            int sampling = options.outWidth / STORED_FOTO_WIDTH;
            if (sampling > 1) {
                options.inSampleSize = sampling;
            }
            options.inJustDecodeBounds = false;

            Bitmap scaledScreen = BitmapFactory.decodeFile(cameraRawPictureFile.getPath(), options);

            saveScaledBitmap(storagePictureFile, scaledScreen);
            // temp file begone!
            cameraRawPictureFile.delete();
        } else if (requestCode == REQUEST_SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            Bitmap bitmap = getBitmapFromUri(selectedImageUri);

            int sampling = bitmap.getWidth() / STORED_FOTO_WIDTH;
            Bitmap scaledScreen = bitmap;
            if (sampling > 1) {
                scaledScreen = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / sampling,
                        bitmap.getHeight() / sampling, false);
            }

            saveScaledBitmap(storagePictureFile, scaledScreen);
        }
    } catch (Exception e) {
        Log.e(TAG, "Error processing photo", e);
        Toast.makeText(getApplicationContext(), getString(R.string.error_processing_photo) + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap resizeBitmap(Bitmap bitmap, int width, int height) {
    int scaledWidth = bitmap.getWidth();
    int scaledHeight = bitmap.getHeight();

    if (scaledWidth < scaledHeight) {
        float scale = width / (float) scaledWidth;

        scaledWidth = width;/*from   ww  w  .  j  a  v a  2s. c  o m*/
        scaledHeight = (int) Math.ceil(scaledHeight * scale);
        if (scaledHeight < height) {
            scale = height / (float) scaledHeight;

            scaledHeight = height;
            scaledWidth = (int) Math.ceil(scaledWidth * scale);
        }
    } else {
        float scale = height / (float) scaledHeight;

        scaledHeight = height;
        scaledWidth = (int) Math.ceil(scaledWidth * scale);

        if (scaledWidth < width) {
            scale = width / (float) scaledWidth;

            scaledWidth = width;
            scaledHeight = (int) Math.ceil(scaledHeight * scale);
        }
    }

    Bitmap bmp = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);

    bitmap.recycle();
    bitmap = null;

    return bmp;
}

From source file:com.cloverstudio.spika.CameraCropActivity.java

private void _scaleBitmap() {
    int image_width = this.mBitmap.getWidth();
    int image_height = this.mBitmap.getHeight();
    int new_image_width;
    int new_image_height;
    int _screen_width = 640;

    if (image_width >= image_height) {
        if (image_height < _screen_width) {
            new_image_width = (int) ((float) image_width * ((float) _screen_width / (float) image_height));
        } else {/*  w  w w.  j av  a  2s .  com*/
            new_image_width = (int) ((float) image_width / ((float) image_height / (float) _screen_width)); // ok
        }
        this.mBitmap = Bitmap.createScaledBitmap(this.mBitmap, new_image_width, _screen_width, true);

    } else if (image_width < image_height) {
        if (image_width < _screen_width) {
            new_image_height = (int) ((float) image_height * ((float) _screen_width / (float) image_width));
        } else {
            new_image_height = (int) ((float) image_height / ((float) image_width / (float) _screen_width));
        }

        this.mBitmap = Bitmap.createScaledBitmap(mBitmap, _screen_width, new_image_height, true);
    }
}

From source file:com.abc.driver.TruckActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CellSiteConstants.TAKE_PICTURE || requestCode == CellSiteConstants.PICK_PICTURE) {

        Uri uri = null;/*  w w w.j a  va  2s.  c om*/
        if (requestCode == CellSiteConstants.TAKE_PICTURE) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_PICTURE) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().getMyTruck().setLicenseImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        // doCrop();

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTLPiv.setImageBitmap(scaledBmp);
        isPortraitChanged = true;
        Log.d(TAG, "onActivityResult PICK_PICTURE");
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_LICENSE_URL);

    } else if (requestCode == CellSiteConstants.CROP_PICTURE) {
        Log.d(TAG, "crop picture");
        // processFile();

        if (data != null) {
            Bundle extras = data.getExtras();
            Bitmap photo = extras.getParcelable("data");

            trcukLicenseBmp = photo;
            mTLPiv.setImageBitmap(trcukLicenseBmp);
            mUpdateImageTask = new UpdateImageTask();
            mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                    Utils.bitmap2String(trcukLicenseBmp), CellSiteConstants.UPDATE_DRIVER_LICENSE_URL);

            isPortraitChanged = true;
        }
    } else if (requestCode == CellSiteConstants.TAKE_PICTURE2
            || requestCode == CellSiteConstants.PICK_PICTURE2) {

        Uri uri = null;
        if (requestCode == CellSiteConstants.TAKE_PICTURE2) {
            uri = imageUri;

        } else if (requestCode == CellSiteConstants.PICK_PICTURE2) {
            uri = data.getData();

        }

        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, filePathColumn, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();
            Log.d(TAG, "filePath =" + filePath);
            Log.d(TAG, "uri=" + uri.toString());
            imageUri = Uri.fromFile(new File(filePath));
        } else //
        {
            if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                Toast.makeText(this, R.string.sdcard_occupied, Toast.LENGTH_SHORT).show();
                return;
            }

            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
            File tmpFile = new File(app.regUserPath + File.separator + "IMG_" + timeStamp + ".png");
            File srcFile = new File(uri.getPath());
            if (srcFile.exists()) {
                try {
                    Utils.copyFile(srcFile, tmpFile);
                    app.getUser().getMyTruck().setPhotoImageUrl(tmpFile.getAbsolutePath());
                } catch (Exception e) {
                    Toast.makeText(this, R.string.create_tmp_file_fail, Toast.LENGTH_SHORT).show();
                    return;
                }
            } else {
                Log.d(TAG, "Logic error, should not come to here");
                Toast.makeText(this, R.string.file_not_found, Toast.LENGTH_SHORT).show();
                return;
            }

            imageUri = Uri.fromFile(tmpFile);
        }

        // doCrop();

        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        Bitmap scaledBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTPiv.setImageBitmap(scaledBmp);
        // s isChanged = true;
        mUpdateImageTask = new UpdateImageTask();
        mUpdateImageTask.execute("" + app.getUser().getId(), "" + app.getUser().getMyTruck().getTruckId(),
                Utils.bitmap2String(scaledBmp), CellSiteConstants.UPDATE_TRUCK_PHOTO_URL);

    } else if (requestCode == CellSiteConstants.UPDATE_TRUCK_MOBILE_REQUSET) {
        Log.d(TAG, "mobile changed");
        if (app.getUser().getMyTruck().getMobileNum() == null) {
            mTMtv.setText(app.getUser().getMobileNum());
            app.getUser().getMyTruck().setMobileNum(app.getUser().getMobileNum());

        } else {
            mTMtv.setText(app.getUser().getMyTruck().getMobileNum());
        }
    }
}

From source file:de.uulm.graphicalpasswords.openmiba.MIBACreatePasswordActivity.java

public void changeBackground(int imageindex) {
    int img = 0;//from w  ww .java2  s  .c o  m
    if (imageindex == -1) {
        img = R.drawable.ccp000;
    } else
        img = R.drawable.ccp001 + imageindex;

    seenPictureIds.add(img);

    Bitmap bmp = BitmapFactory.decodeResource(getResources(), img);
    bmp = Bitmap.createScaledBitmap(bmp, width, height, true);

    Drawable d = new BitmapDrawable(getResources(), bmp);
    bmp = null; // prevent outofmemory
    tblLayout.setBackgroundDrawable(d);

}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override//from   w  w  w.  j  a va 2s . co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.d(LOG_TAG, "onCreate() : " + savedInstanceState);

    setContentView(R.layout.activity_jet_pack_elf);

    // App Invites
    mInvitesFragment = AppInvitesFragment.getInstance(this);

    // App Measurement
    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_rocket));

    // [ANALYTICS SCREEN]: Rocket Sleigh
    AnalyticsManager.initializeAnalyticsTracker(this);
    AnalyticsManager.sendScreenView(R.string.analytics_screen_rocket);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        ImmersiveModeHelper.setImmersiveSticky(getWindow());
        ImmersiveModeHelper.installSystemUiVisibilityChangeListener(getWindow());
    }

    mIntroVideo = (VideoView) findViewById(R.id.intro_view);
    mIntroControl = findViewById(R.id.intro_control_view);
    if (savedInstanceState == null) {
        String path = "android.resource://" + getPackageName() + "/" + R.raw.jp_background;
        mBackgroundPlayer = new MediaPlayer();
        try {
            mBackgroundPlayer.setDataSource(this, Uri.parse(path));
            mBackgroundPlayer.setLooping(true);
            mBackgroundPlayer.prepare();
            mBackgroundPlayer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

        boolean nomovie = false;
        if (getIntent().getBooleanExtra("nomovie", false)) {
            nomovie = true;
        } else if (Build.MANUFACTURER.toUpperCase().contains("SAMSUNG")) {
            //                nomovie = true;
        }
        if (!nomovie) {
            mIntroControl.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    endIntro();
                }
            });
            path = "android.resource://" + getPackageName() + "/" + R.raw.intro_wipe;
            mIntroVideo.setVideoURI(Uri.parse(path));
            mIntroVideo.setOnCompletionListener(this);
            mIntroVideo.start();
            mMoviePlaying = true;
        } else {
            mIntroControl.setOnClickListener(null);
            mIntroControl.setVisibility(View.GONE);
            mIntroVideo.setVisibility(View.GONE);
        }
    } else {
        mIntroControl.setOnClickListener(null);
        mIntroControl.setVisibility(View.GONE);
        mIntroVideo.setVisibility(View.GONE);
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // For hit indication.

    mHandler = new Handler(); // Get the main UI handler for posting update events

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    Log.d(LOG_TAG, "Width: " + dm.widthPixels + " Height: " + dm.heightPixels + " Density: " + dm.density);

    mScreenHeight = dm.heightPixels;
    mScreenWidth = dm.widthPixels;
    mSlotWidth = mScreenWidth / SLOTS_PER_SCREEN;

    // Setup the random number generator
    mRandom = new Random();
    mRandom.setSeed(System.currentTimeMillis()); // This is ok.  We are not looking for cryptographically secure random here!

    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Setup the background/foreground
    mBackgroundLayout = (LinearLayout) findViewById(R.id.background_layout);
    mBackgroundScroll = (HorizontalScrollView) findViewById(R.id.background_scroll);
    mForegroundLayout = (LinearLayout) findViewById(R.id.foreground_layout);
    mForegroundScroll = (HorizontalScrollView) findViewById(R.id.foreground_scroll);

    mBackgrounds = new Bitmap[6];
    mBackgrounds2 = new Bitmap[6];
    mExitTransitions = new Bitmap[6];
    mEntryTransitions = new Bitmap[6];

    // Need to vertically scale background to fit the screen.  Checkthe image size
    // compared to screen size and scale appropriately.  We will also use the matrix to translate
    // as we move through the level.
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), BACKGROUNDS[0]);
    Log.d(LOG_TAG, "Bitmap Width: " + bmp.getWidth() + " Height: " + bmp.getHeight() + " Screen Width: "
            + dm.widthPixels + " Height: " + dm.heightPixels);
    mScaleY = (float) dm.heightPixels / (float) bmp.getHeight();
    mScaleX = (float) (dm.widthPixels * 2) / (float) bmp.getWidth(); // Ensure that a single bitmap is 2 screens worth of time.  (Stock xxhdpi image is 3840x1080)

    if ((mScaleX != 1.0f) || (mScaleY != 1.0f)) {
        Bitmap tmp = Bitmap.createScaledBitmap(bmp, mScreenWidth * 2, mScreenHeight, false);
        if (tmp != bmp) {
            bmp.recycle();
            bmp = tmp;
        }
    }
    BackgroundLoadTask.createTwoBitmaps(bmp, mBackgrounds, mBackgrounds2, 0);

    // Load the initial background view
    addNextImages(0);
    addNextImages(0);

    mWoodObstacles = new TreeMap<Integer, Bitmap>();
    mWoodObstacleList = new ArrayList<Integer>();
    mWoodObstacleIndex = 0;
    // We need the bitmaps, so we do pre-load here synchronously.
    initObstaclesAndPreLoad(WOOD_OBSTACLES, 3, mWoodObstacles, mWoodObstacleList);

    mCaveObstacles = new TreeMap<Integer, Bitmap>();
    mCaveObstacleList = new ArrayList<Integer>();
    mCaveObstacleIndex = 0;
    initObstacles(CAVE_OBSTACLES, 2, mCaveObstacleList);

    mFactoryObstacles = new TreeMap<Integer, Bitmap>();
    mFactoryObstacleList = new ArrayList<Integer>();
    mFactoryObstacleIndex = 0;
    initObstacles(FACTORY_OBSTACLES, 2, mFactoryObstacleList);

    // Setup the elf
    mElf = (ImageView) findViewById(R.id.elf_image);
    mThrust = (ImageView) findViewById(R.id.thrust_image);
    mElfLayout = (LinearLayout) findViewById(R.id.elf_container);
    loadElfImages();
    updateElf(false);
    // Elf should be the same height relative to the height of the screen on any platform.
    Matrix scaleMatrix = new Matrix();
    mElfScale = ((float) dm.heightPixels * 0.123f) / (float) mElfBitmap.getHeight(); // On a 1920x1080 xxhdpi screen, this makes the elf 133 pixels which is the height of the drawable.
    scaleMatrix.preScale(mElfScale, mElfScale);
    mElf.setImageMatrix(scaleMatrix);
    mThrust.setImageMatrix(scaleMatrix);
    mElfPosX = (dm.widthPixels * 15) / 100; // 15% Into the screen
    mElfPosY = (dm.heightPixels - ((float) mElfBitmap.getHeight() * mElfScale)) / 2; // About 1/2 way down.
    mElfVelX = (float) dm.widthPixels / 3000.0f; // We start at 3 seconds for a full screen to scroll.
    mGravityAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((1.2 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 1.2 seconds
    mThrustAccelY = (float) (2 * dm.heightPixels) / (float) Math.pow((0.7 * 1000.0), 2.0); // a = 2*d/t^2 Where d = height in pixels and t = 0.7 seconds

    // Setup the control view
    mControlView = findViewById(R.id.control_view);
    mGestureDetector = new GestureDetector(this, this);
    mGestureDetector.setIsLongpressEnabled(true);
    mGestureDetector.setOnDoubleTapListener(this);

    mScoreLabel = getString(R.string.score);
    mScoreText = (TextView) findViewById(R.id.score_text);
    mScoreText.setText("0");

    mPlayPauseButton = (ImageView) findViewById(R.id.play_pause_button);
    mExit = (ImageView) findViewById(R.id.exit);

    // Is Tv?
    mIsTv = TvUtil.isTv(this);
    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": 0");
        mPlayPauseButton.setVisibility(View.GONE);
        mExit.setVisibility(View.GONE);
        // move scoreLayout position to the Top-Right corner.
        View scoreLayout = findViewById(R.id.score_layout);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) scoreLayout.getLayoutParams();
        params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

        final int marginTop = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_top);
        final int marginLeft = getResources().getDimensionPixelOffset(R.dimen.overscan_margin_left);

        params.setMargins(marginLeft, marginTop, 0, 0);
        scoreLayout.setLayoutParams(params);
        scoreLayout.setBackground(null);
        scoreLayout.findViewById(R.id.score_text_seperator).setVisibility(View.GONE);
    } else {
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setOnClickListener(this);
        mExit.setOnClickListener(this);
    }

    mBigPlayButtonLayout = findViewById(R.id.big_play_button_layout);
    mBigPlayButtonLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // No interaction with the screen below this one.
            return true;
        }
    });
    mBigPlayButton = (ImageButton) findViewById(R.id.big_play_button);
    mBigPlayButton.setOnClickListener(this);

    // For showing points when getting presents.
    mPlus100 = (ImageView) findViewById(R.id.plus_100);
    m100Anim = new AlphaAnimation(1.0f, 0.0f);
    m100Anim.setDuration(1000);
    m100Anim.setFillBefore(true);
    m100Anim.setFillAfter(true);
    mPlus500 = (ImageView) findViewById(R.id.plus_500);
    m500Anim = new AlphaAnimation(1.0f, 0.0f);
    m500Anim.setDuration(1000);
    m500Anim.setFillBefore(true);
    m500Anim.setFillAfter(true);

    // Get the obstacle layouts ready.  No obstacles on the first screen of a level.
    // Prime with a screen full of obstacles.
    mObstacleLayout = (LinearLayout) findViewById(R.id.obstacles_layout);
    mObstacleScroll = (HorizontalScrollView) findViewById(R.id.obstacles_scroll);

    // Initialize the present bitmaps.  These are used repeatedly so we keep them loaded.
    mGiftBoxes = new Bitmap[GIFT_BOXES.length];
    for (int i = 0; i < GIFT_BOXES.length; i++) {
        mGiftBoxes[i] = BitmapFactory.decodeResource(getResources(), GIFT_BOXES[i]);
    }

    // Add starting obstacles.  First screen has presents.  Next 3 get obstacles.
    addFirstScreenPresents();
    //        addFinalPresentRun();  // This adds 2 screens of presents
    //        addNextObstacles(0, 1);
    addNextObstacles(0, 3);

    // Setup the sound pool
    mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
    mSoundPool.setOnLoadCompleteListener(this);
    mCrashSound1 = mSoundPool.load(this, R.raw.jp_crash_1, 1);
    mCrashSound2 = mSoundPool.load(this, R.raw.jp_crash_2, 1);
    mCrashSound3 = mSoundPool.load(this, R.raw.jp_crash_3, 1);
    mGameOverSound = mSoundPool.load(this, R.raw.jp_game_over, 1);
    mJetThrustSound = mSoundPool.load(this, R.raw.jp_jet_thrust, 1);
    mLevelUpSound = mSoundPool.load(this, R.raw.jp_level_up, 1);
    mScoreBigSound = mSoundPool.load(this, R.raw.jp_score_big, 1);
    mScoreSmallSound = mSoundPool.load(this, R.raw.jp_score_small, 1);
    mJetThrustStream = 0;

    if (!mMoviePlaying) {
        doCountdown();
    }
}

From source file:com.lastsoft.plog.adapter.PlayAdapter.java

public Bitmap resizeImageForImageView(Bitmap bitmap, int size) {
    Bitmap resizedBitmap;/* www .j a  v a  2  s .  c  o m*/
    int originalWidth = bitmap.getWidth();
    int originalHeight = bitmap.getHeight();
    int newWidth = -1;
    int newHeight = -1;
    float multFactor;
    if (originalHeight > originalWidth) {
        newHeight = size;
        multFactor = (float) originalWidth / (float) originalHeight;
        newWidth = (int) (newHeight * multFactor);
    } else if (originalWidth > originalHeight) {
        newWidth = size;
        multFactor = (float) originalHeight / (float) originalWidth;
        newHeight = (int) (newWidth * multFactor);
    } else if (originalHeight == originalWidth) {
        newHeight = size;
        newWidth = size;
    }
    resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);
    return resizedBitmap;
}

From source file:com.abc.driver.PersonalActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH,
                CellSiteConstants.IMAGE_HEIGHT, false));

        mUserPortraitIv.setImageBitmap(app.getPortaritBitmap());
        isPortraitChanged = true;//  ww w.  ja  v a  2  s.  c  o m

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH);
        intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueA.java

/**
 *        Check Image Orientation  //  www . j  a v  a  2 s . c o  m
 */
public void CheckOrient() {

    BitmapFactory.Options options = new BitmapFactory.Options(); // Resize is needed otherwize outofmemory exception
    options.inSampleSize = 6;

    //------------- read tmp file ------------------ 
    Image_BMP = BitmapFactory.decodeFile(image_path_source_temp, options); // , options

    //---------------- find exif header --------
    ExifInterface exif;
    String exifOrientation = "0"; // 0 = exif not working
    try {
        exif = new ExifInterface(image_path_source_temp);
        exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    //---------------- Resize ---------------------
    if (exifOrientation.equals("0")) {
        if (Image_BMP.getWidth() < Image_BMP.getHeight() && Image_BMP.getWidth() > 400) {
            Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 400, 640, true); // <- To sent
        } else if (Image_BMP.getWidth() > Image_BMP.getHeight() && Image_BMP.getWidth() > 640) {
            Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 640, 400, true); // <- To sent
        }
    } else {

        if (exifOrientation.equals("1") && Image_BMP.getWidth() > 640) { // normal

            Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 640, 400, true); // <- To sent

        } else if (exifOrientation.equals("6") && Image_BMP.getWidth() > 400) { // rotated 90 degrees

            // Rotate
            Matrix matrix = new Matrix();

            int bmwidth = Image_BMP.getWidth();
            int bmheight = Image_BMP.getHeight();

            matrix.postRotate(90);

            Image_BMP = Bitmap.createBitmap(Image_BMP, 0, 0, bmwidth, bmheight, matrix, true);

            Image_BMP = Bitmap.createScaledBitmap(Image_BMP, 400, 640, true); // <- To sent
        }
    }

    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

    //------------ now store as jpg over the temp jpg
    File imagef = new File(image_path_source_temp);
    try {
        Image_BMP.compress(Bitmap.CompressFormat.JPEG, 95, new FileOutputStream(imagef));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) {
    boolean isLandscape = bitmap.getWidth() > bitmap.getHeight();

    int newWidth, newHeight;
    if (isLandscape) {
        newWidth = maxSize;/* ww  w  .  ja v  a  2 s  . c om*/
        newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight());
    } else {
        newHeight = maxSize;
        newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth());
    }

    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);

    if (resizedBitmap != bitmap)
        bitmap.recycle();

    Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(),
            Config.ARGB_8888);

    Canvas roundedCanvas = new Canvas(roundedProfile);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 7.0f;

    paint.setAntiAlias(true);
    roundedCanvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint);
    return roundedProfile;
}