課程
/移動(dòng)開發(fā)
/Android
/Android攝像頭基礎(chǔ)
如果把水印加入圖片中到底怎么做 有誰貼一下這一塊的代碼 謝謝
2015-11-22
源自:Android攝像頭基礎(chǔ) 4-1
正在回答
private?class?PhotoTask?extends?Thread ????{ ????????private?String?file; ????????private?boolean?isFinished; ????????public?PhotoTask(String?file) ????????{ ????????????this.file?=?file; ????????} ???????? ????????@Override ????????public?void?run() ????????{ ????????????BufferedOutputStream?bos?=?null; ????????????Bitmap?icon?=?null; ????????????try ????????????{ ????????????????BitmapFactory.Options?options?=?new?BitmapFactory.Options(); ????????????????options.inJustDecodeBounds?=?true; ????????????????BitmapFactory.decodeFile(file,?options);?//此時(shí)返回bm為空 ????????????????float?percent?= ????????????????????options.outHeight?>?options.outWidth???options.outHeight?/?960f?:?options.outWidth?/?960f; ???????????????? ????????????????if?(percent?<?1) ????????????????{ ????????????????????percent?=?1; ????????????????} ????????????????int?width?=?(int)(options.outWidth?/?percent); ????????????????int?height?=?(int)(options.outHeight?/?percent); ????????????????icon?=?Bitmap.createBitmap(width,?height,?Bitmap.Config.RGB_565); ???????????????? ????????????????//初始化畫布?繪制的圖像到icon上?? ????????????????Canvas?canvas?=?new?Canvas(icon); ????????????????//建立畫筆?? ????????????????Paint?photoPaint?=?new?Paint(); ????????????????//獲取跟清晰的圖像采樣?? ????????????????photoPaint.setDither(true); ????????????????//過濾一些?? ????????????????//????????????????????photoPaint.setFilterBitmap(true); ????????????????options.inJustDecodeBounds?=?false; ???????????????? ????????????????Bitmap?prePhoto?=?BitmapFactory.decodeFile(file); ????????????????if?(percent?>?1) ????????????????{ ????????????????????prePhoto?=?Bitmap.createScaledBitmap(prePhoto,?width,?height,?true); ????????????????} ???????????????? ????????????????canvas.drawBitmap(prePhoto,?0,?0,?photoPaint); ???????????????? ????????????????if?(prePhoto?!=?null?&&?!prePhoto.isRecycled()) ????????????????{ ????????????????????prePhoto.recycle(); ????????????????????prePhoto?=?null; ????????????????????System.gc(); ????????????????} ???????????????? ????????????????//設(shè)置畫筆?? ????????????????Paint?textPaint?=?new?Paint(Paint.ANTI_ALIAS_FLAG?|?Paint.DEV_KERN_TEXT_FLAG); ????????????????//字體大小?? ????????????????textPaint.setTextSize(20.0f); ????????????????//采用默認(rèn)的寬度?? ????????????????textPaint.setTypeface(Typeface.DEFAULT); ????????????????//采用的顏色?? ????????????????textPaint.setColor(Color.YELLOW); ????????????????//陰影設(shè)置?? ????????????????//????????????????textPaint.setShadowLayer(3f,?1,?1,?Color.DKGRAY);?? ???????????????? ????????????????//?時(shí)間水印?? ????????????????String?mark?=?getCurrTime("yyyy-MM-dd?HH:mm:ss"); ????????????????float?textWidth?=?textPaint.measureText(mark); ????????????????canvas.drawText(mark,?width?-?textWidth?-?10,?height?-?26,?textPaint); ???????????????? ????????????????bos?=?new?BufferedOutputStream(new?FileOutputStream(file)); ???????????????? ????????????????int?quaility?=?(int)(100?/?percent?>?80???80?:?100?/?percent); ????????????????icon.compress(CompressFormat.JPEG,?quaility,?bos); ????????????????bos.flush(); ????????????} ????????????catch?(Exception?e) ????????????{ ????????????????e.printStackTrace(); ????????????} ????????????finally ????????????{ ????????????????isFinished?=?true; ????????????????if?(bos?!=?null) ????????????????{ ????????????????????try ????????????????????{ ????????????????????????bos.close(); ????????????????????} ????????????????????catch?(IOException?e) ????????????????????{ ????????????????????????e.printStackTrace(); ????????????????????} ????????????????} ????????????????if?(icon?!=?null?&&?!icon.isRecycled()) ????????????????{ ????????????????????icon.recycle(); ????????????????????icon?=?null; ????????????????????System.gc(); ????????????????} ????????????} ????????} ????}
這個(gè)貌似網(wǎng)上一堆啊 ?隨便拿個(gè)來就可以用啊
舉報(bào)
帶你走進(jìn)Android攝像頭的秘密花園,探索Camera的奧秘
1 回答怎么我的圖片水印沒出來 只在surfaceview里面看到水印
1 回答實(shí)時(shí)對(duì)預(yù)覽圖片處理
1 回答圖片處理的課程在哪里呀
1 回答水印沒效果
2 回答你們有水印效果嗎
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-06-27
2015-12-21
這個(gè)貌似網(wǎng)上一堆啊 ?隨便拿個(gè)來就可以用啊