- 浏览: 933065 次
- 性别:
- 来自: 山西
文章分类
最新评论
-
白小默:
你好 可以提供下源码DEMO吗,不知为何,我导出来的excel ...
jxls 使用模板文件导出生成excel -
zkzqzzz:
博主威武!
让微信二维码扫描您的APK -
zkzqzzz:
感谢博主 原来那些类都不是必须的 或者自己写!!博主真棒 ...
抢红包插件实现原理浅析 -
zkzqzzz:
博主 请问你的其他类在哪里呢?
抢红包插件实现原理浅析 -
zkzqzzz:
其他类在哪呢?
抢红包插件实现原理浅析
给图片加上圆角效果好看多了。
- public class ImageUtil {
- public static InputStream getRequest(String path) throws Exception {
- URL url = new URL(path);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setRequestMethod("GET");
- conn.setConnectTimeout(5000);
- if (conn.getResponseCode() == 200){
- return conn.getInputStream();
- }
- return null;
- }
- public static byte[] readInputStream(InputStream inStream) throws Exception {
- ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
- byte[] buffer = new byte[4096];
- int len = 0;
- while ((len = inStream.read(buffer)) != -1) {
- outSteam.write(buffer, 0, len);
- }
- outSteam.close();
- inStream.close();
- return outSteam.toByteArray();
- }
- public static Drawable loadImageFromUrl(String url){
- URL m;
- InputStream i = null;
- try {
- m = new URL(url);
- i = (InputStream) m.getContent();
- } catch (MalformedURLException e1) {
- e1.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- Drawable d = Drawable.createFromStream(i, "src");
- return d;
- }
- public static Drawable getDrawableFromUrl(String url) throws Exception{
- return Drawable.createFromStream(getRequest(url),null);
- }
- public static Bitmap getBitmapFromUrl(String url) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- return byteToBitmap(bytes);
- }
- public static Bitmap getRoundBitmapFromUrl(String url,int pixels) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- Bitmap bitmap = byteToBitmap(bytes);
- return toRoundCorner(bitmap, pixels);
- }
- public static Drawable geRoundDrawableFromUrl(String url,int pixels) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- BitmapDrawable bitmapDrawable = (BitmapDrawable)byteToDrawable(bytes);
- return toRoundCorner(bitmapDrawable, pixels);
- }
- public static byte[] getBytesFromUrl(String url) throws Exception{
- return readInputStream(getRequest(url));
- }
- public static Bitmap byteToBitmap(byte[] byteArray){
- if(byteArray.length!=0){
- return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
- }
- else {
- return null;
- }
- }
- public static Drawable byteToDrawable(byte[] byteArray){
- ByteArrayInputStream ins = new ByteArrayInputStream(byteArray);
- return Drawable.createFromStream(ins, null);
- }
- public static byte[] Bitmap2Bytes(Bitmap bm){
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
- return baos.toByteArray();
- }
- public static Bitmap drawableToBitmap(Drawable drawable) {
- Bitmap bitmap = Bitmap
- .createBitmap(
- drawable.getIntrinsicWidth(),
- drawable.getIntrinsicHeight(),
- drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
- : Bitmap.Config.RGB_565);
- Canvas canvas = new Canvas(bitmap);
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
- drawable.getIntrinsicHeight());
- drawable.draw(canvas);
- return bitmap;
- }
- /**
- * 图片去色,返回灰度图片
- * @param bmpOriginal 传入的图片
- * @return 去色后的图片
- */
- public static Bitmap toGrayscale(Bitmap bmpOriginal) {
- int width, height;
- height = bmpOriginal.getHeight();
- width = bmpOriginal.getWidth();
- Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
- Canvas c = new Canvas(bmpGrayscale);
- Paint paint = new Paint();
- ColorMatrix cm = new ColorMatrix();
- cm.setSaturation(0);
- ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
- paint.setColorFilter(f);
- c.drawBitmap(bmpOriginal, 0, 0, paint);
- return bmpGrayscale;
- }
- /**
- * 去色同时加圆角
- * @param bmpOriginal 原图
- * @param pixels 圆角弧度
- * @return 修改后的图片
- */
- public static Bitmap toGrayscale(Bitmap bmpOriginal, int pixels) {
- return toRoundCorner(toGrayscale(bmpOriginal), pixels);
- }
- /**
- * 把图片变成圆角
- * @param bitmap 需要修改的图片
- * @param pixels 圆角的弧度
- * @return 圆角图片
- */
- public static Bitmap toRoundCorner(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);
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
- canvas.drawBitmap(bitmap, rect, rect, paint);
- return output;
- }
- /**
- * 使圆角功能支持BitampDrawable
- * @param bitmapDrawable
- * @param pixels
- * @return
- */
- public static BitmapDrawable toRoundCorner(BitmapDrawable bitmapDrawable, int pixels) {
- Bitmap bitmap = bitmapDrawable.getBitmap();
- bitmapDrawable = new BitmapDrawable(toRoundCorner(bitmap, pixels));
- return bitmapDrawable;
- }
- }
public class ImageUtil { public static InputStream getRequest(String path) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); if (conn.getResponseCode() == 200){ return conn.getInputStream(); } return null; } public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outSteam.write(buffer, 0, len); } outSteam.close(); inStream.close(); return outSteam.toByteArray(); } public static Drawable loadImageFromUrl(String url){ URL m; InputStream i = null; try { m = new URL(url); i = (InputStream) m.getContent(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Drawable d = Drawable.createFromStream(i, "src"); return d; } public static Drawable getDrawableFromUrl(String url) throws Exception{ return Drawable.createFromStream(getRequest(url),null); } public static Bitmap getBitmapFromUrl(String url) throws Exception{ byte[] bytes = getBytesFromUrl(url); return byteToBitmap(bytes); } public static Bitmap getRoundBitmapFromUrl(String url,int pixels) throws Exception{ byte[] bytes = getBytesFromUrl(url); Bitmap bitmap = byteToBitmap(bytes); return toRoundCorner(bitmap, pixels); } public static Drawable geRoundDrawableFromUrl(String url,int pixels) throws Exception{ byte[] bytes = getBytesFromUrl(url); BitmapDrawable bitmapDrawable = (BitmapDrawable)byteToDrawable(bytes); return toRoundCorner(bitmapDrawable, pixels); } public static byte[] getBytesFromUrl(String url) throws Exception{ return readInputStream(getRequest(url)); } public static Bitmap byteToBitmap(byte[] byteArray){ if(byteArray.length!=0){ return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); } else { return null; } } public static Drawable byteToDrawable(byte[] byteArray){ ByteArrayInputStream ins = new ByteArrayInputStream(byteArray); return Drawable.createFromStream(ins, null); } public static byte[] Bitmap2Bytes(Bitmap bm){ ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); return baos.toByteArray(); } public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; } /** * 图片去色,返回灰度图片 * @param bmpOriginal 传入的图片 * @return 去色后的图片 */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { int width, height; height = bmpOriginal.getHeight(); width = bmpOriginal.getWidth(); Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGrayscale); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; } /** * 去色同时加圆角 * @param bmpOriginal 原图 * @param pixels 圆角弧度 * @return 修改后的图片 */ public static Bitmap toGrayscale(Bitmap bmpOriginal, int pixels) { return toRoundCorner(toGrayscale(bmpOriginal), pixels); } /** * 把图片变成圆角 * @param bitmap 需要修改的图片 * @param pixels 圆角的弧度 * @return 圆角图片 */ public static Bitmap toRoundCorner(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); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } /** * 使圆角功能支持BitampDrawable * @param bitmapDrawable * @param pixels * @return */ public static BitmapDrawable toRoundCorner(BitmapDrawable bitmapDrawable, int pixels) { Bitmap bitmap = bitmapDrawable.getBitmap(); bitmapDrawable = new BitmapDrawable(toRoundCorner(bitmap, pixels)); return bitmapDrawable; } }
- public class TimeUtil {
- public static String converTime(long timestamp){
- long currentSeconds = System.currentTimeMillis()/1000;
- long timeGap = currentSeconds-timestamp;//与现在时间相差秒数
- String timeStr = null;
- if(timeGap>24*60*60){//1天以上
- timeStr = timeGap/(24*60*60)+"天前";
- }else if(timeGap>60*60){//1小时-24小时
- timeStr = timeGap/(60*60)+"小时前";
- }else if(timeGap>60){//1分钟-59分钟
- timeStr = timeGap/60+"分钟前";
- }else{//1秒钟-59秒钟
- timeStr = "刚刚";
- }
- return timeStr;
- }
- public static String getStandardTime(long timestamp){
- SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
- Date date = new Date(timestamp*1000);
- sdf.format(date);
- return sdf.format(date);
- }
- } http://helloandroid.iteye.com/blog/1136297
发表评论
-
Android客户端代码保护技术-完整性校验
2018-01-08 17:10 1248由于Android系统固有的缺陷、Android应用分发 ... -
android开发中手动v2签名实现方法
2018-01-08 10:31 998用v2签名前要进行v1签名或zipalign。 1. z ... -
webview支持LocalStorage本地存储
2017-03-31 10:30 1358//允许JavaScript执行 ... -
七步配置phonegap+cordova+ionic开发环境
2016-12-19 16:21 690本文讲的是Android混合 ... -
梆梆加固破解
2016-10-13 09:01 1500本文假设你已经使用过梆梆加固,手头至少有个一个通过梆梆加固后 ... -
android zxing 扫描二维码 横屏转竖屏
2016-09-14 15:41 0Zxing 竖屏切换 Android 在google上下 ... -
封装Volley使Volley的每个请求都自动保存和发送Cookie
2016-09-14 10:57 0思路很简单,每次请求获取到服务器返回的response就解 ... -
Android二维码ZXing扫描区域大小的调整,提高扫描速度
2016-09-14 10:48 2637Zxing本身默认的扫图区域最大只有 360*480 ... -
解决Android二维码扫描ZXing竖屏拉伸变长闪退扫描区域小等问题
2016-09-14 10:42 1222Android 基于google Zxing实现二维码、条形 ... -
Android平台下利用zxing实现二维码开发
2016-09-14 09:25 474现在走在大街小巷都能看到二维码,而且最近由于项目需要,所以研 ... -
Zxing扫描二维码
2016-09-14 09:24 652摘要 android Zxing扫描二维码 横竖屏 ... -
Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
2016-09-14 09:18 497转载请注明出处:http://blog.csdn.net/x ... -
React Native应用部署/热更新-CodePush最新集成总结
2016-08-02 11:06 563本文出自《React Native学习笔记》系列文章。 ... -
让微信二维码扫描您的APK
2016-07-27 11:26 1496二维码深入人心,很多App都在官网挂出了可以扫描下载apk的 ... -
Activity类的runOnUiThread方法
2016-07-22 10:40 763[javascript] view plain c ... -
Can't create handler inside thread that has not called Looper.prepare()
2016-07-22 10:24 625错误信息:在Android开发中,如果在一个Thread中启 ... -
Android编程之解决android-support-v4打包问题
2016-07-21 09:27 547如果工程引入了android-support-v4的jar类 ... -
Android 编程下的代码混淆之(android-support-v4.jar)
2016-07-21 09:24 390项目在代码混淆过程中如果引用了第三方 Jar 包,需要在混淆 ... -
phoneGap可行性分析
2016-07-20 16:25 5091 移动应用现状 移动应用产品往往常 ... -
梆梆SDKs详细分析(1) - 防界面劫持SDK
2016-07-20 10:23 744前言 前段时间,国外知名的安全公司fireeye发 ...
相关推荐
腾讯人脸识别多版本接口文档,需要的下载,本文只负责转摘,不做商业用途,需要的可以下载,里面涵盖腾讯人脸的多个文档,这个是我之前做的腾讯人脸项目所用到的,腾讯官方只给到在线版的,我就自己弄了个PDF
android 布局参数中文注释说明 两张图片截图,仅对linerlayout 及RelativeLayout参数说明! 网络转摘!仅供学习!
Eclipse中用SWT和JFace开发入门-转摘 .doc
有很多的朋友给自己硬盘新建分区都喜欢用第三方软件,我想原因是在XP系统下只能在安装系统时才能进行分区,一旦系统做好之后要想新建分区就必须...本文转摘自『蓝派网』http://www.lan27.com/Article/201101/10965.htm
公司控制权之争及公司股权设计模式转摘.doc
新零售时代,小卖家如何迅速做出销量(转摘).zip
完全平方公式变形的应用练习题_2(转摘).doc
新零售时代,小卖家如何迅速做出销量(转摘).doc
新零售时代,小卖家如何迅速做出销量(转摘)-知识杂货店.doc
一、开发环境:pb11.2 8669 二、pb的webservice程序必须置于英文目录下,含中文路径时部署会出错; 三、代码只要改一个地方: n_webservice对象的of_retrieve函数中 sqlca.logpass设置为你测试数据库的sa对应密码即可 四...
华为从事通信网络技术与产品的研究、开发、生产与销售,是中国电信市场的主要供应商之一,并已成功进入全球电信市场。每年华为都要在各大高校招聘大批的应界生,特别是华中科技大学。 下面据说是华为公司的笔试题...
移动端开发(转摘jtyjty99999/mobileTech) ECMA-262,第 5 版 外链(即ES5) ECMAScript5.1中文版 外链(很详细教程) 前端技能汇总 外链(朴灵git) 在线预览word文档 颜色互转 MIME 类型 常用算法 async和defer...
很多可能在转摘过程中失真或未经验证就被转摘,真正使用时却不行,也由此决定自己全方位试验一下,努力还是没有白费,虽然最终得出的结果是很简单的,但其过程对于一个新学AJAX的人来说,真是挺累。欢迎您在使用过程...
这个是我从网上找到的资料,现在共享给大家,希望能帮助到大家。
本站声明:此文章来源于网络,如果未署名,可能因为此文被转摘多次,原作者不详。本站转载时稍作整理。如果原作者认为侵权,请联系我。我将在第一时间按其要求做出处理,并消除影响。
保留区的颜色是指要将图片中的什么颜色输出为导线。BMP图象格式不需要为单色完全实现彩色转换! Bmp2Pcb使用说明: 1、选择需要转换的图片。 2、用CTRL+左键点图片上需要转出来的颜色这时可以看到颜色值已经添加到...
转摘:Microsoft Office Access(前名 Microsoft Access)是由微软发布的关联式数据库管理系统。它结合了 Microsoft Jet Database Engine 和 图形用户界面两项特点,是 Microsoft Office的成员之一。 Access能够...
除非特别声明,原文版权归作者所有,如有转摘请注明原作者以及译者(FPGA技术网)信息。本译文会不断更新,要获得本译文的最新版本请查看本文的在线版本SystemVerilog 3.1a 语言参考手册。 由于时间及译者水平所限,...
DataFactory 是一种快度的,易于产生测试数据的带有直觉用户接口的工具,它能建模复杂数据关系。在当今快速的开发环境中,应用程序的测试总是处于次要地位。DataFactory是一种强的的数据产生器,它允许开发人员和QA...
在不打开串口的情况下监视串口的数据,属于转摘