public static Bitmap drawText2Bitmap(String text, int imgResourceId, Context mContext) {
try {
Resources resources = mContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = BitmapFactory.decodeResource(resources, imgResourceId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
// set default bitmap config if none
if (bitmapConfig == null) bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
// resource bitmaps are imutable, so we need to convert it to mutable one
bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // new antialised Paint
paint.setColor(Color.rgb(110, 110, 110)); // text color - #3D3D3D
paint.setTextSize((int)(12 * scale)); // text size in pixels
paint.setShadowLayer(1f, 0f, 1f, Color.DKGRAY); // text shadow // draw text to the Canvas center
Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
int x = (bitmap.getWidth() - bounds.width()) / 6;
int y = (bitmap.getHeight() + bounds.height()) / 5; canvas.drawText(text, x * scale, y * scale, paint);
return bitmap;
} catch (Exception e) {
return null;
}
}

android中向bitmap里写入文字的更多相关文章

  1. Android中如何设置RadioButton在文字的右边,图标在左边

    from:http://blog.csdn.net/sunnyfans/article/details/7901592?utm_source=tuicool&utm_medium=referr ...

  2. 四十六、android中的Bitmap

    四十六.android中的Bitmap: http://www.cnblogs.com/linjiqin/archive/2011/12/28/2304940.html 四十七.实现调用Android ...

  3. android中可以使用bitmap的平铺,镜像平铺等减小图片带来的apk过大的问题

    bitmap的平铺.镜像drawable文件夹中新建bitmap,其中的tileMode属性 tileMode 属性就是用于定义背景的显示模式:  disabled  默认值,表示不使用平铺  cla ...

  4. android中获取 bitmap 像素的颜色 之吸管取色功能

    本功能是参考android API colorPickerView修改,实现类似与PS中吸管取色功能.也就是可以对图片的任意位置取该位置的RGB.本demo中,完成了色盘取色功能.当点击色盘的某个位置 ...

  5. android中对Bitmap图片设置任意角为圆角

    http://blog.csdn.net/l448288137/article/details/48276681 最近项目开发中使用到了圆角图片,网上找到的圆角图片控件大多比较死板,只可以全圆角.其中 ...

  6. android中保存Bitmap图片到指定文件夹中的方法

    /** 保存方法 */  public void saveBitmap() {   Log.e(TAG, "保存图片");   File f = new File("/s ...

  7. Android中关于使用空格对齐文字

    前言:今日编写新项目UI时,突然遇到文本有长有短无法对齐的问题(汗,以前竟从未遇到也从未考虑过这小小的问题),在资源文件中尝试Tab键.space空格键,发现效果都不能很好的实现,无奈只得请求度娘的协 ...

  8. 关于Android中获取Intent里的数据

    Intent获取数据和发送数据的办法: //直接通过Intent发送 intent.putExtra("name","wytings"); //直接通过Inte ...

  9. Android中利用C++处理Bitmap对象

    相信有些Android&图像算法开发者和我一样,遇到过这样的状况:要对Bitmap对象做一些密集计算(例如逐像素的滤波),但是在java层写循环代码来逐像素操作明显是不现实的,因为Java代码 ...

随机推荐

  1. linux协议栈部分资料

    socket实现:http://blog.csdn.net/zhangskd(含有tcp/ip专栏) http://blog.chinaunix.net/uid-20528014-id-90573.h ...

  2. CardView官方教程

    Create Cards CardView extends the FrameLayout class and lets you show information inside cards that ...

  3. ProgressBar 示例及自定义样式

    在layout中使用ProgerssBar,其中使用了自定义的样式 <ProgressBar android:id="@+id/footer_refresh_prgs" st ...

  4. JAVA文件中获取路径及WEB应用程序获取路径方法

    JAVA文件中获取路径及WEB应用程序获取路径方法 1. 基本概念的理解 `绝对路径`:你应用上的文件或目录在硬盘上真正的路径,如:URL.物理路径 例如: c:/xyz/test.txt代表了tes ...

  5. BZOJ 2301 Problem b(莫比乌斯函数)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2301 题意:每次给出a,b,c,d,K.求有多少数对(x,y)满足a<=x< ...

  6. OGG-00782 - OGG 11.2.1.0.2 FOR Windows x64 Microsoft SQL Server

    OS ENV:主机名:           WIN-NO42QRNPMFAOS 名称:          Microsoft Windows Server 2008 R2 Datacenter OS ...

  7. Android开发之ActivityManager获取系统信息

    1.判断指定的service是否在运行 public static boolean isServiceRunning(Context ctx, String serviceName) { Activi ...

  8. java中的线程创建和使用

    Java中实现多线程有两种途径:继承Thread类或者实现Runnable接口.Runnable是接口,建议用接口的方式生成线程,因为接口可以实现多继承,况且Runnable只有一个run方法,很适合 ...

  9. Android之ScaleGestureDetector(缩放手势检测)

    一.概述 ScaleGestureDetector这个类是专门用来检测两个手指在屏幕上做缩放的手势用的,最简单的应用就是用来缩放图片或者缩放网页. 二.要求 利用ScaleGestureDetecto ...

  10. 函数xdes_get_offset

    /********************************************************************//** Returns page offset of the ...