相关文章推荐
千杯不醉的丝瓜  ·  兆豐證券美股投資任意門·  4 月前    · 
路过的茴香  ·  推荐10本“设计思维” 书籍·  2 年前    · 
文武双全的刺猬  ·  低代码是什么?什么是低代码开发?低代码有什么 ...·  2 年前    · 
潇洒的荒野  ·  20世纪中国女性文学史(Chinese ...·  2 年前    · 
彷徨的香菇  ·  Surface Hub 2S: Now a ...·  2 年前    · 
小百科  ›  Android处理图像数据全记录开发者社区
bitmap
旅途中的盒饭
2 年前
作者头像
技术小黑屋
0 篇文章

Android处理图像数据全记录

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 技术小黑屋 > Android处理图像数据全记录

Android处理图像数据全记录

作者头像
技术小黑屋
发布 于 2018-09-04 17:20:31
388 0
发布 于 2018-09-04 17:20:31
举报

Android中处理图像是一件很常见的事情,这里记录备忘一些亲身使用过的处理图片数据的方法。

转为Bitmap

RGB值转Bitmap

1 9

private Bitmap createColorBitmap(String rgb, int width, int height) { Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int color = Color.parseColor(rgb); bmp.eraseColor(color); return bmp; //Usage Bitmap bmp = createColorBitmap("#cce8cf", 200, 50);

Color值转Bitmap

1 7

private Bitmap createColorBitmap(int color, int width, int height) { Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bmp.eraseColor(color); return bmp; //Usage Bitmap bmp = createColorBitmap(Color.BLUE, 200, 50);

字节数组转Bitmap

1 3

private Bitmap getBitmapFromByteArray(byte[] array) { return BitmapFactory.decodeByteArray(array, 0, array.length); }

读取文件转Bitmap

1 3

private Bitmap getBitmapFromFile(String pathName) { return BitmapFactory.decodeFile(pathName); }

读取资源转Bitmap

1 3

private Bitmap getBitmapFromResource(Resources res, int resId) { return BitmapFactory.decodeResource(res, resId); }

输入流转Bitmap

1 3

private Bitmap getBitmapFromStream(InputStream inputStream) { return BitmapFactory.decodeStream(inputStream); }

Drawable转Bitmap

1

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);

转为Drawable

资源转Drawable

1

Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);

Bitmap转Drawable

1

Drawable d = new BitmapDrawable(getResources(),bitmap);

图片圆角展示

通过对图片数据bitmap进行处理即可,其中pixels为边角的半径。

1 21

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap .getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

 
推荐文章
千杯不醉的丝瓜  ·  兆豐證券美股投資任意門
4 月前
路过的茴香  ·  推荐10本“设计思维” 书籍
2 年前
文武双全的刺猬  ·  低代码是什么?什么是低代码开发?低代码有什么优势?-Zoho Creator
2 年前
潇洒的荒野  ·  20世纪中国女性文学史(Chinese Edition) eBook ... - Amazon.com
2 年前
彷徨的香菇  ·  Surface Hub 2S: Now a Microsoft Teams Rooms on Windows device
2 年前
Link管理   ·   Sov5搜索   ·   小百科
小百科 - 百科知识指南