by Anonymous » 10 Apr 2025, 04:04
Ich habe eine Bitmap mit einer Größe von 320x480 und ich muss es auf verschiedenen Gerätebildschirmen ausdehnen. Ich habe versucht, dies zu verwenden:
Code: Select all
Rect dstRect = new Rect();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(frameBuffer, null, dstRect, null);
< /code>
Es funktioniert, das Bild füllt den gesamten Bildschirm, wie ich es wollte, aber das Bild ist pixeliert und es sieht schlecht aus. Dann habe ich es versucht: < /p>
float scaleWidth = (float) newWidth / width;
float scaleHeight = (float) newHeight / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(frameBuffer, 0, 0,
width, height, matrix, true);
canvas.drawBitmap(resizedBitmap, 0, 0, null);
< /code>
Diesmal sieht es perfekt, schön und glatt aus, aber dieser Code muss in meiner Hauptspielschleife sein, und das Erstellen von Bitmap < /code> hat es sehr langsam. Wie kann ich mein Bild ändern, damit es nicht pixeliert wird und schnell erledigt wird?Paint paint = new Paint();
paint.setFilterBitmap();
canvas.drawBitmap(bitmap, matrix, paint);
Ich habe eine Bitmap mit einer Größe von 320x480 und ich muss es auf verschiedenen Gerätebildschirmen ausdehnen. Ich habe versucht, dies zu verwenden:
[code]Rect dstRect = new Rect();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(frameBuffer, null, dstRect, null);
< /code>
Es funktioniert, das Bild füllt den gesamten Bildschirm, wie ich es wollte, aber das Bild ist pixeliert und es sieht schlecht aus. Dann habe ich es versucht: < /p>
float scaleWidth = (float) newWidth / width;
float scaleHeight = (float) newHeight / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(frameBuffer, 0, 0,
width, height, matrix, true);
canvas.drawBitmap(resizedBitmap, 0, 0, null);
< /code>
Diesmal sieht es perfekt, schön und glatt aus, aber dieser Code muss in meiner Hauptspielschleife sein, und das Erstellen von Bitmap < /code> hat es sehr langsam. Wie kann ich mein Bild ändern, damit es nicht pixeliert wird und schnell erledigt wird?Paint paint = new Paint();
paint.setFilterBitmap();
canvas.drawBitmap(bitmap, matrix, paint);
[/code]