图片缩放:
public static Drawable resizeImage(Drawable d, int w, int h) {
// load the origial Bitmap
Bitmap BitmapOrg = ((BitmapDrawable) d).getBitmap();
int width = BitmapOrg.getWidth();
int height = BitmapOrg.getHeight();
int newWidth = w;
int newHeight = h;
// calculate the scale
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the Bitmap
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
height, matrix, true);
// make a Drawable from Bitmap to allow to set the Bitmap
// to the ImageView, ImageButton or what ever
return new BitmapDrawable(resizedBitmap);
}
public static Drawable resizeImage(Bitmap bitmap, int w, int h) {
// load the origial Bitmap
Bitmap BitmapOrg = bitmap;
int width = BitmapOrg.getWidth();
int height = BitmapOrg.getHeight();
int newWidth = w;
int newHeight = h;
// calculate the scale
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the Bitmap
matrix.postScale(scaleWidth, scaleHeight);
// if you want to rotate the Bitmap
// matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
height, matrix, true);
// make a Drawable from Bitmap to allow to set the Bitmap
// to the ImageView, ImageButton or what ever
return new BitmapDrawable(resizedBitmap);
}
图片写字:
/**
* 图片上画字
* */
private Bitmap drawTextAtBitmap(Bitmap bitmap,String text){
int x = bitmap.getWidth();
int y = bitmap.getHeight();
// 创建一个和原图同样大小的位图
Bitmap newbit = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newbit);
Paint paint = new Paint();
// 在原始位置0,0插入原图
canvas.drawBitmap(bitmap, 0, 0, paint);
paint.setColor(Color.parseColor("#dedbde"));
paint.setTextSize(20);
// 在原图指定位置写上字
canvas.drawText(text, 53 , 30, paint);
canvas.save(Canvas.ALL_SAVE_FLAG);
// 存储
canvas.restore();
return newbit;
}
分享到:
相关推荐
android图片处理总结,总结了一些关于安装的图片处理方法,欢迎借鉴
Android图片浏览器报告[参照].pdf
自己总结的关于Android上传图片到服务器的一个小demo
Android 三大图片缓存原理、特性对比
自己的工作上的一些总结,之后会不断更新的 现在这个是有关Opengl为啥有时候贴图不显示 和Android获得剩余内存的问题
android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....
自己写的demo,总结一下关于拍照本地图片多选。实现文件夹按图片修改时间排序,点击查看大图
在android中,获取网络图片进行缓存是必须的,但是如果你的缓存策略不够好的话就会内存溢出,今天我总结一下我自己的看法,并做了demo。用到了线程池来控制线程,根据你手机的cpu的个数来确定你线程池中线程数的大小...
自己总结的一个关于Android上传图片到服务器的一个小demo
详情请移步:http://blog.csdn.net/alfred_c/article/details/50542741
popupWindow、对话框、元素切换场景动画、图片打点、RN与Android交互、美团界面实现
在具体实现代码之前,我们先来了解一下Android api对实现自定义Camera的介绍。 根据api的介绍,对于Camera应用可以简单总结以下几个步骤。 1.检查Camera是否存在,并在AndroidManifest.xml中赋予相关的权限; 2....
自己对android中图片与内存消耗的一点总结!
在网上调查了图片压缩的方法并实装后,大致上可以认为有两类压缩:...android图片压缩总结 总 结来看,图片有三种存在形式:硬盘上时是file,网络传输时是stream,内存中是stream或bitmap,所谓的质量压缩,它其实只能
安卓android编译总结 安卓android开发从零开始代码若水 二维码生成图片 安卓中国象棋源码 安卓Android实用开发技巧集101.pdf 安卓Android_Eclipse开发教程.pdf 安卓Android_SDK与Eclipse最新版开发环境搭建.pdf 安卓...
NULL 博文链接:https://chenjinbo1983.iteye.com/blog/1326644
主要讲述了Android如何管理短信 彩信,如何写代码实现拦截彩信,获取彩信的附件图片等等