A (175)

(Tuis.) #1

356 CHAPTER 10: Android Animation: Making Your UI Designs Move


If you are not going to have to composite your animation over other graphics (or are compositing
with blending modes using the PorterDuff class), you can also consider using a JPEG format to get a
far smaller per-frame data footprint. As you know, the JPEG codec does this by throwing away some
of the image data (and thus throwing away some of the original image’s quality).


It is important to note, however, that using JPEG for animation can increase image artifacts in each
frame of the animation. If you apply too much image compression on each frame, causing artifacts,
and you later animate the JPEG artifacts, this will cause an effect commonly termed in the industry
as “dot crawl” or “pixel crawl.”


With JPEG animation, not only do you have artifacts, but because the medium is animated, and
the artifacts are on different pixels on each frame, it’s like they are waving their hands in the air and
saying: “Here I am, I’m an important artifact!” This doesn’t lend itself to a good user experience if
your JPEG frames are poorly optimized.


Just as you can optimize a 2D animation by using the indexed (8-bit) color depth, you can also
optimize your 2D animation by using fewer frames to create the illusion of motion. As you will see
in the next chapter on digital video, the same concepts hold true for bitmap animation as with digital
video: fewer frames to store will yield a smaller data footprint, which ultimately will translate into a
smaller Android application file size for your APK.


Also, the smaller the number of frames that will be used to achieve realistic motion, the fewer frames
will have to be defined in our frame animation XML definition markup. It’s also important to note that
at runtime, fewer frames will require less processing power in order to play your frame animation,
and less memory resources to hold the frames in, before they are displayed on the device display
screen. In fact, we get professional results in this chapter by using only a few frames of animation for
your ImageView UI’s 3D animation new media assets.


Data footprint optimization becomes more important as the number of frame animations that are
included in the application increases. New media applications such as games and eBooks tend
to have several frame animations running at any given time inside the application Activity screen.
Thus, you need to consider processor power and system memory as valuable resources! Animation
assets will require careful optimization, so that the application does not use up your user’s Android
hardware device memory and CPU resources while your app is being used.


Animation Resolution: Pixels Add to File Size!


The number of pixels in each animation frame, or the frame resolution for your frame-based
animation, is of tantamount importance to the optimization of a frame animation asset data footprint.
Review the raw image data mathematics that we covered back in Chapter 9, and apply this to each
frame in your animation, so that you can calculate the exact raw data system memory footprint you
will need to hold your frame-based animation.


Just like you did with your static digital image button assets, you will need to provide (at most) five
resolution density-specific raster animation image target resolutions to be able to span every popular
Android device type screen density. For this reason, if you can make your animation a few dozen
pixels smaller for each dimension, without affecting its visual quality, this will add up to memory
savings in your endgame, no pun intended.

Free download pdf