小编Oti*_*ium的帖子

UIImage的CGImage返回NULL

我创建了一个将图像分割成多个图像的函数,但是当我拿到UIImage的CGImage时,CGImage返回NULL

NSArray* splitImage(UIImage* image,NSUInteger pieces) {

NSLog(@"width: %f, %zu",image.size.width,CGImageGetWidth(image.CGImage));
NSLog(@"%@",image.CGImage);
returns NULL
NSMutableArray* tempArray = [[NSMutableArray alloc]initWithCapacity:pieces];

CGFloat piecesSize = image.size.height/pieces;

for (NSUInteger i = 0; i < pieces; i++) {

    // take in account retina displays
    CGRect subFrame = CGRectMake(0,i * piecesSize * image.scale ,image.size.width * image.scale,piecesSize * image.scale);

    CGImageRef newImage = CGImageCreateWithImageInRect(image.CGImage,subFrame);

    UIImage* finalImage =[UIImage imageWithCGImage:newImage];

    CGImageRelease(newImage);

    [tempArray addObject:finalImage];

}

NSArray* finalArray = [NSArray arrayWithArray:tempArray];

[tempArray release];

return finalArray;



}
Run Code Online (Sandbox Code Playgroud)

objective-c uiimage cgimage ios

7
推荐指数
2
解决办法
5561
查看次数

将Torrent info_hash从bencoded转换为URLEncoded数据

我在objective-c中创建了torrent scraper,我正在使用AFNetworking来处理HTTP请求.我需要发送跟踪器请求的元信息部分的sha1哈希值.我已成功创建哈希并验证它是否正确.我不能将哈希值放在NSString中,因为它不对二进制数据进行编码,因此我将它放在NSData对象中,然后在要发送的参数中.这就是我现在所拥有的,但我总是得到一个错误,我会假设它是使用我用来发送哈希的方法.我也尝试过编码哈希的url然后把它放在NSString中但没有用

 NSMutableDictionary *parameters = [NSMutableDictionary dictionary];

 unsigned char infoHash[20];
 [self.tracker generateTorrentInfoHash:infoHash];

 const char peer_id[20] = "randomstringfornow";

[parameters setObject:[NSData dataWithBytes:&infoHash length:20] forKey:@"info_hash"];    
[parameters setObject:[NSData dataWithBytes:&peer_id length:20] forKey:@"peer_id"];
[parameters setObject:@(8080) forKey:@"port"];
[parameters setObject:@(0) forKey:@"uploaded"];
[parameters setObject:@(self.tracker.metaInfo.totalFileSize) forKey:@"left"];
[parameters setObject:@(0) forKey:@"downloaded"];
[parameters setObject:@(0) forKey:@"compact"];
[parameters setObject:@"stopped" forKey:@"event"];


[self getPath:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"%@",operation.responseString);


   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@",operation.responseString);
}];
Run Code Online (Sandbox Code Playgroud)

有没有人知道AFNetworking是否有可能这样做,或者我希望错过一些简单的事情.

bittorrent http objective-c ios afnetworking

6
推荐指数
1
解决办法
1115
查看次数

标签 统计

ios ×2

objective-c ×2

afnetworking ×1

bittorrent ×1

cgimage ×1

http ×1

uiimage ×1