Ok, so you will need to add several things for this to work (it needs an enum and 6 structs). First the enum:
Public Enum InterpolationQuality
Default = 0
None = 1
Low = 2
Medium = 4
High = 3
Now the 6 structs (3 for 32bit and 3 for 64bit):
[code]//32 bit structs
Structure CGPoint32
x as single
y as single
Structure CGSize32
w as single
h as single
Structure CGRect32
origin as CGPoint32
rsize as CGSize32
//64 bit structs
Structure CGPoint64
x as double
y as double
Structure CGSize64
w as double
h as double
Structure CGRect64
origin as CGPoint64
rsize as CGSize64[/code]
You will also need the following constants:
UIKitLib = "UIKit.framework"
CoreGraphicsLib = "CoreGraphics.framework"
Now for the actual scaling method:
[code]Function Scale(extends img as iOSImage, scaleFactor as Double, mode as InterpolationQuality = InterpolationQuality.Default) As iOSImage
dim UIImageRef as ptr = img.Handle
#if Target32Bit
declare function size lib UIKitLib selector “size” (obj_id as ptr) as CGSize32
dim sz as CGSize32 = size(UIImageRef)
dim newSize as CGSize32
#Elseif Target64Bit
declare function size lib UIKitLib selector “size” (obj_id as ptr) as CGSize64
dim sz as CGSize64 = size(UIImageRef)
dim newSize as CGSize64
#Endif
newSize.w = sz.w * scaleFactor
newSize.h = sz.h * scaleFactor
#if Target32Bit
declare sub UIGraphicsBeginImageContext lib UIKitLib (mSize as CGSize32)
#Elseif Target64Bit
declare sub UIGraphicsBeginImageContext lib UIKitLib (mSize as CGSize64)
#Endif
UIGraphicsBeginImageContext(newSize)
declare function UIGraphicsGetCurrentContext lib UIKitLib () as ptr
dim CGContextRef as ptr = UIGraphicsGetCurrentContext
declare sub CGContextSetInterpolationQuality lib CoreGraphicsLib (context as ptr, quality as InterpolationQuality)
CGContextSetInterpolationQuality(CGContextRef, mode)
#if Target32Bit
declare sub drawInRect lib UIKitLib selector “drawInRect:” (obj_id as ptr, rect as CGRect32)
dim r as CGRect32
#Elseif Target64Bit
declare sub drawInRect lib UIKitLib selector “drawInRect:” (obj_id as ptr, rect as CGRect64)
dim r as CGRect64
#Endif
r.origin.x = 0
r.origin.y = 0
r.rsize.w = newSize.w
r.rsize.h = newSize.h
drawInRect(UIImageRef,r)
declare function UIGraphicsGetImageFromCurrentImageContext lib UIKitLib () as ptr
dim newUIImage as Ptr = UIGraphicsGetImageFromCurrentImageContext
declare sub UIGraphicsEndImageContext lib UIKitLib ()
UIGraphicsEndImageContext
Return iOSImage.FromHandle(newUIImage)
End Function
[/code]
Note that this does not alter the original image but instead returns a new copy which is scaled.
This has been added to iOSKit and will be included in the next update (hopefully I can push the update tomorrow since it is mostly fixes) if you don’t want to try to put it together yourself.