android纹理存储,android纹理文本
這是使用PorterDuffXfermode進行此操作的一種方法.
public class MainActivity extends Activity {
private EditText mEditText;
private ImageView mImageView;
private Bitmap mTexture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEditText = (EditText) findViewById(R.id.activity_main_edittext);
mImageView = (ImageView) findViewById(R.id.activity_main_image);
mTexture = BitmapFactory.decodeResource(getResources(),R.drawable.texture);
}
public void onTextCreate(View v) {
final String text = mEditText.getEditableText().toString();
Bitmap result = Bitmap.createBitmap(mTexture.getWidth(),mTexture.getHeight(),Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(200);
paint.setARGB(255,0);
canvas.drawText(text,200,paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(mTexture,paint);
paint.setXfermode(null);
mImageView.setImageBitmap(result);
}
}
布局非常簡單:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:id="@+id/activity_main_edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Write a sample text" />
android:id="@+id/activity_main_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="onTextCreate"
android:text="Do it!" />
這段代碼使用canvas.drawText()寫文本.如果要使用常規(guī)TextView,可以:
>創(chuàng)建TextView>設(shè)置文本>使用textView.draw(canvas)將TextView繪制到畫布中;>而不是使用canvas.drawText()而不是canvas.drawBitmap()
總結(jié)
以上是生活随笔為你收集整理的android纹理存储,android纹理文本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 顶墙门柜开创者楚楚顶墙是顶墙十大品牌吗?
 - 下一篇: 吸顶机和中央空调区别