图片缩放:
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图片浏览器报告" Android图片浏览器是一种移动应用程序,旨在提供一个便捷的图片浏览体验。通过实现一个完整的软件,体验软件项目开发的工作流程,加深对相关理论知识的理解,提高实际分析设计能力。 在...
自己总结的关于Android上传图片到服务器的一个小demo
自己总结的一个关于Android上传图片到服务器的一个小demo
Android应用程序的资源文件包括布局文件、字符串资源、图片资源等。这些资源文件可以被应用程序引用和使用。 3.2 asset文件 asset文件是Android应用程序的资源文件,用于存储应用程序的数据和配置信息。 四、...
Android 三大图片缓存原理、特性对比
自己的工作上的一些总结,之后会不断更新的 现在这个是有关Opengl为啥有时候贴图不显示 和Android获得剩余内存的问题
android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....
Android ListView 控件显示数据库中...本文总结了 Android ListView 控件显示数据库中图片的过程,涉及到 SimpleAdapter、ViewBinder、数据库操作、ListView 控件的点击事件、图片的显示等知识点,希望对读者有所帮助。
在网上调查了图片压缩的方法并实装后,大致上可以认为有两类压缩:...android图片压缩总结 总 结来看,图片有三种存在形式:硬盘上时是file,网络传输时是stream,内存中是stream或bitmap,所谓的质量压缩,它其实只能
自己写的demo,总结一下关于拍照本地图片多选。实现文件夹按图片修改时间排序,点击查看大图
在android中,获取网络图片进行缓存是必须的,但是如果你的缓存策略不够好的话就会内存溢出,今天我总结一下我自己的看法,并做了demo。用到了线程池来控制线程,根据你手机的cpu的个数来确定你线程池中线程数的大小...
详情请移步:http://blog.csdn.net/alfred_c/article/details/50542741
popupWindow、对话框、元素切换场景动画、图片打点、RN与Android交互、美团界面实现
在具体实现代码之前,我们先来了解一下Android api对实现自定义Camera的介绍。 根据api的介绍,对于Camera应用可以简单总结以下几个步骤。 1.检查Camera是否存在,并在AndroidManifest.xml中赋予相关的权限; 2....
自己对android中图片与内存消耗的一点总结!
《Android应用开发》个人总结报告 刚开始接触Android感觉到它很有意思,在界面开发上和web也可以形成了相通的架构 ,更加方便,视觉上也是非常的酷,在前期我通过的大量的Android SDK开发范例大全中的例子以及...