1
나는 안드로이드에 대한 멍청한 존재이며, 9 가지의 오래된 안드로이드 플레이크 데모를 내 앱에 구현하려고합니다. 그러나 데모에서 사용하는 이미지에서 이미지 리소스를 내 응용 프로그램을 선택하는 중 하나로 변경하면 IllegalArgumentException이 발생합니다. 너비와 높이가 0보다 커야합니다. 내 logcat은 createdcaledbitmap 및 createFlake가 문제를 일으키는 행을 말합니다. . 데모 이미지의 너비가 75px x 90px이고 내 이미지의 너비가 166px x 72px 인 이유가 무엇인지 알 수 없습니다. 어떤 도움이라도 대단히 감사합니다. (내가 플레이크를 만들 수)9 개의 오래된 Androids 플레이크를 구현하는 문제
FLAKE VIEW CLASS
void addFlakes(int quantity) {
for (int i = 0; i < quantity; ++i) {
flakes.add(Flake.createFlake(getWidth(), droid)); //This line causes exception
}
setNumFlakes(numFlakes + quantity);
}
/**
* Subtract the specified number of droidflakes. We just take them off the end of the
* list, leaving the others unchanged.
*/
void subtractFlakes(int quantity) {
for (int i = 0; i < quantity; ++i) {
int index = numFlakes - i - 1;
flakes.remove(index);
}
setNumFlakes(numFlakes - quantity);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
// Reset list of droidflakes, then restart it with 8 flakes
flakes.clear();
numFlakes = 0;
addFlakes(8); //This line causes exception
// Cancel animator in case it was already running
animator.cancel();
// Set up fps tracking and start the animation
startTime = System.currentTimeMillis();
prevTime = startTime;
frames = 0;
animator.start();
}
FLAKE CLASS (I 크기를 조절하여 만든 비트 맵)
static Flake createFlake(float xRange, Bitmap originalBitmap) {
Flake flake = new Flake();
// Size each flake with a width between 5 and 55 and a proportional height
flake.width = (int)(5 + (float)Math.random() * 50);
float hwRatio = originalBitmap.getHeight()/originalBitmap.getWidth();
flake.height = (int)(flake.width * hwRatio);
// Position the flake horizontally between the left and right of the range
flake.x = (float)Math.random() * (xRange - flake.width);
// Position the flake vertically slightly off the top of the display
flake.y = 0 - (flake.height + (float)Math.random() * flake.height);
// Each flake travels at 50-200 pixels per second
flake.speed = 50 + (float) Math.random() * 150;
// Flakes start at -90 to 90 degrees rotation, and rotate between -45 and 45
// degrees per second
flake.rotation = (float) Math.random() * 180 - 90;
flake.rotationSpeed = (float) Math.random() * 90 - 45;
// Get the cached bitmap for this size if it exists, otherwise create and cache one
flake.bitmap = bitmapMap.get(flake.width);
if (flake.bitmap == null) {
flake.bitmap = Bitmap.createScaledBitmap(originalBitmap, //This line causes exception
(int)flake.width, (int)flake.height, true);
bitmapMap.put(flake.width, flake.bitmap);
}
return flake;
}
이 중요하지만, 원래의 데모 영상이 75x90 (너비 x 높이)이며, 이미지가 166x72 (너비 x 높이) 인 경우, 행이'떠 경우 나도 몰라 hwRatio = originalBitmap에
.getHeight()/originalBitmap.getWidth();'첫 번째 경우에는> 1이고 두 번째 경우에는 <1 인 hwRatio가 생성됩니다. 아니면 잘못된 생각으로 생각하고 있습니다. – Squonk
@ 스컹크 감사합니다. 나는 그 라인을 만지작 거리며 일하는 것을 얻었습니다. –
OK, 기꺼이 도와 드리겠습니다. – Squonk