Android 圖片縮放,圖片圓角處理

來源:互聯網
上載者:User

/**<br /> *<br /> * [圖片縮放]<BR><br /> * [功能詳細描述]<br /> *<br /> * @param bitmapOrg<br /> * @param dstw<br /> * @param dsth<br /> * @return<br /> */<br /> public static Bitmap resizeImage(Bitmap bitmapOrg, int dstw, int dsth)<br /> {</p><p> Bitmap resizedBitmap;<br /> int srcw = bitmapOrg.getWidth();<br /> int srch = bitmapOrg.getHeight();</p><p> // 如果長寬小於產生的靶心圖表片,直接返回圖片<br /> if (srcw <= dstw && srch <= dsth)<br /> {</p><p> return bitmapOrg;<br /> }<br /> // else if (srcw > dstw && srch < dsth)<br /> // {<br /> //<br /> // resizedBitmap<br /> //<br /> //<br /> // }</p><p> float scaleWidth = ((float) dstw) / srcw;<br /> float scaleHeight = ((float) dsth) / srch;</p><p> // create a matrix for the manipulation<br /> Matrix matrix = new Matrix();<br /> // resize the Bitmap<br /> matrix.postScale(scaleWidth, scaleHeight);<br /> // if you want to rotate the Bitmap<br /> // matrix.postRotate(45);</p><p> // recreate the new Bitmap<br /> resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, srcw, srch,<br /> matrix, true);<br /> bitmapOrg.recycle();<br /> // make a Drawable from Bitmap to allow to set the Bitmap<br /> // to the ImageView, ImageButton or what ever<br /> return resizedBitmap;</p><p> }</p><p> /**<br /> *<br /> * [ 映像圓角處理]<BR><br /> * [功能詳細描述]<br /> *<br /> * @param bitmap<br /> * @param roundPX<br /> * @return<br /> */<br /> public static Bitmap getRCB(Bitmap bitmap, float roundPX) //RCB means Rounded Corner Bitmap<br /> {<br /> Bitmap dstbmp = Bitmap.createBitmap(bitmap.getWidth(),<br /> bitmap.getHeight(), Config.ARGB_8888);<br /> Canvas canvas = new Canvas(dstbmp);</p><p> final int color = 0xff424242;<br /> final Paint paint = new Paint();<br /> final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());<br /> final RectF rectF = new RectF(rect);<br /> paint.setAntiAlias(true);<br /> canvas.drawARGB(0, 0, 0, 0);<br /> paint.setColor(color);<br /> canvas.drawRoundRect(rectF, roundPX, roundPX, paint);<br /> paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));<br /> canvas.drawBitmap(bitmap, rect, rect, paint);</p><p> return dstbmp;<br /> }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.