             src = renderToBitmapData(src, Math.ceil(targetW), Math.ceil(targetH), multipassScaleThreshold);
             targetScale /= multipassScaleThreshold;
         }
-        bounds = srcBounds();
+        bounds = getBitmapDrawableBounds(src);
 
         var bmd :BitmapData = new BitmapData(w, h, true, 0x00);
         var m :Matrix = new Matrix();

        return new XML(bytes.readUTFBytes(bytes.length));
    }

    public static function renderToBitmapData (src :IBitmapDrawable, w :int, h :int,
        scale :Number = 1, multipassScaleThreshold :Number = 0.5) :BitmapData {

        function srcBounds () :Rectangle {
            if (src is BitmapData) {
                return new Rectangle(0, 0, BitmapData(src).width, BitmapData(src).height);
            } else if (src is DisplayObject) {
                return DisplayObject(src).getBounds(DisplayObject(src));
            } else {
                throw new ArgumentError("src must be a a BitmapData or a DisplayObject");
            }
        }

        var bounds :Rectangle = srcBounds();

        if (scale != 1 && !(src is BitmapData)) {
            // for down or up-scaling, render at normal size first, then scale to get the
            // benefit of bitmap smoothing. BitmapData.draw smoothing only works
            // when the source is itself a BitmapData object.
            src = renderToBitmapData(src, Math.ceil(bounds.width), Math.ceil(bounds.height), 1);
            bounds = srcBounds();
        }

        // Don't downscale by more than 50% at a time - this causes Flash's

        bmd.draw(src, m, null, null, null, true);
        return bmd;
    }

    protected static function getBitmapDrawableBounds (src :IBitmapDrawable) :Rectangle {
        if (src is BitmapData) {
            return new Rectangle(0, 0, BitmapData(src).width, BitmapData(src).height);
        } else if (src is DisplayObject) {
            return DisplayObject(src).getBounds(DisplayObject(src));
        } else {
            throw new ArgumentError("src must be a a BitmapData or a DisplayObject");
        }
    }
}
}