<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSBitmapImageRep/setCompression(_:factor:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBitmapImageRep(im)setCompression:factor:"
  },
  "title" : "setCompression(_:factor:)"
}
-->

# setCompression(_:factor:)

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

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

## Parameters

`compression`

An `enum` constant that identifies one of the supported compression types as described in [`NSBitmapImageRep.TIFFCompression`](/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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)