Using pngMagic

To use the pngMagic tool by CuriousTech, first download it from the web: pngMagic.

  1. Unpack the program it to a folder.
  2. In the same folder, create the following sub-folders and place the 9-patch images in these sub-folders accordingly:

    uncompiled/drawable-ldpi

    uncompiled/drawable-mdpi

    uncompiled/drawable-hdpi

    uncompiled/drawable-xhdpi

  3. Launch the PngMagic.exe program.
  4. Copy all the text below the +++++++++++++++++ line on this page, and paste it into the PngMagic window.
  5. In PngMagic, click Run.

The whitelabel folder now contains the compiled 9-patch images, which can then be placed on the server as specified in the previous section.

+++++++++++++++++

// Batch compile pngs

// Takes 9-patch images from the folders:

// uncompiled/drawable-lpdi

// uncompiled/drawable-mpdi

// uncompiled/drawable-hpdi

// uncompiled/drawable-xhpdi

// and converts them as compiled 9-patch images in the folders:

// whitelabel/android/drawable-ldpi

// whitelabel/android/drawable-mdpi

// whitelabel/android/drawable-hdpi

// whitelabel/android/drawable-xhdpi

// (Folders will be created, and existing files will be overwritten)

source_parent = 'uncompiled'

dest_parent = 'whitelabel\\android'

folder_ldpi = 'drawable-ldpi'

folder_mdpi='drawable-mdpi'

folder_hdpi='drawable-hdpi'

folder_xhdpi='drawable-xhdpi'

var fso = new ActiveXObject('Scripting.FileSystemObject')

// ldpi

source_ldpi = fso.GetFolder( source_parent)

source_ldpi = fso.BuildPath( source_ldpi, folder_ldpi)

source_ldpi = fso.GetFolder( source_ldpi) // gets reference to folder

Pm.Echo( source_ldpi)

var subFlds_ldpi = new Enumerator(source_ldpi.files)

for (; !subFlds_ldpi.atEnd(); subFlds_ldpi.moveNext())

CompImage( subFlds_ldpi.item(), folder_ldpi )

// mdpi

source_mdpi = fso.GetFolder( source_parent)

source_mdpi = fso.BuildPath( source_mdpi, folder_mdpi)

source_mdpi = fso.GetFolder( source_mdpi) // gets reference to folder

Pm.Echo( source_mdpi)

var subFlds_mdpi = new Enumerator(source_mdpi.files)

for (; !subFlds_mdpi.atEnd(); subFlds_mdpi.moveNext())

CompImage( subFlds_mdpi.item(), folder_mdpi )

// hdpi

source_hdpi = fso.GetFolder( source_parent)

source_hdpi = fso.BuildPath( source_hdpi, folder_hdpi)

source_hdpi = fso.GetFolder( source_hdpi) // gets reference to folder

Pm.Echo( source_hdpi)

var subFlds_hdpi = new Enumerator(source_hdpi.files)

for (; !subFlds_hdpi.atEnd(); subFlds_hdpi.moveNext())

CompImage( subFlds_hdpi.item(), folder_hdpi )

// xhdpi

source_xhdpi = fso.GetFolder( source_parent)

source_xhdpi = fso.BuildPath( source_xhdpi, folder_xhdpi)

source_xhdpi = fso.GetFolder( source_xhdpi) // gets reference to folder

Pm.Echo( source_xhdpi)

var subFlds_xhdpi = new Enumerator(source_xhdpi.files)

for (; !subFlds_xhdpi.atEnd(); subFlds_xhdpi.moveNext())

CompImage( subFlds_xhdpi.item(), folder_xhdpi )

// CompImage

function CompImage( file, sub_folder) {

Gdi.LoadImage(file)

Pm.Echo( fso.GetFileName(file) )

// increase screen size if needed

if(Gdi.Width < Gdi.ImageWidth) Gdi.Width = Gdi.ImageWidth

if(Gdi.Height < Gdi.ImageHeight) Gdi.Height = Gdi.ImageHeight

Gdi.Clear(0xFFFFFFFF)

Gdi.Clear(0)

Gdi.DrawImage(0, 0)

folder_file = fso.GetParentFolderName( file)

base = fso.GetParentFolderName( folder_file)

base = fso.GetParentFolderName( base) // Move up one folder

base = fso.BuildPath(base, dest_parent)

base = fso.BuildPath(base, sub_folder)

Pm.Echo( base)

newfile = fso.BuildPath( base, fso.GetFileName(file) )

// Compile and save .9 file

Gdi.Save( newfile, 0, 0, Gdi.ImageWidth, Gdi.ImageHeight, 'Compile' )

}

Next topic

Custom graphics on Apple iOS