그래서 나는 리소스 파일에서로드 한 비트 맵 (AN PNG 이미지)이 : 내가 사용 번만 비트 맵을 그리면안드로이드 : 문제 캔버스에 반복해서 같은 비트 맵을 그릴 때
Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.wave);
을 canvas.drawBitmap(...);
아무 문제 없습니다. 그러나 동일한 비트 맵을 여러 번 그으면 그림이 계속 깜박입니다.
동일한 비트 맵을 두 번 이상 사용할 수 없다는 의심 때문에 동일한 그림을 그릴 때마다 이미지를 새로운 비트 맵에로드하려고 시도했지만 도움이되지 않아 동작이 계속 유지됩니다.
프로그램은 복잡하지만 기본적으로 나는 바다 물결을 그려보고 싶습니다. 나는 작은 파도의 이미지를 가지고있다. 웨이브의 효과를 화면의 왼쪽 가장자리에서 오른쪽 가장자리로 이동하려면 비트 맵 왼쪽 가장자리의 위치를 추적합니다.
// The ocean.
private ArrayList<Wave> waves;
// Draw the waves and update their positions.
for (int i = 0; i < this.waves.size(); i++)
{
Wave wave = this.waves.get(i);
// Go through each of the sub-waves of this current wave.
for (int j = 0; j < wave.getSubWaveEdges().size(); j++)
{
// Get the sub wave.
final float subWaveEdge = wave.getSubWaveEdges().get(j);
canvas.drawBitmap(wave.getSubWave(j), subWaveEdge, 40, brush);
wave.setSubWaveEdge(j, subWaveEdge + (float) 0.5);
}
// Update this current wave.
wave.update();
// If the wave has passed the left edge of the screen then add a new sub-wave.
if (wave.getFarthestEdge() >= 0)
wave.addSubWaveEdges(wave.getFarthestEdge() - this.getWidth());
}
비트 맵의 좌측 에지가 화면 내에 있을지
다음 I 동일한 이미지 파일에서 새로운 맵을 만들고 그린다. 다음은 클래스 웨이브는 다음과 같습니다private class Wave
{
private Bitmap wave;
private float farthestEdge;
private ArrayList<Float> subWaveEdges;
private ArrayList<Bitmap> subWaves;
public Wave(Bitmap wave)
{
this.wave = wave;
this.farthestEdge = 0;
this.subWaveEdges = new ArrayList<Float>();
this.subWaves = new ArrayList<Bitmap>();
}
public Bitmap getWave()
{ return this.wave; }
public void setWave (Bitmap wave)
{ this.wave = wave; }
public float getFarthestEdge()
{ return this.farthestEdge; }
public void setFarthestEdge (final float furthestEdge)
{ this.farthestEdge = furthestEdge; }
public ArrayList<Float> getSubWaveEdges()
{ return subWaveEdges; }
public void setSubWaveEdge (final int index, final float value)
{
this.subWaveEdges.remove(index);
this.subWaveEdges.add(value);
}
public void addSubWaveEdges (final float edge)
{
this.subWaveEdges.add(edge);
Bitmap newSubWave = BitmapFactory.decodeResource(getResources(), R.drawable.wave);
newSubWave = Bitmap.createScaledBitmap(newSubWave, MasterView.this.getWidth(), newSubWave.getHeight(), true);
this.subWaves.add(newSubWave);
}
public Bitmap getSubWave(final int index)
{ return this.subWaves.get(index); }
public void update()
{
// Check to see if there is any sub-wave going outside of the screen.
// If there is then remove that wave.
for (int index = 0; index < this.subWaveEdges.size(); index++)
if (this.subWaveEdges.get(index) > MasterView.this.getWidth())
{
this.subWaveEdges.remove(index);
this.subWaves.remove(index);
}
// Set the farthest edge to the other side of the screen.
this.farthestEdge = MasterView.this.getWidth();
// Get the farthest edge of the wave.
for (int index = 0; index < this.subWaveEdges.size(); index++)
if (this.subWaveEdges.get(index) < this.farthestEdge)
this.farthestEdge = this.subWaveEdges.get(index);
}
}
또 다른 의심 나는 이미지의 픽셀이 각 비트 맵 만 얻을 수 있다는 것을 의미, 두 개의 비트 맵 중 분할 나도 같은 리소스 파일에서 두 개의 비트 맵을 만들 때이 될 수있다 가지고 모든 픽셀이 아닌 일부. 비트 맵을 그릴 때 겹치는 부분이 꾸준히 그려 지므로 깜박 거리지 않아서 의심 스럽습니다.
누구나이 문제가 발생하여 해결 방법을 알고 있습니까?
감사합니다,
포스트 소스. – Wroclai
방금 한 번 해봐. – Einiosaurus