---
title: "jpegData(compressionQuality:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiimage/jpegdata(compressionquality:)"
---

# jpegData(compressionQuality:)

Returns a data object that contains the image in JPEG format.

## Declaration

```swift
func jpegData(compressionQuality: CGFloat) -> Data?
```

## Parameters

- `compressionQuality`: The quality of the resulting JPEG image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).

## Return Value

Return Value A data object containing the JPEG data, or nil if there’s a problem generating the data. This function may return nil if the image has no data or if the underlying CGImageRef contains data in an unsupported bitmap format.

## Discussion

Discussion If the image object’s underlying image data has been purged, calling this function forces that data to be reloaded into memory.

## See Also

### Image creation

- [Supporting HDR images in your app](uikit/supporting-hdr-images-in-your-app.md)
- [pngData()](uikit/uiimage/pngdata().md)
- [UIGraphicsBeginImageContext(_:)](uikit/uigraphicsbeginimagecontext(_:).md)
- [UIGraphicsGetImageFromCurrentImageContext()](uikit/uigraphicsgetimagefromcurrentimagecontext().md)
- [UIGraphicsEndImageContext()](uikit/uigraphicsendimagecontext().md)
