android ImageUtils 图片处理工具类 收集平时用到的代码段
来源:互联网 发布:青少年心理问题数据 编辑:程序博客网 时间:2024/04/29 05:39
/**
* 添加文字到图片,类似水印文字。
* @param gContext
* @param gResId
* @param gText
* @return
*/
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) {
Resources resources = gContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
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);
// new antialised Paint
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// text color - #3D3D3D
paint.setColor(Color.rgb(61,61,61));
// text size in pixels
paint.setTextSize((int) (14 * scale*5));
// text shadow
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
// draw text to the Canvas center
Rect bounds = new Rect();
paint.getTextBounds(gText, 0, gText.length(), bounds);
// int x = (bitmap.getWidth() - bounds.width()) / 2;
// int y = (bitmap.getHeight() + bounds.height()) / 2;
//draw text to the bottom
int x = (bitmap.getWidth() - bounds.width())/10*9 ;
int y = (bitmap.getHeight() + bounds.height())/10*9;
canvas.drawText(gText, x , y, paint);
return bitmap;
}
* 添加文字到图片,类似水印文字。
* @param gContext
* @param gResId
* @param gText
* @return
*/
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) {
Resources resources = gContext.getResources();
float scale = resources.getDisplayMetrics().density;
Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);
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);
// new antialised Paint
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
// text color - #3D3D3D
paint.setColor(Color.rgb(61,61,61));
// text size in pixels
paint.setTextSize((int) (14 * scale*5));
// text shadow
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
// draw text to the Canvas center
Rect bounds = new Rect();
paint.getTextBounds(gText, 0, gText.length(), bounds);
// int x = (bitmap.getWidth() - bounds.width()) / 2;
// int y = (bitmap.getHeight() + bounds.height()) / 2;
//draw text to the bottom
int x = (bitmap.getWidth() - bounds.width())/10*9 ;
int y = (bitmap.getHeight() + bounds.height())/10*9;
canvas.drawText(gText, x , y, paint);
return bitmap;
}
0 0
- android ImageUtils 图片处理工具类 收集平时用到的代码段
- android ImageUtils 图片处理工具类
- Java的图片处理工具类ImageUtils
- ImageUtils-图片工具类
- Android手机拍照和手机相册选取图片的工具类ImageUtils
- 图片上传工具:ImageUtils
- ImageUtils.java:图片处理工具类[裁剪/图片水印/文字水印/缩放补白/Base64加密解密]
- Android开发工具类之FileUtils,ImageUtils
- android 图片处理代码收集
- Android ImageUtils 图片工具类,包括:小米从相册调图像空指针,三星旋转照片,压缩图片,保存Bitmap到本地,获取本地视频的缩略图,毛化玻璃效果,代码以后会更新
- 平时用到的开发工具快捷键
- 关于平时用到的工具总结
- ImageUtils工具类
- ImageUtils工具类,IamgeLoager
- android图片处理的工具代码
- Android 中图可以用到的图片处理类 BitmapUtils
- Android 中图可以用到的图片处理类 BitmapUtils
- 经常用到的代码段
- ASSERT(m_pCtrlSite != NULL);
- JVM中可生成的最大Thread数量
- 网站在架构时要考虑的事情
- UVA 10828 - Back to Kernighan-Ritchie(概率+高斯消元)
- 大范围的发的分公司的地方
- android ImageUtils 图片处理工具类 收集平时用到的代码段
- HDU 2000 ASCII码排序
- Tomcat的四种web应用部署方式详解
- 初探敏捷
- POJ2151 概率题
- Android中显示/隐藏软键盘的相关方法
- Android笔记之 文件保存、压缩与清空删除
- 坐标系
- 1430: 小猴打架 (prufer编码)