How to rescale a bitmap file in android?

How to rescale a bitmap file in android?

Content Index :

How to rescale a bitmap file in android?
Tag : android , By : AnthonyC
Date : December 01 2020, 04:55 PM

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Cannot rescale bitmap

Tag : android , By : Jµ.
Date : March 29 2020, 07:55 AM
I hope this helps you . I am tring to implement "extend" button to fit image into chosen boundaries.
public static Bitmap resizeBitmap(Bitmap photo, float x, float y) {

    try {
        // get current bitmap width and height
        int width = photo.getWidth();
        int height = photo.getHeight();

        // determine how much to scale
        float scaleWidth = x / width;
        float scaleHeight = y / height;

        // create the matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bitmap
        matrix.postScale(scaleWidth, scaleHeight);

        // recreate the new bitmap
        Bitmap resizebitmap = Bitmap.createBitmap(photo, 0, 0, width,
                height, matrix, false);
        return resizebitmap;

    } catch (NullPointerException e) {
    } catch (OutOfMemoryError e) {
    return null;

OutOfMemory Error when trying to rescale a Bitmap

Tag : android , By : Tim Benninghoff
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Please have a look at my related question:
High resolution Image - OutOfMemoryError
public  Bitmap scaleDownBitmap(Bitmap photo, int newHeight) {

     final float densityMultiplier = getResources().getDisplayMetrics().density;

     int h= (int) (newHeight*densityMultiplier);
     int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));

     photo = Bitmap.createScaledBitmap(photo, w, h, true);

     return photo;
ImageView.setImageBitmap(scaleDownBitmap(youroldbitmap, 300));

Android - Resource Bitmap uses more memory than Bitmap from file

Tag : android , By : inquiringmind
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I noticed something odd. If I open an image (1.6mb) from Drawable Resource, the app crashes with the OutOfMemory error, however, if I open the same image which is saved on SD Card, the app does not crash. , check this out :

How to examine the potential filesize/bitmap size before decoding the bitmap from file path in android?

Tag : android , By : Maplye
Date : March 29 2020, 07:55 AM
this will help Instead of doing bitmapOptions.inJustDecodeBounds = false; change that to true and you will get back the bounds of the image
you should probably read this too http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Faster Bitmap Rescale

Tag : cpp , By : aspitzer
Date : March 29 2020, 07:55 AM
hope this fix your issue Refactored the function to apply your suggestions and enabled the SSE2 and fp:fast options. Performance increased by 3x:
static int ReScale(char* srcBuffer, int srcLen, int srcStart, int srcStride, int srcHeight, VideoInfo::ePixelFormat srcPixelFormat,
                   char* dstBuffer, int dstLen, int dstStart, int dstStride, int dstHeight, VideoInfo::ePixelFormat dstPixelFormat, bool reverseCopy)
    int srcPixelDepth = VideoInfo::GetPixelFormatSize(srcPixelFormat);
    int srcWidth = static_cast<int>(floor(srcStride / static_cast<float>(srcPixelDepth)));
    int dstPixelDepth = VideoInfo::GetPixelFormatSize(dstPixelFormat);
    int dstWidth = static_cast<int>(floor(dstStride / static_cast<float>(dstPixelDepth)));

    float resizeRatio = min(dstWidth / static_cast<float>(srcWidth), dstHeight / static_cast<float>(srcHeight));
    int dstXOffset = static_cast<int>((dstWidth - (resizeRatio * srcWidth)) / 2.f);
    int dstYOffset = static_cast<int>((dstHeight - (resizeRatio * srcHeight)) / 2.f);
    ZeroMemory(dstBuffer + dstStart, dstLen);

    srcBuffer += srcStart;
    dstBuffer += dstStart;

    dstWidth -= 2 * dstXOffset;
    dstHeight -= 2 * dstYOffset;

    int dstPixelOffset = 0;
    int srcPixelOffset = 0;
    int srcPixelYOffset = 0;
    float srcPixelXOffset = 0;
    float srcPixelXStride = 1 / resizeRatio;
    int pixelDepthSize = min(srcPixelDepth, dstPixelDepth);
    for (int y = 0; y < dstHeight; y++)
        dstPixelOffset = dstXOffset * dstPixelDepth + (y + dstYOffset) * dstStride;
        srcPixelYOffset = static_cast<int>(min(y / resizeRatio, srcHeight));
        srcPixelYOffset = (reverseCopy ? (srcHeight - (srcPixelYOffset + 1)) : srcPixelYOffset) * srcStride;
        srcPixelXOffset = 0;
        for (int x = 0; x < dstWidth; x++)
            srcPixelOffset = srcPixelYOffset + (static_cast<int>(min(srcPixelXOffset, srcWidth)) * srcPixelDepth);
            if (srcPixelOffset + pixelDepthSize < srcLen && dstPixelOffset + pixelDepthSize < dstLen)
                memcpy(dstBuffer + dstPixelOffset, srcBuffer + srcPixelOffset, pixelDepthSize);
            dstPixelOffset += dstPixelDepth;
            srcPixelXOffset += srcPixelXStride;
    return 0;
Related Posts Related QUESTIONS :
  • Android: unable to hide appbar on scrolling
  • Best layout for form-style screen
  • How To create multiple function in Adapter Class Android with Retrofit
  • Can the Android Flow virtual layout handle variable-width Views
  • How to fix "Unable to load class 'dagger.Multibindings'" due to problems with gradle
  • VpnService always-on "not supported by this app"
  • Android Studio - Gradle "Sync now" is not Available
  • How do i get my code to give my current location?
  • Could not initialize class sun.util.calendar.ZoneInfoFile while using Flutter firebase-notifications
  • How to implement circular to check / tick animation in Android?
  • Toolbar shadow not showing
  • Android Sqlite get rows where first character is not an Alphabet
  • why I receive "bad request" in my request by retrofit
  • Intercept NavigationUI.onNavDestinationSelected() to make backstack pop with "inclusive = true"
  • I have a problem with the navigation fragments in my proyect, it sais that I need a defaut nav host atribute but I alrea
  • How can I keep a BottomSheetDialogFragment height to always match_parent?
  • How to reference a timerPicker in android studio using kotlin
  • Firebase Crashlytics - get stacktrace info to display during CrashlyticsListener.crashlyticsDidDetectCrashDuringPrevious
  • Schedule a repeating alarm clock
  • Can't assign values outside onTouchListener
  • Is setContentView() needed to inflate a fragment?
  • Why instead of string method returns Kotlin.Unit?
  • Retrofit slash as Query
  • When does onCreateView() get called in this app?
  • Fragment is reloaded each time after rejecting location permission
  • How to read ViewModel data from sttrings.xml list of items
  • Flutter doctor does not see vs code ,VS code does not detect flutter/bin
  • How to build aar in flutter
  • Is displayMetrix xdpi and ydpi accurate?
  • How to detect doubletap on a View?
  • how to play an encrypted file in Android
  • Android: keytool error on the command line when locating debug.keystore
  • Android paint/canvas issue; drawing smooth curves
  • Problems with starting an activity in onStart
  • Performance of map overlay in conjunction with ItemizedOverlay is very poor
  • How to change android indeterminate ProgressBar color?
  • How do I change the Mobile Country Code (MCC) in the Android Emulator?
  • Stop Progressbar manual scrolling in Android
  • Android: download large file
  • Android : uploaded .apk file to server but cant download that .apk file
  • How do I distribute Android app to beta tester without using Market
  • Android Unable to launch the Inbox from a notification
  • Android: Ringer mode changed to silent doesn't stop the phone vibrating
  • Change the side the text appears on a radio button
  • Check the memory usage anp cpu and power of an application in android
  • What is the String 'volumeName' argument of MediaStore.Audio.Playlists.Members.getContentUri referring to?
  • Playing Multiple sounds at the same time in Android
  • Android: how to change the time in emulator?
  • close the soft key pad when i click on other views in android
  • Setting the position within a spinner
  • How to play ringtone/alarm sound in Android
  • How to adjust text font size to fit textview
  • "Android 2.x" vs "Google APIs" for Android AVD Setup
  • How to center buttons on screen horizontally and vertically plus equidistant apart?
  • Discrete seekbar in Android app?
  • Gradle Build Fails - Illegal exception table range in class file com/google/wireless/android/sdk/stats/GradleBuildMemory
  • register has type Long (High Half) but expected Long (Low Half)
  • Is it good idea to use Dispatcher.Main with delay( )?
  • WebView and Advanced View is Not loading partiucalr URL
  • How to show three dots at the end of text view
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com