Skip to content

Commit

Permalink
Merge pull request #82 from skiptools/uiimage-png-jpeg
Browse files Browse the repository at this point in the history
Add support for UIImage pngData() and jpegData(compressionQuality:)
  • Loading branch information
marcprux authored Oct 29, 2024
2 parents 8c5355c + 0fa99e4 commit 32fafee
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Sources/SkipUI/SkipUI/UIKit/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,27 @@ public class UIImage {
@available(*, unavailable)
public func drawAsPattern(in rect: CGRect) {
}
@available(*, unavailable)
public func jpegData(compressionQuality: CGFloat) -> Data? {
fatalError()
#if !SKIP
return nil
#else
guard let bitmap else { return nil }
let outputStream = java.io.ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG, Int(compressionQuality * 100.0), outputStream)
let bytes = outputStream.toByteArray()
return Data(platformValue: bytes)
#endif
}
@available(*, unavailable)
public func pngData() -> Data? {
fatalError()
#if !SKIP
return nil
#else
guard let bitmap else { return nil }
let outputStream = java.io.ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
let bytes = outputStream.toByteArray()
return Data(platformValue: bytes)
#endif
}

public struct Configuration {
Expand Down

0 comments on commit 32fafee

Please sign in to comment.