UIImage新增水印(Logo 文字)

2021-07-26 02:49:07 字數 1761 閱讀 2589

新增水印是經常遇到的需求了,也算是影象數字處理比較容易的乙個環節,網上能搜出好幾種解決方案,但作為新手的我還是折騰了好長時間。

沒有什麼邏輯,就是把你所需要用到的素材全都渲染到contex中,最後再作為乙個整體取出來。

// 建立乙個bitmap的context

uigraphicsbeginimagecontext();

// 渲染背景圖

// 渲染素材logo+文字

// 用的是同乙個方法

drawinrect:

. . .

// 取出uiimage

uiimage *imagenew = uigraphicsgetimagefromcurrentimagecontext();

//一些釋放操作

uigraphicsendimagecontext();

由於是uiimage的一些處理,這種需求最合適寫進category裡面

- (uiimage *)imagewater1:(uiimage *)imagelogo waterstring:(nsstring *)waterstring

; [waterstring drawinrect:cgrectmake(targetghostwidth, 0, self

.size

.width*0.6, wordhigh) withattributes:dic];

[@"rno:0000023034001230" drawinrect:cgrectmake(targetghostwidth, wordhigh*1, self

.size

.width*0.6, wordhigh) withattributes:dic];

[@"gps:27.34223132,4533.2313324" drawinrect:cgrectmake(targetghostwidth, wordhigh*2, self

.size

.width*0.6, wordhigh) withattributes:dic];

.size

.width*0.6, wordhigh) withattributes:dic];

// uiimage

uiimage *imagenew = uigraphicsgetimagefromcurrentimagecontext();

uigraphicsendimagecontext();

return imagenew;

}

這樣寫是ok的,剛開始在渲染logo是這樣寫的

[imagelogo drawinrect:cgrectmake(0, 0, imagelogo.size.width, imagelogo.size.height)];

渲染出來的 特小,因為是點陣圖(bitmap)的關係吧,

要想用logo實際大小可以這樣

iOS 新增水印

新增水印,這個需求要求調研時,因為是新的技術點,查閱了一些資料。資料中統統都說 獲取介面的rgb值,將需要加密的資訊翻譯成二進位制,通過位運算,新增到每個rgb值的二進位制末尾實現。解碼時線取介面的rgb二進位制值,通過位運算,得出加密資訊的二進位制即可。網上給了一些獲得介面rgb的方法,我按照其方...

js新增水印

watermark 傳入動態水印內容 function watermark settings 採用配置項替換預設值,作用類似jquery.extend if arguments.length 1 typeof arguments 0 object for key in src var otemp d...

Java新增水印

description param sourceimgpath 源路徑 param tarimgpath 儲存的路徑 param watermarkcontent 水印內容 param fileext 格式 return void public static void addwatermark st...