iOS 자체 워터마크 이미지
1. 배경 그림 UIImage 객체 만들기
UIImage *bgImage = [UIImage imageNamed:@"bgImage"];
2, 비트맵 컨텍스트 만들기
UIGraphicsBeginImageContextWithOptions(size,opaque,scale); 크기: 그림 크기 opaque: YES 불투명, NO 투명 scale: 그림을 생성하는 크기 가져오기: 2020 그림 크기 생성: (20scale20scale
3. 배경 그림을 그림에 추가하고drawInRect를 호출하는 방법:
4. 워터마크 이미지 객체를 만들고 drawInRect를 호출하는 방법: 이를 그림 상하문에 추가하는 방법
5, 비트맵 컨텍스트에서 작성된 새 이미지를 가져오고 컨트롤러의 이미지 뷰에 표시하며 비트맵 컨텍스트에서 작성된 새 이미지를 가져오는 방법 UIGraphicsGetImageFromCurrentImageContext()
6, 비트맵 편집 끝내기, UIGraphicsEndImageContext 호출()으로 편집 끝내기
7、합성된 그림을 저장
그림을 NSData로 변환하고 NSData의 write 방법을 호출합니다.그 중에서 UIImage를 NSData로 변환하는 방법은 두 가지가 있는데 그것이 바로 UIImagePNGrepresentation()과 UIImageJPEGrepresentation()이다.
부분 코드:
UIImage *bgImage = [UIImage imageNamed:@"bgImage"];
// UIImage , imageView
// ,
//size
//opaque alpha YES , NO
//scale :20*20 :(20*scale*20*scale)
UIGraphicsBeginImageContextWithOptions(bgImage.size, NO, 4);
[bgImage drawInRect:CGRectMake(0, 0, bgImage.size.width, bgImage.size.width)];
UIImage *waterImage = [UIImage imageNamed:@"header"];
[waterImage drawInRect:CGRectMake(bgImage.size.width - 60, bgImage.size.height - 60, 60, 60)];
//
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//
UIGraphicsEndImageContext();
self.imageView.image = newImage;
// Image png
// UIImage NSData ,NSData write
NSData *iamgeData = UIImagePNGRepresentation(newImage);
[iamgeData writeToFile:@"/Users/apple/Desktop/new.png" atomically:YES];
// jpg
//compressionQuality (0-1)
// 100KB * 0.7 = 70KB
NSData *imageData = UIImageJPEGRepresentation(newImage, 0.7);
[imageData writeToFile:@"/Users/apple/Desktop/new1.jpg" atomically:YES];
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.