文本在Android图标 [英] Text to Image in android

查看:121
本文介绍了文本在Android图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,我需要生成的文本图像和图像存储和SD卡。结果
谁能告诉我一个图书馆(就像textimagegenerator用于Java)我需要兼容的Andr​​oid库或来源,我可以用这个?


解决方案

 的TextView的TextView =新的TextView(activity.getContext());
textView.setText(的Hello World);
textView.setDrawingCacheEnabled(真);
textView.destroyDrawingCache();
textView.buildDrawingCache();
位图的位图= getTransparentBitmapCopy(textView.getDrawingCache());
私人位图getTransparentBitmapCopy(位图源)
{
    INT宽度= source.getWidth();
    INT高度= source.getHeight();
    位图副本= Bitmap.createBitmap(宽度,高度,Bitmap.Config.ARGB_8888);
    INT [] =像素新INT [宽*高]。
    source.getPixels(像素,0,宽度,0,0,宽度,高度);
    copy.setPixels(像素,0,宽度,0,0,宽度,高度);
    返回副本;
}

I am developing an application where I need to generate an Image from text and store that Image to the SDCard.
Can anyone tell me a library(just like textimagegenerator for java) I need android compatible library or source which I can use for this?

解决方案

TextView textView = new TextView(activity.getContext());
textView.setText("Hello World");
textView.setDrawingCacheEnabled(true);
textView.destroyDrawingCache();
textView.buildDrawingCache();
Bitmap bitmap = getTransparentBitmapCopy(textView.getDrawingCache());


private Bitmap getTransparentBitmapCopy(Bitmap source)
{
    int width =  source.getWidth();
    int height = source.getHeight();
    Bitmap copy = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    int[] pixels = new int[width * height];
    source.getPixels(pixels, 0, width, 0, 0, width, height);
    copy.setPixels(pixels, 0, width, 0, 0, width, height);
    return copy;
}

这篇关于文本在Android图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆