小编Mik*_*ein的帖子

在Django中将UploadedFile转换为PIL图像

在保存之前,我正在尝试检查图像的尺寸.我不需要改变它,只要确保它符合我的极限.

现在,我可以读取该文件,并将其保存到AWS而没有任何问题.

output['pic file'] = request.POST['picture_file']
conn = myproject.S3.AWSAuthConnection(aws_key_id, aws_key)
filedata = request.FILES['picture'].read()
content_type = 'image/png'
conn.put(
        bucket_name,
        request.POST['picture_file'],
        myproject.S3.S3Object(filedata),
        {'x-amz-acl': 'public-read', 'Content-Type': content_type},
        )
Run Code Online (Sandbox Code Playgroud)

我需要在中间放一步,以确保文件具有正确的尺寸/宽度尺寸.我的文件不是来自使用ImageField的表单,而且我见过的所有解决方案都使用它.

有没有办法做类似的事情

img = Image.open(filedata)
Run Code Online (Sandbox Code Playgroud)

python django python-imaging-library

5
推荐指数
1
解决办法
1976
查看次数

将CAGradient掩码层应用于UITextView

我有一个带可滚动文本的UITextView.我正在尝试对其应用渐变图层,因此可见文本的底部总是略微淡出.

这是我的代码:

CAGradientLayer *maskLayer = [CAGradientLayer layer];

maskLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor], (id)[[UIColor yellowColor] CGColor], nil];
maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
                       [NSNumber numberWithFloat:0.2],
                       [NSNumber numberWithFloat:0.8],
                       [NSNumber numberWithFloat:1.0], nil];
maskLayer.bounds = clueTextView.bounds;
myUITextView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)

现在,这导致UITextViewLayer完全透明 - 我看到UITextViewLayer作为子视图的UIView的背景颜色.虽然我可以选择并复制文本以粘贴到notes程序中,但我看不到其中包含的任何文本.

我缺少什么想法?

objective-c uitextview cagradientlayer

4
推荐指数
1
解决办法
4060
查看次数

'设置UINavigationController时,不能对类型:(null)'进行比较查询

我的应用程序崩溃在应用程序委托中.

它抛出的错误是:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法对类型执行比较查询:(null)'

我的代码如下.我已经离开了日志记录语句,所以你可以看到我在检查的地方:

self.viewController = [[ParseStarterProjectViewController alloc] initWithNibName:@"ParseStarterProjectViewController" bundle:nil];
NSLog(@"View controller is %@",self.viewController);
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
NSLog(@"Nav controller is %@",navController);
NSLog(@"Self window is %@",self.window);
self.window.rootViewController = navController;
Run Code Online (Sandbox Code Playgroud)

当它试图运行最后一行时,它会断开,将rootViewController设置为navController.

3条NSLog线的结果如下:

View controller is <ParseStarterProjectViewController: 0x1fda0770>
Nav controller is <UINavigationController: 0x1fda1390>
Self window is <UIWindow: 0x1fd97c90; frame = (0 0; 320 480); opaque = NO; autoresize = RM+BM; layer = <UIWindowLayer: 0x1fd97d90>>
Run Code Online (Sandbox Code Playgroud)

对我来说看起来没有任何东西是空的,这就是为什么我非常困惑.

objective-c uinavigationcontroller ios

4
推荐指数
1
解决办法
5871
查看次数