为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

图片处理时边框的处理以及翻转

2018-07-15 6页 doc 19KB 7阅读

用户头像

is_511210

暂无简介

举报
图片处理时边框的处理以及翻转图片处理时边框的处理以及翻转 图片处理时,有时需要为图片加一些边框,下面介绍一种为图片添加简单边框的方法。 /** , * 图片与边框组合 , * @param bm 原图片 , * @param res 边框资源 , * @return , */ , private Bitmap combinateFrame(Bitmap bm, int[] res) , { , Bitmap bmp = decodeBitmap(res[0]); ? // 边框的宽高 ,, final int smallW = bmp....
图片处理时边框的处理以及翻转
图片处理时边框的处理以及翻转 图片处理时,有时需要为图片加一些边框,下面介绍一种为图片添加简单边框的方法。 /** , * 图片与边框组合 , * @param bm 原图片 , * @param res 边框资源 , * @return , */ , private Bitmap combinateFrame(Bitmap bm, int[] res) , { , Bitmap bmp = decodeBitmap(res[0]); ? // 边框的宽高 ,, final int smallW = bmp.getWidth(); ,, final int smallH = bmp.getHeight(); ,, ,, // 原图片的宽高 ,, final int bigW = bm.getWidth(); ,, final int bigH = bm.getHeight(); ,, ,, int wCount = (int) Math.ceil(bigW * 1.0 / smallW); ,, int hCount = (int) Math.ceil(bigH * 1.0 / smallH); ,? ,, // 组合后图片的宽高 ,, int newW = (wCount + 2) * smallW; ,, int newH = (hCount + 2) * smallH; ,, ,, // 重新定义大小 ,, Bitmap newBitmap = Bitmap.createBitmap(newW, newH, Config.ARGB_8888); ,, Canvas canvas = new Canvas(newBitmap); ,, Paint p = new Paint(); ,, p.setColor(Color.TRANSPARENT); ,? canvas.drawRect(new Rect(0, 0, newW, newH), p); ,, ,, Rect rect = new Rect(smallW, smallH, newW - smallW, newH - smallH); ,, Paint paint = new Paint(); ,, paint.setColor(Color.WHITE); ,, canvas.drawRect(rect, paint); ,, ,, // 绘原图 ,, canvas.drawBitmap(bm, (newW - bigW - 2 * smallW) / 2 + smallW, (newH - bigH - 2 * smallH) / 2 + smallH, null); ,, // 绘边框 ,? // 绘四个角 ,, int startW = newW - smallW; ,, int startH = newH - smallH; ,, Bitmap leftTopBm = decodeBitmap(res[0]); // 左上角 ,, Bitmap leftBottomBm = decodeBitmap(res[2]); // 左下角 ,, Bitmap rightBottomBm = decodeBitmap(res[4]); // 右下角 ,, Bitmap rightTopBm = decodeBitmap(res[6]); // 右上角 ,, ,, canvas.drawBitmap(leftTopBm, 0, 0, null); ,, canvas.drawBitmap(leftBottomBm, 0, startH, null); ,? canvas.drawBitmap(rightBottomBm, startW, startH, null); ,, canvas.drawBitmap(rightTopBm, startW, 0, null); ,, ,, leftTopBm.recycle(); ,, leftTopBm = null; ,, leftBottomBm.recycle(); ,, leftBottomBm = null; ,, rightBottomBm.recycle(); ,, rightBottomBm = null; ,, rightTopBm.recycle(); ,? rightTopBm = null; ,, ,, // 绘左右边框 ,, Bitmap leftBm = decodeBitmap(res[1]); ,, Bitmap rightBm = decodeBitmap(res[5]); ,, for (int i = 0, length = hCount; i < length; i++) ,, { ,, int h = smallH * (i + 1); ,, canvas.drawBitmap(leftBm, 0, h, null); ,, canvas.drawBitmap(rightBm, startW, h, null); ,? } ,, ,, leftBm.recycle(); ,, leftBm = null; ,, rightBm.recycle(); ,, rightBm = null; ,, ,, // 绘上下边框 ,, Bitmap bottomBm = decodeBitmap(res[3]); ,, Bitmap topBm = decodeBitmap(res[7]); ,? for (int i = 0, length = wCount; i < length; i++) ,, { ,, int w = smallW * (i + 1); ,, canvas.drawBitmap(bottomBm, w, startH, null); ,, canvas.drawBitmap(topBm, w, 0, null); ,, } ,, ,, bottomBm.recycle(); ,, bottomBm = null; ,, topBm.recycle(); ,? topBm = null; ?, ?, canvas.save(Canvas.ALL_SAVE_FLAG); ?, canvas.restore(); ?, ?, return newBitmap; ?, } 图片旋转,缩放 , /** , * 截取图片的中间的200X200的区域 , * @param bm , * @return , */ , private Bitmap cropCenter(Bitmap bm) , { , int dstWidth = 200; ? int dstHeight = 200; ,, int startWidth = (bm.getWidth() - dstWidth)/2; ,, int startHeight = ((bm.getHeight() - dstHeight) / 2); ,, Rect src = new Rect(startWidth, startHeight, startWidth + dstWidth, startHeight + dstHeight); ,, return dividePart(bm, src); ,, } ,, ,, /** ,, * 剪切图片 ,, * @param bmp 被剪切的图片 ,? * @param src 剪切的位置 ,, * @return 剪切后的图片 ,, */ ,, private Bitmap dividePart(Bitmap bmp, Rect src) ,, { ,, int width = src.width(); ,, int height = src.height(); ,, Rect des = new Rect(0, 0, width, height); ,, Bitmap croppedImage = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); ,, Canvas canvas = new Canvas(croppedImage); ,? canvas.drawBitmap(bmp, src, des, null); ,, return croppedImage; ,, }
/
本文档为【图片处理时边框的处理以及翻转】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索