圖片形狀圓角,形狀圓角
一定要先轉換成PNG格式的否則會不透明
1 /** 2 * 方形轉換圖片成圓形 3 * 4 * @param bitmap 5 * 傳入Bitmap對象 6 * @return 7 */ 8 public Bitmap toRoundBitmap(Bitmap bitmap) { 9 int width = bitmap.getWidth();10 int height = bitmap.getHeight();11 float roundPx;12 float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;13 if (width <= height) {14 roundPx = width / 2;15 left = 0;16 top = 0;17 right = width;18 bottom = width;19 height = width;20 dst_left = 0;21 dst_top = 0;22 dst_right = width;23 dst_bottom = width;24 } else {25 roundPx = height / 2;26 float clip = (width - height) / 2;27 left = clip;28 right = width - clip;29 top = 0;30 bottom = height;31 width = height;32 dst_left = 0;33 dst_top = 0;34 dst_right = height;35 dst_bottom = height;36 }37 38 Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);39 Canvas canvas = new Canvas(output);40 41 final int color = 0xff424242;42 final Paint paint = new Paint();43 final Rect src = new Rect((int) left, (int) top, (int) right,44 (int) bottom);45 final Rect dst = new Rect((int) dst_left, (int) dst_top,46 (int) dst_right, (int) dst_bottom);47 final RectF rectF = new RectF(dst);48 49 paint.setAntiAlias(true);// 設定畫筆無鋸齒50 51 canvas.drawARGB(0, 0, 0, 0); // 填充整個Canvas52 paint.setColor(color);53 54 // 以下有兩種方法畫圓,drawRounRect和drawCircle55 // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);//56 // 畫圓角矩形,第一個參數為圖形顯示地區,第二個參數和第三個參數分別是水平圓角半徑和垂直圓角半徑。57 canvas.drawCircle(roundPx, roundPx, roundPx, paint);58 59 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));// 設定兩張圖片相交時的模式,參考http://trylovecatch.iteye.com/blog/118945260 canvas.drawBitmap(bitmap, src, dst, paint); // 以Mode.SRC_IN模式合并bitmap和已經draw了的Circle61 62 return output;63 }
1 // 矩形將圖片的四角圓化 2 public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { 3 Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 4 bitmap.getHeight(), Config.ARGB_8888); 5 // 得到畫布 6 Canvas canvas = new Canvas(output); 7 // 將畫布的四角圓化 8 final int color = Color.RED; 9 final Paint paint = new Paint();10 // 得到與映像相同大小的地區 由構造的四個值決定地區的位置以及大小11 final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());12 final RectF rectF = new RectF(rect);13 // 值越大角度越明顯14 final float roundPx = 30;15 paint.setAntiAlias(true);16 canvas.drawARGB(0, 0, 0, 0);17 paint.setColor(color);18 // drawRoundRect的第2,3個參數一樣則畫的是正圓的一角,如果數值不同則是橢圓的一角19 canvas.drawRoundRect(rectF, roundPx, roundPx, paint);20 paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));21 canvas.drawBitmap(bitmap, rect, rect, paint);22 return output;23 }
怎PS圖片圓角的形狀
樓主的意思是圓角邊框嗎?
百度搜尋就有許多這一類的教程。
下面我簡單地介紹一下
1.雙擊右下角“圖層”視窗中的“背景圖”解鎖
2.工具列上右擊“矩形工具”選擇裡面的“圓角矩形工具(位於文字工具下方)”
3.“功能表列”下面“選項欄”中,設定工具的屬性。(將“圖案工具”改為“路徑”,“半徑”可以設定圓角的弧度,數值越大,角越圓)
4.圖中拖出想要的大小→ctrl+斷行符號“建立選區”→ctrl+shift+i 反選選區→按Del鍵 刪除選區
5.儲存為“PNG”格式即可
註:
1.圓角矩形工具是路徑工具而不是選區工具(LZ所使用的是選區工具)
2.圓角矩形工具中包括“矩形、圓角、橢圓、多邊形、直線,自訂”這六個形狀
PS怎將圖片的形狀改成圓角矩形?有圖
ps裡有個圓角矩形工具(快速鍵:U)
選中圓角矩形工具後,通過工具列上的半徑數值調整圓角角度大小
在圖上畫出圓角矩形路徑
Ctrl+Enter轉換成選區,Ctrl+Shift+I反選,Delete刪除邊角
儲存即可~
如果儲存為jpg格式,邊角被刪除的部分會變成白色。
儲存為png格式,被刪除的部分則會變透明~(但要記得把背景圖層一併刪除)
大概就是這樣,有什麼不明的地方,可以補充問題,我會儘力給你解答~