Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:10:49+00:00 2026-06-12T00:10:49+00:00

I need to post-release support different display densities on Android During development drawable-hdpi has

  • 0

I need to post-release support different display densities on Android

During development drawable-hdpi has grown to 160 png (like 20 of them 9 patch) assets

I now need to convert all those bitmaps to mdpi, ldpi (layouts and drawables XML are already fine, to avoid raising OOM on LayoutInflater

Is there any tool suitable to convert all those bitmaps in batch ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:10:50+00:00Added an answer on June 12, 2026 at 12:10 am

    Here is a simple script to create lower-resolution Android drawables from higher-resolution ones.

    For example, given a batch of -xhdpi images, it can generate -hdpi and -mdpi images.

    With this script, it’s possible to export only highest-resolution artwork from authoring tools and then create the lower-resolution versions with a few batch commands.

    Script usage:

    drawable_convert.py -d res/drawable-mdpi -d res/drawable-hdpi res/drawable-xhdpi-v14/*.png
    

    This will take every png file from xhdpi and place lower-resolution versions into mdpi and hdpi folders.

    http://kmansoft.com/2012/05/23/scale-android-drawables-with-a-script/
    original script, https://gist.github.com/2771791


    Script itself, to avoid dependency on github gist/original blogpost.
    name drawable_convert.py

    #!/usr/bin/python
    
    import sys
    import argparse
    import os
    import re
    
    '''
    A simple script to create lower-resolution Android drawables from higher-resolution ones.
    
    For example, given a batch of -xhdpi images, you can generate -hdpi and -mdpi images.
    
    This makes it possible to only export highest-resolution artwork from image authoring tools, and
    automate the rest.
    
    Usage:
    
       drawable_convert.py -d res/drawable-mdpi -d res/drawable-hdpi res/drawable-xhdpi-v14/select*.png
    
       ... will take select*.png from xhdpi and place versions into mdpi and hdpi folders.
    
       Correct resize ratios are computed based on resource directory names.
    
       Actual scaling is done by ImageMagick's convert command.
    '''
    
    class Converter:
        def __init__(self, dstList):
            print u'Dst list: {0}'.format(dstList)
            self.mDstList = dstList
    
        def convert(self, src):
            for dstpath in self.mDstList:
                (srcpath, srcname) = os.path.split(src)
                dst = os.path.join(dstpath, srcname)
                self.convertOne(src, dst)
    
        def convertOne(self, src, dst):
            print u'\n*****\n{0} to {1}\n*****\n'.format(src, dst)
            '''
            Determine relative density
            '''
            srcDpi = self.getDpi(src)
            dstDpi = self.getDpi(dst)
    
            if srcDpi < dstDpi:
                print u'NOT converting from {0}dpi to {1}dpi'.format(srcDpi, dstDpi)
            else:
                factor = dstDpi*100/srcDpi
                print u'Converting from {0}dpi to {1}dpi, {2}%'.format(srcDpi, dstDpi, factor)
                cmd = u'convert -verbose "{0}" -resize "{2}%x{2}%" "{1}"'.format(src, dst, factor)
                os.system(cmd)
    
        def getDpi(self, f):
            p = os.path.dirname(f)
            if re.match('.*drawable.*\\-mdpi.*', p):
                return 160
            elif re.match('.*drawable.*\\-hdpi.*', p):
                return 240
            elif re.match('.*drawable.*\\-xhdpi.*', p):
                return 320
            else:
                raise ValueError(u'Cannot determine densitiy for {0}'.format(p))
    
    if __name__ == "__main__":
        '''
        Parse command line arguments
        '''
        parser = argparse.ArgumentParser(description='Converts drawable resources in Android applications')
        parser.add_argument('-d', dest='DST', action='append', required=True, help='destination directory')
        parser.add_argument('src', nargs='+', help='files to convert (one or more)')
        args = parser.parse_args()
    
        cv = Converter(args.DST)
        for src in args.src:
            cv.convert(src)
    
    
    '''
    
    
    if [ $# -lt 1 ] ; then
        echo "Usage: $0 file_list"
        exit 1
    fi
    
    for f in $*
    do
        echo "File: ${f}"
        convert -verbose "${f}" -resize "75%x75%" "../drawable-hdpi/${f}"
        convert -verbose "${f}" -resize "50%x50%" "../drawable-mdpi/${f}"
    done
    
    '''
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to invoke a webservice via Android. I need to POST some
There was a post about preparations for Andoid Icecream Sandwich release on Android Dev
UPDATE #1 9/18 My company has decided to entirely revamp their development/release cycle to
I need to post message on a certain FB page as a owner by
I need to post in the background with Greasemonkey. I tried to create an
I need to post a form on a new website which is UTF-8 encoded.
I need to post some text to a remote server over HTTP, this server
I don't think I need to post my code (there's lots of it) but
I've got a form and I need to post data to the server every
In my app, I have this scenario where I need to post an object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.