相关疑难解决方法(0)

UIImage:调整大小,然后裁剪

我一直在this this for for for for for for and and and while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while while

我认为,在我的设计的概念阶段提前,从iPhone的相机或库中获取图像,将其缩小到指定高度,使用与Aspect Fill选项相当的功能将是一件小事. UIImageView(完全在代码中),然后裁掉任何不适合传递给CGRect的东西.

从相机或图书馆获取原始图像非常简单.我很惊讶其他两个步骤的难度.

附图显示了我想要实现的目标.有人请你好好握住我的手吗?到目前为止我发现的每个代码示例似乎都会破坏图像,颠倒过来,看起来像废话,画出界限,或者其他方法都不能正常工作.

iphone core-graphics image-processing ios

187
推荐指数
6
解决办法
12万
查看次数

如何在Swift中获取图像文件大小?

我在用

UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIPopoverControllerDelegate
Run Code Online (Sandbox Code Playgroud)

这些代表从我的画廊或我的相机中选择图像.那么,如何在选择图像后获得图像文件大小?

我想用这个:

let filePath = "your path here"
    var fileSize : UInt64 = 0

    do {
        let attr : NSDictionary? = try NSFileManager.defaultManager().attributesOfItemAtPath(filePath)

        if let _attr = attr {
            fileSize = _attr.fileSize();
            print(fileSize)
        }
    } catch {
    }
Run Code Online (Sandbox Code Playgroud)

但是在这里我需要一条路径,但是如果没有路径,我只能通过图像文件获得?

uiimageview uiimagepickercontroller ios swift

29
推荐指数
3
解决办法
4万
查看次数

iOS:使用自定义分辨率保存图像

嗨我尝试捕获视图然后将图像另存为照片库,但我需要为捕获的图像创建自定义分辨率,这是我的代码但是当应用程序保存图像时分辨率很低!

UIGraphicsBeginImageContextWithOptions(self.captureView.bounds.size, self.captureView.opaque, 0.0);

[self.captureView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();

CGRect cropRect = CGRectMake(0 ,0 ,1435 ,1435);
CGImageRef imageRef = CGImageCreateWithImageInRect([screenshot CGImage], cropRect);
CGImageRelease(imageRef);

UIImageWriteToSavedPhotosAlbum(screenshot , nil, nil, nil);

UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)

但iPhone的分辨率为:320 x 320,视网膜为:640 x 640

如果你能帮助我解决这个问题,我将不胜感激.

iphone xcode objective-c ipad ios

15
推荐指数
2
解决办法
2万
查看次数

如何为UIView制作基于图像的平铺背景,使其无法缩放?

在iOS应用程序中,我有250x85pt UIView.我希望它有基于图像的平铺背景.原始图像为398x398像素.我希望我的图像能够平铺.

在此输入图像描述

当我运行应用程序时,我的图像拼贴,但由于某种原因,它按如下方式缩放:

在此输入图像描述

我使用以下代码来实现它:

var image = UIImage(contentsOfFile: "myfilepath.png")!
var uicolor = UIColor(patternImage: image)
uiview.backgroundColor = uicolor
Run Code Online (Sandbox Code Playgroud)

你能解释一下:为什么ios会缩放我的图像,以及2.如何在不缩放的情况下绘制平铺图像?

uiimage ios swift

8
推荐指数
2
解决办法
5385
查看次数

在iphone中将相机/照片库图像文件大小减少到100 KB以下

我想减少从中获取的图像文件大小UIImagePickerController.我用这种方法

NSData*imageData = UIImageJPEGRepresentation(image,0.1);

但它将2.2 MB的图像文件大小减少到300 KB我希望我的图像文件大小小于100 KB.

iphone image uiimage ios image-size

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

UIImageJPEGRepresentation占用大量内存

我试图找出这个问题,但在做了我在OS或谷歌上发现的所有事情后失败了.问题是,当我转换UIImageNSData使用UIImageJPEGRepresentationUIImagePNGRepresentation它将内存大小增加到30Mb(相信我或不相信).
这是我的代码

myImage= image;
LoginSinglton*loginObj = [LoginSinglton sharedInstance];
NSError *error;
NSData *pngData = UIImageJPEGRepresentation(image, scaleValue); //scaleVale is 1.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory

self.imageCurrentDateAndTime =[self getTimeAndDate];
 self.filePathAndDirectory = [documentsPath stringByAppendingPathComponent:@"Photos Dir"];

NSLog(@"Documents path %@",self.filePathAndDirectory);
if (![[NSFileManager defaultManager] createDirectoryAtPath:self.filePathAndDirectory
                               withIntermediateDirectories:NO
                                                attributes:nil
                                                     error:&error])
{
    NSLog(@"Create directory error: %@", error);
}
self.imageName= [NSString stringWithFormat:@"photo-%@-%@.jpg",loginObj.userWebID,self.imageCurrentDateAndTime];
 NSString *filePath = [self.filePathAndDirectory stringByAppendingPathComponent:self.imageName];

[pngData writeToFile:filePath atomically:YES]; //Write the file …
Run Code Online (Sandbox Code Playgroud)

objective-c uiimage ios

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

区分两种景观模式

将Android设备旋转到横向模式时,它可以位于2个不同的位置,从设备的角度来看,底部按钮可以在左侧或右侧.有没有办法区分这两种模式?无论是通过onConfigurationChanged还是通过View.onSizeChanged我都得到了相同的结果(很明显),因为设备在横向上并且两种"模式"的分辨率相同(在我的情况下为800x480).

谢谢

android landscape

3
推荐指数
1
解决办法
321
查看次数

如何从UIImageView压缩图像?

我正在使用UIImageView*图像中的图像上传到服务器.我使用代码, NSData *imageToUpload = UIImageJPEGRepresentation(image.image, 90); 但我想压缩图像小于2MB.如何从UIImageView压缩图像?

ios ios5 ios6

3
推荐指数
1
解决办法
424
查看次数

从UIImagePickerController调整UIImage的大小

我目前正在使用此代码拍照

- (void) cameraButtonSelected
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)

我允许用户编辑照片,但是当我因某种原因使用此委托方法时,UIImagePickerController在用户按下"使用照片"后不会从视图中删除

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
Run Code Online (Sandbox Code Playgroud)

我想知道

  1. 如何在按下"使用照片"按钮后从视图中删除UIImagePickerController
  2. 我如何调整刚刚拍摄的照片的大小,因为我需要一个较小的变体发送到我的服务器

任何帮助,将不胜感激.

objective-c uiimagepickercontroller uiimage ios

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