seven365-zyprinter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +43 -0
- package/README.md +186 -0
- package/Seven365Zyprinter.podspec +27 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/mycompany/plugins/example/Example.java +342 -0
- package/android/src/main/java/com/mycompany/plugins/example/ExamplePlugin.java +161 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +229 -0
- package/dist/esm/definitions.d.ts +56 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +49 -0
- package/dist/esm/web.js +40 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +54 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +57 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Seven365Zyprinter.podspec +28 -0
- package/ios/Sources/Plugin/ZyprintPlugin.swift +161 -0
- package/ios/Sources/Plugin/ZywellSDK.swift +358 -0
- package/ios/Sources/Seven365Zyprinter-Umbrella.h +16 -0
- package/ios/Sources/module.modulemap +12 -0
- package/ios/Sources/sources/BLEManager.h +658 -0
- package/ios/Sources/sources/BLEManager.m +2842 -0
- package/ios/Sources/sources/GCD/Documentation.html +47 -0
- package/ios/Sources/sources/GCD/GCDAsyncSocket.h +1226 -0
- package/ios/Sources/sources/GCD/GCDAsyncSocket.m +8560 -0
- package/ios/Sources/sources/GCD/GCDAsyncUdpSocket.h +1036 -0
- package/ios/Sources/sources/GCD/GCDAsyncUdpSocket.m +5632 -0
- package/ios/Sources/sources/GCD/PrinterManager.h +91 -0
- package/ios/Sources/sources/GCD/PrinterManager.m +513 -0
- package/ios/Sources/sources/GCD/WifiManager.h +91 -0
- package/ios/Sources/sources/GCD/WifiManager.m +510 -0
- package/ios/Sources/sources/ImageTranster.h +38 -0
- package/ios/Sources/sources/ImageTranster.m +389 -0
- package/ios/Sources/sources/POSBLEManager.h +759 -0
- package/ios/Sources/sources/POSBLEManager.m +834 -0
- package/ios/Sources/sources/POSSDK.h +93 -0
- package/ios/Sources/sources/POSWIFIManager.h +116 -0
- package/ios/Sources/sources/POSWIFIManager.m +260 -0
- package/ios/Sources/sources/POSWIFIManagerAsync.h +745 -0
- package/ios/Sources/sources/POSWIFIManagerAsync.m +1847 -0
- package/ios/Sources/sources/PosCommand.h +633 -0
- package/ios/Sources/sources/PosCommand.m +1019 -0
- package/ios/Sources/sources/TscCommand.h +723 -0
- package/ios/Sources/sources/TscCommand.m +566 -0
- package/ios/Tests/ExamplePluginTests/ExamplePluginTests.swift +15 -0
- package/package.json +339 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ImageTranster.m
|
|
3
|
+
// Printer
|
|
4
|
+
//
|
|
5
|
+
// Created by LeeLee on 16/7/19.
|
|
6
|
+
// Copyright © 2016年 Admin. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "ImageTranster.h"
|
|
10
|
+
|
|
11
|
+
@implementation ImageTranster
|
|
12
|
+
|
|
13
|
+
#define Mask8(x) ((x)&0xFF)
|
|
14
|
+
#define A(x) (Mask8(x))
|
|
15
|
+
#define B(x) (Mask8(x>>8))
|
|
16
|
+
#define G(x) (Mask8(x>>16))
|
|
17
|
+
#define R(x) (Mask8(x>>24))
|
|
18
|
+
#define RGBAMake(r,g,b,a) (Mask8(a)|Mask8(b)<<8|Mask8(g)<<16|Mask8(r)<<24)
|
|
19
|
+
+(UIImage *)covertToGrayScale:(UIImage*)image{
|
|
20
|
+
CGImageRef cgimage=[image CGImage];
|
|
21
|
+
size_t width=CGImageGetWidth(cgimage);
|
|
22
|
+
size_t height=CGImageGetHeight(cgimage);
|
|
23
|
+
|
|
24
|
+
//像素将画在这个数组
|
|
25
|
+
uint32_t *pixels = (uint32_t *)malloc(width *height *sizeof(uint32_t));
|
|
26
|
+
//清空像素数组
|
|
27
|
+
memset(pixels, 0, width*height*sizeof(uint32_t));
|
|
28
|
+
|
|
29
|
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
30
|
+
|
|
31
|
+
//用 pixels 创建一个 context
|
|
32
|
+
CGContextRef context =CGBitmapContextCreate(pixels, width, height, 8, width*sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
|
|
33
|
+
CGContextDrawImage(context, CGRectMake(0, 0, width, height),cgimage);
|
|
34
|
+
|
|
35
|
+
int tt =1;
|
|
36
|
+
CGFloat intensity;
|
|
37
|
+
int bw;
|
|
38
|
+
|
|
39
|
+
for (int y = 0; y <height; y++) {
|
|
40
|
+
for (int x =0; x <width; x ++) {
|
|
41
|
+
uint8_t *rgbaPixel = (uint8_t *)&pixels[y*width+x];
|
|
42
|
+
intensity = (rgbaPixel[tt] + rgbaPixel[tt + 1] + rgbaPixel[tt + 2]) / 3. / 255.;
|
|
43
|
+
|
|
44
|
+
bw = intensity > 0.45?255:0;
|
|
45
|
+
|
|
46
|
+
rgbaPixel[tt] = bw;
|
|
47
|
+
rgbaPixel[tt + 1] = bw;
|
|
48
|
+
rgbaPixel[tt + 2] = bw;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// create a new CGImageRef from our context with the modified pixels
|
|
54
|
+
CGImageRef image2 = CGBitmapContextCreateImage(context);
|
|
55
|
+
|
|
56
|
+
// we're done with the context, color space, and pixels
|
|
57
|
+
CGContextRelease(context);
|
|
58
|
+
CGColorSpaceRelease(colorSpace);
|
|
59
|
+
free(pixels);
|
|
60
|
+
// make a new UIImage to return
|
|
61
|
+
UIImage *resultUIImage = [UIImage imageWithCGImage:image2];
|
|
62
|
+
// we're done with image now too
|
|
63
|
+
CGImageRelease(image2);
|
|
64
|
+
return resultUIImage;
|
|
65
|
+
}
|
|
66
|
+
+(NSData *)Imagedata:(UIImage *) mIamge andType:(BmpType) bmptype{
|
|
67
|
+
CGImageRef cgimage=[[ImageTranster covertToGrayScale:mIamge] CGImage];
|
|
68
|
+
size_t w=CGImageGetWidth(cgimage);
|
|
69
|
+
size_t h=CGImageGetHeight(cgimage);
|
|
70
|
+
UInt32 *pixels;
|
|
71
|
+
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
|
|
72
|
+
NSInteger bpp=4;//每个像素的字节
|
|
73
|
+
NSInteger bpc=8;//每个组成像素的位深
|
|
74
|
+
NSInteger bpr=w*bpp;//每行字节数
|
|
75
|
+
pixels=(UInt32 *)calloc(w*h,sizeof(UInt32));
|
|
76
|
+
CGContextRef context=CGBitmapContextCreate(pixels, w, h, bpc, bpr, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrder32Big);
|
|
77
|
+
CGContextDrawImage(context, CGRectMake(0, 0, w, h), cgimage);
|
|
78
|
+
//将像素数据封装成打印机能识别的数据
|
|
79
|
+
size_t n=(w+7)/8;
|
|
80
|
+
uint8_t *newPixels;
|
|
81
|
+
size_t m=0x01;
|
|
82
|
+
size_t rep=(h+23)/24;
|
|
83
|
+
newPixels=(uint8_t *)calloc(n*h, sizeof(uint8_t));
|
|
84
|
+
for (NSInteger y=0; y<h; y++) {
|
|
85
|
+
for (NSInteger x=0; x<n*8; x++) {
|
|
86
|
+
if (x<w) {
|
|
87
|
+
if ((pixels[y*w+x]&0xff0000)>> 16 != 0) {
|
|
88
|
+
newPixels[y*n+x/8]|=m<<(7-x%8);
|
|
89
|
+
}
|
|
90
|
+
}else if (x>=w){
|
|
91
|
+
newPixels[y*n+x/8]|=0<<(0-x%8);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
NSMutableData *dataM=[[NSMutableData alloc] init];
|
|
96
|
+
for (NSInteger i=0; i<rep; i++)
|
|
97
|
+
{
|
|
98
|
+
if (i==rep-1)
|
|
99
|
+
{
|
|
100
|
+
if (h%24==0)
|
|
101
|
+
{
|
|
102
|
+
Byte cpyByte[24*n];
|
|
103
|
+
memcpy(cpyByte, newPixels+(24*n*i), 24*n);
|
|
104
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
{
|
|
109
|
+
Byte cpyByte[(h%24)*n];
|
|
110
|
+
memcpy(cpyByte, newPixels+(24*n*i), (h%24)*n);
|
|
111
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
{
|
|
116
|
+
Byte cpyByte[24*n];
|
|
117
|
+
memcpy(cpyByte, newPixels+(24*n*i), 24*n);
|
|
118
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//释放图片
|
|
122
|
+
CGContextRelease(context);
|
|
123
|
+
CGColorSpaceRelease(colorSpace);
|
|
124
|
+
//释放内存
|
|
125
|
+
free(pixels);
|
|
126
|
+
free(newPixels);
|
|
127
|
+
return dataM;
|
|
128
|
+
}
|
|
129
|
+
+(NSData *)rasterImagedata:(UIImage *) mIamge andType:(BmpType) bmptype andPrintRasterType:(PrintRasterType) type{
|
|
130
|
+
//NSMutableData *dataM=[[NSMutableData alloc] init];
|
|
131
|
+
// mIamge=[self imageCompressForWidthScale:mIamge targetWidth:576];
|
|
132
|
+
//得到UIImage,获取图片像素,并转换为UInt32类型数据
|
|
133
|
+
//int pixels[w*h];
|
|
134
|
+
UInt32 aveGray;
|
|
135
|
+
UInt32 sumGray=0;
|
|
136
|
+
CGImageRef cgimage=[mIamge CGImage];
|
|
137
|
+
size_t w=CGImageGetWidth(cgimage);
|
|
138
|
+
size_t h=CGImageGetHeight(cgimage);
|
|
139
|
+
UInt32 *pixels;
|
|
140
|
+
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
|
|
141
|
+
|
|
142
|
+
NSInteger bpp=4;//每个像素的字节
|
|
143
|
+
NSInteger bpc=8;//每个组成像素的位深
|
|
144
|
+
NSInteger bpr=w*bpp;//每行字节数
|
|
145
|
+
|
|
146
|
+
pixels=(UInt32 *)calloc(w*h,sizeof(UInt32));
|
|
147
|
+
|
|
148
|
+
CGContextRef context=CGBitmapContextCreate(pixels, w, h, bpc, bpr, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrder32Big);
|
|
149
|
+
CGContextDrawImage(context, CGRectMake(0, 0, w, h), cgimage);
|
|
150
|
+
//操作像素
|
|
151
|
+
UInt8 *gradPixels;
|
|
152
|
+
gradPixels=(UInt8 *)calloc(w*h, sizeof(UInt8));
|
|
153
|
+
//1.灰度处理
|
|
154
|
+
for (NSInteger j=0; j<h; j++) {
|
|
155
|
+
for (NSInteger i=0; i<w; i++) {
|
|
156
|
+
UInt32 currentPixel=pixels[(w*j)+i];
|
|
157
|
+
UInt32 color=currentPixel;
|
|
158
|
+
//灰度化当前像素点
|
|
159
|
+
UInt32 grayColor=//(R(color)+G(color)+B(color))/3;
|
|
160
|
+
(R(color)*299+G(color)*587+B(color)*114+500)/1000;
|
|
161
|
+
gradPixels[w*j+i]=grayColor;
|
|
162
|
+
sumGray+=grayColor;
|
|
163
|
+
// NSLog(@"%i",grayColor);
|
|
164
|
+
pixels[w*j+i]=RGBAMake(grayColor, grayColor, grayColor, A(color));
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//2.黑白处理(二值法,抖动算法)
|
|
169
|
+
//int e=0;
|
|
170
|
+
//NSInteger g;
|
|
171
|
+
//uint8_t *grayPixels;
|
|
172
|
+
//int g;
|
|
173
|
+
switch (bmptype) {
|
|
174
|
+
case Dithering:
|
|
175
|
+
|
|
176
|
+
//二值法处理
|
|
177
|
+
aveGray=sumGray/(w*h);
|
|
178
|
+
aveGray=150;//调整打印浓度、粗细
|
|
179
|
+
for (NSInteger j=0; j<h; j++) {
|
|
180
|
+
for (NSInteger i=0; i<w; i++) {
|
|
181
|
+
UInt32 currentPixel=pixels[(w*j)+i];
|
|
182
|
+
UInt32 color=currentPixel;
|
|
183
|
+
if (R(color)<aveGray) {
|
|
184
|
+
pixels[w*j+i]=RGBAMake(0, 0, 0, A(color));
|
|
185
|
+
}else{
|
|
186
|
+
pixels[w*j+i]=RGBAMake(0xff, 0xff, 0xff, A(color));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
break;
|
|
193
|
+
case Threshold:
|
|
194
|
+
//抖动算法
|
|
195
|
+
for (NSInteger j=0; j<h; j++) {
|
|
196
|
+
for (NSInteger i=0; i<w; i++) {
|
|
197
|
+
//UInt32 currentPixel=pixels[(w*j)+i];
|
|
198
|
+
//UInt32 color=*currentPixel;
|
|
199
|
+
NSInteger e=0;
|
|
200
|
+
NSInteger g=gradPixels[w*j+i];
|
|
201
|
+
if (g>=150) {
|
|
202
|
+
pixels[w*j+i]=RGBAMake(0xff, 0xff, 0xff, 0xff);
|
|
203
|
+
e=g-255;
|
|
204
|
+
}else{
|
|
205
|
+
pixels[w*j+i]=RGBAMake(0x00 , 0x00, 0x00, 0xff);
|
|
206
|
+
e=g-0;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (i<w-1&&j<h-1) {//不靠右边和下边的像素
|
|
210
|
+
//右边像素处理
|
|
211
|
+
// UInt8 leftPixel1=gradPixels[(w*j)+i+1];
|
|
212
|
+
// int lred1=Mask8(leftPixel1);
|
|
213
|
+
// lred1+=3*e/8;
|
|
214
|
+
// leftPixel1=lred1;
|
|
215
|
+
gradPixels[(w*j)+i+1]+=3*e/8;
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
//下边像素处理
|
|
219
|
+
// UInt8 lowPixel1=gradPixels[(w*j)+i+w];
|
|
220
|
+
//
|
|
221
|
+
// int lowred1=Mask8(lowPixel1);
|
|
222
|
+
// lowPixel1+=3*e/8;
|
|
223
|
+
// lowPixel1=lowred1;
|
|
224
|
+
gradPixels[(w*(j+1))+i]+=3*e/8;
|
|
225
|
+
//右下方像素处理
|
|
226
|
+
// UInt8 leftlowPixel1=gradPixels[(w*j)+i+w+1];
|
|
227
|
+
// int llred1=Mask8(leftlowPixel1);
|
|
228
|
+
// llred1+=e/4;
|
|
229
|
+
// leftlowPixel1=llred1;
|
|
230
|
+
gradPixels[w*(j+1)+i+1]+=e/4;
|
|
231
|
+
|
|
232
|
+
}else if (i==w-1&&j<h-1){//靠右边界的像素
|
|
233
|
+
//下边像素处理
|
|
234
|
+
// UInt8 lowPixel1=gradPixels[(w*j)+i+w];
|
|
235
|
+
//
|
|
236
|
+
// int lowred1=Mask8(lowPixel1);
|
|
237
|
+
// lowred1+=3*e/8;
|
|
238
|
+
// lowPixel1=lowred1;
|
|
239
|
+
gradPixels[(w*(j+1))+i]+=3*e/8;
|
|
240
|
+
|
|
241
|
+
}else if (i<w-1&&j==h-1){//靠底部的像素
|
|
242
|
+
|
|
243
|
+
//右边像素处理
|
|
244
|
+
// UInt8 leftPixel1=gradPixels[(w*j)+i+1];
|
|
245
|
+
// int lred1=Mask8(leftPixel1);
|
|
246
|
+
// lred1+=3*e/8;
|
|
247
|
+
// leftPixel1=lred1;
|
|
248
|
+
gradPixels[(w*j)+i+1]+=e/4;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//将像素数据封装成打印机能识别的数据
|
|
259
|
+
size_t n=(w+7)/8;
|
|
260
|
+
uint8_t *newPixels;
|
|
261
|
+
size_t m=0x01;
|
|
262
|
+
Byte xL=n%256;
|
|
263
|
+
Byte xH=n/256;
|
|
264
|
+
size_t rep=(h+23)/24;
|
|
265
|
+
newPixels=(uint8_t *)calloc(n*h, sizeof(uint8_t));
|
|
266
|
+
for (NSInteger y=0; y<h; y++) {
|
|
267
|
+
for (NSInteger x=0; x<n*8; x++) {
|
|
268
|
+
if (x<w) {
|
|
269
|
+
if (R(pixels[y*w+x])==0) {
|
|
270
|
+
newPixels[y*n+x/8]|=(m<<(7-x%8));
|
|
271
|
+
}
|
|
272
|
+
}else if (x>=w){
|
|
273
|
+
newPixels[y*n+x/8]|=(0<<(7-x%8));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
NSMutableData *dataM=[[NSMutableData alloc] init];
|
|
278
|
+
//将像素数据封装成光栅位图格式
|
|
279
|
+
Byte head[8]={0x1D,0x76,0x30,type,xL,xH,0x18,0x00};
|
|
280
|
+
|
|
281
|
+
for (NSInteger i=0; i<rep; i++)
|
|
282
|
+
{
|
|
283
|
+
if (i==rep-1)
|
|
284
|
+
{
|
|
285
|
+
if (h%24==0)
|
|
286
|
+
{
|
|
287
|
+
head[6]=0x18;
|
|
288
|
+
[dataM appendBytes:&head length:sizeof(head)];
|
|
289
|
+
Byte cpyByte[24*n];
|
|
290
|
+
memcpy(cpyByte, newPixels+(24*n*i), 24*n);
|
|
291
|
+
|
|
292
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
else
|
|
296
|
+
{
|
|
297
|
+
|
|
298
|
+
head[6]=h%24;
|
|
299
|
+
[dataM appendBytes:&head length:sizeof(head)];
|
|
300
|
+
Byte cpyByte[(h%24)*n];
|
|
301
|
+
memcpy(cpyByte, newPixels+(24*n*i), (h%24)*n);
|
|
302
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
else
|
|
308
|
+
{
|
|
309
|
+
head[6]=0x18;
|
|
310
|
+
[dataM appendBytes:&head length:sizeof(head)];
|
|
311
|
+
Byte cpyByte[24*n];
|
|
312
|
+
memcpy(cpyByte, newPixels+(24*n*i), 24*n);
|
|
313
|
+
[dataM appendBytes:&cpyByte length:sizeof(cpyByte)];
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//释放图片
|
|
319
|
+
CGContextRelease(context);
|
|
320
|
+
CGColorSpaceRelease(colorSpace);
|
|
321
|
+
//释放内存
|
|
322
|
+
free(pixels);
|
|
323
|
+
free(gradPixels);
|
|
324
|
+
free(newPixels);
|
|
325
|
+
|
|
326
|
+
//3.通过处理后的像素来重新得到新的图片
|
|
327
|
+
|
|
328
|
+
//直接返回像素数据会跟合适
|
|
329
|
+
return dataM;
|
|
330
|
+
}
|
|
331
|
+
//指定宽度按比例缩放,缩放有些时候只对宽度进行了缩放
|
|
332
|
+
+(UIImage *) imageCompressForWidthScale:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth{
|
|
333
|
+
|
|
334
|
+
UIImage *newImage = nil;
|
|
335
|
+
CGSize imageSize = sourceImage.size;
|
|
336
|
+
CGFloat width = imageSize.width;
|
|
337
|
+
CGFloat height = imageSize.height;
|
|
338
|
+
CGFloat targetWidth = defineWidth;
|
|
339
|
+
CGFloat targetHeight = height / (width / targetWidth);
|
|
340
|
+
CGSize size = CGSizeMake(targetWidth, targetHeight);
|
|
341
|
+
CGFloat scaleFactor = 0.0;
|
|
342
|
+
CGFloat scaledWidth = targetWidth;
|
|
343
|
+
CGFloat scaledHeight = targetHeight;
|
|
344
|
+
CGPoint thumbnailPoint = CGPointMake(0.0, 0.0);
|
|
345
|
+
|
|
346
|
+
if(CGSizeEqualToSize(imageSize, size) == NO){
|
|
347
|
+
|
|
348
|
+
CGFloat widthFactor = targetWidth / width;
|
|
349
|
+
CGFloat heightFactor = targetHeight / height;
|
|
350
|
+
|
|
351
|
+
if(widthFactor > heightFactor){
|
|
352
|
+
scaleFactor = widthFactor;
|
|
353
|
+
}
|
|
354
|
+
else{
|
|
355
|
+
scaleFactor = heightFactor;
|
|
356
|
+
}
|
|
357
|
+
scaledWidth = width * scaleFactor;
|
|
358
|
+
scaledHeight = height * scaleFactor;
|
|
359
|
+
|
|
360
|
+
if(widthFactor > heightFactor){
|
|
361
|
+
|
|
362
|
+
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
|
|
363
|
+
|
|
364
|
+
}else if(widthFactor < heightFactor){
|
|
365
|
+
|
|
366
|
+
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
UIGraphicsBeginImageContext(size);
|
|
371
|
+
|
|
372
|
+
CGRect thumbnailRect = CGRectZero;
|
|
373
|
+
thumbnailRect.origin = thumbnailPoint;
|
|
374
|
+
thumbnailRect.size.width = scaledWidth;
|
|
375
|
+
thumbnailRect.size.height = scaledHeight;
|
|
376
|
+
|
|
377
|
+
[sourceImage drawInRect:thumbnailRect];
|
|
378
|
+
|
|
379
|
+
newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
380
|
+
|
|
381
|
+
if(newImage == nil){
|
|
382
|
+
|
|
383
|
+
NSLog(@"scale image fail");
|
|
384
|
+
}
|
|
385
|
+
UIGraphicsEndImageContext();
|
|
386
|
+
return newImage;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
@end
|