标签: uiimagejpegrepresentation

当用户捏住屏幕时如何放大/缩小UIImage对象?

当用户在我的应用程序上执行标准捏合操作时,我想放大/缩小UIImage对象.我正在使用UIImageView显示我的图像,如果该细节有任何帮助.

我正在试图弄清楚如何做到这一点,但到目前为止还没有这样的运气.

有线索吗?

cocoa-touch uiimage uiimagejpegrepresentation

82
推荐指数
7
解决办法
12万
查看次数

图像压缩大小 - iPhone SDK

我想压缩图像(相机/照片库),然后将其发送到服务器.我知道我可以按高度和宽度进行压缩,但我想将图像按尺寸压缩到固定尺寸(200 KB)并保持原始高度和宽度.JPEGRepresentation中的比例因子不代表大小和仅压缩质量.如何在不使用任何第三方库的情况下实现此目的(压缩到固定大小)?谢谢你的帮助.

iphone api uiimagejpegrepresentation ios

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

使用UIImageJPEGRepresentation时,compressQuality应该是什么?

我想对用户库中的照片应用过滤器,然后将其写回磁盘.我正在使用UIImageJPEGRepresentation.此函数采用a UIImagecompressionQuality0.0到1.0之间的值.因为我想保留原始质量,我将其设置为1.0.但我发现这实际上创建了一个文件大小比原始文件更大的图像文件,甚至更大.我注意到在Apple的Sample Photo Editing Extension应用程序中,他们总是将质量设置为0.9.我试过了,它输出的文件大小接近原始照片文件大小.这对我来说没有意义.有人可以解释一下吗?始终使用0.9是否合适?iOS相机是否使用该值压缩它,因此0.9是原始质量?或者为什么0.9实际上不是1.0,如果没有更好的质量?

NSData *renderedJPEGData = UIImageJPEGRepresentation(image, 0.9f);
Run Code Online (Sandbox Code Playgroud)

uiimage uiimagejpegrepresentation ios

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

使用ALAssetsLibrary和ALAsset取出Image作为NSData

我希望以NSData对象的形式直接使用ALAssetsLibrary和ALAsset提取图像.

使用NSURL我以下列方式取出图像.

NSURL *referenceURL =newURL;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:referenceURL resultBlock:^(ALAsset *asset)
{
     UIImage  *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
}
Run Code Online (Sandbox Code Playgroud)

现在我们将图像作为UIImage,但我需要将图像直接作为NSData.

我希望这样做是因为(我已经读过)一旦你在UIImage中拍摄图像,那么我们就会丢失图像的所有EXIF细节.

这就是我想直接将图像提取为NSData的原因,而不是这样做

NSData *webUploadData=UIImageJPEGRepresentation(copyOfOriginalImage, 0.5);
Run Code Online (Sandbox Code Playgroud)

这一步让我失去了所有的EXIF细节.

请帮忙.

iphone exif uiimage nsdata uiimagejpegrepresentation

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

iOS UIImageJPEGRepresentation错误:不是JPEG文件:以0xff 0xd9开头

我正在将.jpg文件写入我的应用程序的Documents目录,如下所示:

NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0);
BOOL retValue = [img writeToFile:myFilePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)

之后,我使用以下命令将该图像加载回UIImage:

UIImage *myImage = [UIImage imageWithContentsOfFile:path];
Run Code Online (Sandbox Code Playgroud)

我知道它有效,因为我可以在表格单元格中绘制图像,这很好.现在,如果我尝试使用UIImageJPEGRepresentation(myImage,1.0),调试器会打印出这些行:

<Error>: Not a JPEG file: starts with 0xff 0xd9
<Error>: Application transferred too few scanlines
Run Code Online (Sandbox Code Playgroud)

函数返回nil.有没有人知道为什么会这样?加载后我没有做任何事情来操纵UIImage数据.我刚刚将UIImage提供给单元格中的图像视图.我设置了图像视图属性,使得单元格中的所有图像对齐并且大小相同,但我认为这与将UIImage转换为NSData无关.

iphone uiimageview uiimage nsdata uiimagejpegrepresentation

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

如何使用UIImagePNGRepresentation压缩图像大小 - iOS?

我正在使用UIImagePNGRepresentation保存图像.结果图像的大小为30+ KB,在我的情况下这是大的.

我尝试使用UIImageJPEGRepresentation它,它允许压缩图像,所以图像保存在<5KB大小,这是伟大的,但保存为JPEG给它白色背景,我不想要(我的图像是圆形的,所以我需要保存它透明背景).

如何压缩图像大小UIImagePNGRepresentation

objective-c uiimage uiimagejpegrepresentation ios uiimagepngrepresentation

10
推荐指数
1
解决办法
6233
查看次数

来自CIImage的PNG/JPEG表示始终返回nil

我目前正在制作照片编辑应用.

当用户选择照片时,使用以下代码将其自动转换为黑白照片:

func blackWhiteImage(image: UIImage) -> Data {
    print("Starting black & white")

    let orgImg = CIImage(image: image)
    let bnwImg = orgImg?.applyingFilter("CIColorControls", withInputParameters: [kCIInputSaturationKey:0.0])

    let outputImage = UIImage(ciImage: bnwImg!)

    print("Black & white complete")

    return UIImagePNGRepresentation(outputImage)!
}
Run Code Online (Sandbox Code Playgroud)

我对此代码的问题是我一直收到此错误:

fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)

我的代码略有不同,但是当它到达该UIImagePNG/JPEGRepresentation(xx)部分时它仍然会中断.

是否有任何方法可以从CIImage中获取PNG或JPEG数据,以便在图像视图/ UIImage中使用?

任何其他方法都没有详细说明应该使用什么代码.

uiimage uiimagejpegrepresentation uiimagepngrepresentation ciimage swift

7
推荐指数
1
解决办法
2293
查看次数

如何以字节为单位获取图像的确切大小?

我通过将图像转换为NSData并且其数据长度得到错误值来计算图像大小(以字节为单位).

    NSData *data = UIImageJPEGRepresentation(image,0.5);
    NSLog(@"image size in bytes %lu",(unsigned long)data.length);
Run Code Online (Sandbox Code Playgroud)

objective-c uiimageview uiimage nsdata uiimagejpegrepresentation

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

为什么.jpeg文件使用UIImageJPEGRepresentation方法通过writetofile保存大尺寸然后在ios中使用UIImageWriteToSavedPhotosAlbum

我试图将UIImage对象保存到设备中的.jpeg文件,我正在使用此代码:

-(void)saveImageToDocumentsDirectory:(UIImage *)mimage withFileName:(NSString *)fileName 
{
    UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil);
    NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 1.0);
    NSError *error2 = nil;
    if (![dataForJPEGFile writeToFile:[self getDirectoryFilePath:fileName] options:NSAtomicWrite error:&error2])
    {
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

它会保存.jpeg类型的图像,但与UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil)方法相比会占用太多内存,从而以.jpeg类型和相同的质量保存相同的图像对象.

我的问题是为什么这样.. ??

objective-c uiimagejpegrepresentation ipad ios

6
推荐指数
0
解决办法
351
查看次数

为什么来自UIImagePickerController的图像有时会被错误地裁剪?

有时,从相册中挑选的图像的UIImagePickerController裁剪方式与用户想要裁剪的图像不同.这发生在约.50张图片上传中的1张.

当它发生时,图像总是被裁剪为左上角的图像的一部分.这是一个示例图像,其中(1)在红色矩形中显示用户应该选择裁剪的内容和(2)最终在服务器上的图像.

在此输入图像描述

(1)中的选择是假设的,因为不知道用户如何准确定位作物,并且还不可能再现这种不正确的裁剪.它只在实时应用程序中观察到.有些用户尝试多次上传同一张图片时总是使用相同的错误裁剪并最终投诉,因此并非用户故意裁剪此类图片.

有些用户尝试上传不同的图片,但所有图片都被错误地裁剪.

这是代码(简化但没有更多的图像发生):

class ImagePicker {

    private let imagePicker = UIImagePickerController()

    func showPicker() {
        imagePicker.sourceType = .PhotoLibrary
        imagePicker.mediaTypes = [kUTTypeImage as String]
        imagePicker.allowsEditing = true
        imagePicker.delegate = delegate
        imagePicker.modalPresentationStyle = .OverFullScreen
        parentViewController.presentViewController(imagePicker, animated: true, completion: nil)
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
            uploadImage(image)
        }

        picker.dismissViewControllerAnimated(true, completion: nil)
    }

    func uploadImage(image: UIImage) {

        let imageData = UIImageJPEGRepresentation(image, 0.75)!
        let imageFile = PFFile(name: "image.png", data: imageData) …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller uiimage uiimagejpegrepresentation parse-platform swift

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