---
title: "setCompression(_:factor:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsbitmapimagerep/setcompression(_:factor:)"
---

# setCompression(_:factor:)

Sets the bitmap image representation’s compression type and compression factor.

## Declaration

```swift
func setCompression(_ compression: NSBitmapImageRep.TIFFCompression, factor: Float)
```

## Parameters

- `compression`: An enum constant that identifies one of the supported compression types as described in doc://com.apple.appkit/documentation/AppKit/NSBitmapImageRep/TIFFCompression.
- `factor`: A floating point value that is specific to the compression type. Many types of compression don’t support varying degrees of compression and thus ignore factor. JPEG compression allows a compression factor ranging from 0.0 to 1.0, with 0.0 being the lowest and 1.0 being the highest.

## Discussion

Discussion When an NSBitmapImageRep is created, the instance stores the compression type and factor for the source data. The tiffRepresentation property and tiffRepresentationOfImageReps(in:) class method try to use the stored compression type and factor. Use this method to change the compression type and factor.

## See Also

### Managing Compression Types

- [getTIFFCompressionTypes(_:count:)](appkit/nsbitmapimagerep/gettiffcompressiontypes(_:count:).md)
- [localizedName(forTIFFCompressionType:)](appkit/nsbitmapimagerep/localizedname(fortiffcompressiontype:).md)
- [canBeCompressed(using:)](appkit/nsbitmapimagerep/canbecompressed(using:).md)
- [getCompression(_:factor:)](appkit/nsbitmapimagerep/getcompression(_:factor:).md)
- [setProperty(_:withValue:)](appkit/nsbitmapimagerep/setproperty(_:withvalue:).md)
- [value(forProperty:)](appkit/nsbitmapimagerep/value(forproperty:).md)
- [NSBitmapImageRep.TIFFCompression](appkit/nsbitmapimagerep/tiffcompression.md)
- [NSBitmapImageRep.PropertyKey](appkit/nsbitmapimagerep/propertykey.md)
