简体   繁体   English

如何在Java中的Android上重复位图?

[英]How can i repeat bitmap on Android in Java?

Greetings fellow programmers, I want to repeat my bitmap vertically on Android in Java. 问候程序员,我想在Java的Android上垂直重复我的位图。 I am making a game right now for Android platform such as Mario and a bitmap which is my background needs to be repeated in X-axis. 我现在正在为Android平台(例如Mario)制作游戏,需要在X轴上重复我的背景位图。 My bitmap is too large for my screen that's why I only draw a half portion of the device screen. 我的位图对于我的屏幕来说太大了,这就是为什么我只绘制设备屏幕一半的原因。 I move my background backward on each iteration in my draw method like below; 我在如下的draw方法中将每次迭代的背景向后移动;

bgSrcX[0] += 20;
bgSrcX2[0] += 20;   
bgSrc[0].set(bgSrcX[0], 0, bgSrcX2[0], bg[0].getHeight());    
canvas.drawBitmap(tileMe.getBitmap(), bgSrc[0], bgDst[0], null);   

I would be very grateful if you guys and ladies can help me. 如果您能帮助我,我将不胜感激。 Thanks in advance. 提前致谢。

Have you tried the BitmapDrawable ? 您尝试过BitmapDrawable吗?

Bitmap bitmap = getYourBitmap();
BitmapDrawable drawable = new BitmapDrawable(bitmap);
drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
someView.setBackground(drawable);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM