Best way to use SVG for assets on Android?

I tried using SVG assets for Android, it works okay on Neko target (desktop with the base default resolution), but on Android (N5), the resulting Bitmap is jagged (very visible). I tried smoothing both the BitmapData.draw and the Bitmap. Still jagged. Basically what I did was, I calculate the scaleFactor from the screen size compared to the base default resolution, and then render the SVG with

SVG.render(SHAPE, 0, 0, * scaleFactor, * scaleFactor);
1 Like

That doesn’t help me … because your description is not complete. :frowning:

You would help me immensely if you would show the complete code: exactly how did you calculate “scaleFactor” here?

… in other words, what is “the base default resolution?” Is it “” I surmise that “screen size” is the size of the Stage …

Unfortunately it’s a throwaway code. But I’ll try to explain it further.

base defautl resolution is the resolution that I use in project.xml (in non mobile target, neko, windows), which I usually set to 480x640

scaleFactor is calculated as mobile screen height / 640 (base height).

I assume that with SVG if I’m drawing a cicle, and the size (in pixel) that I request is larger than the default size that come from the SVG ( &, it will still be smooth. But in reality, it was jagged.

Here is how I was scaling svgs before I started using swf assets. It worked pretty well ( I was adding shapes to empty container, but it’s not necessary). Also remember about setting antialiasing to 3 or 4 in application.xml.

private function setup(path:String, scaleType:String = "x"):BitmapData
	var svg:SVG;
	var shape:Shape;
	svg = new SVG(Assets.getText(path));
	shape = new Shape();
	var targetScale:Float;
	if (scaleType == "y")targetScale = STAGE_HEIGHT / ASSETS_HEIGHT;
	else targetScale = STAGE_WIDTH / ASSETS_WIDTH;
	shape.scaleX = shape.scaleY = targetScale;
	var bitmapData = new BitmapData(Math.ceil(width), Math.ceil(height), true, 0x00FFFFFF);
	return bitmapData;