Path.transform is being applied multiple times

Go To StackoverFlow.com

0

I am writing a live wallpaper which utilizes a number of paths. I scale these paths in my shape's constructor using a matrix.

this.path = pathCoords;
this.path.transform(Scale.getMatrix());

Here is how I scale the matrix in the Scale class:

public static void setMatrix(DisplayMetrics mDisplayMetrics) {
    matrix.postScale((float) mDisplayMetrics.widthPixels / 540f,
            (float) mDisplayMetrics.heightPixels / 960f);
}

Now the live wallpaper loads just fine in the preview, but when I set it as wallpaper, the path appears to scale down again. In fact, I can reproduce it maybe 3 more times, each time the path shrinking even more. At the end it crashes with:

E/AndroidRuntime(32434): java.lang.OutOfMemoryError

What am I doing wrong? What's the reason for this behaviour?

Thanks in advance!

2012-04-04 23:08
by Vas


0

I managed to work around this issue by adding a reset prior to scaling:

public static void setMatrix(DisplayMetrics mDisplayMetrics) { 
matrix.reset(); 
matrix.preScale((float) mDisplayMetrics.widthPixels / 540f, (float) mDisplayMetrics.heightPixels / 960f); 
}

However, I think the problem is that the live wallpaper gets loaded (and scaled) multiple times into memory, which ultimately results in the java.lang.OutOfMemoryError. But that's a different matter altogether :)

2012-04-05 18:27
by Vas
Ads