Private Sub GetTrueBmp(srcbmp As Bitmap, dst() As Byte) ' the new B4i function
Dim no As NativeObject = Me
Dim mWidth, mHeight As Int
mWidth = srcbmp.Width ' get bitmap width
mHeight = srcbmp.Height ' get bitmap height
no.RunMethod("UIImageToBuffer::::", Array(srcbmp, no.ArrayToNSData(dst), mWidth, mHeight))
End Sub
#if OBJC
- (void)UIImageToBuffer:(UIImage*) bmp :(NSData*)data :(int)width :(int)height{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate([(NSMutableData*)data mutableBytes],
width,
height,
8,
4 * width,
colorSpace,
kCGImageAlphaPremultipliedLast);
if(!context) {
NSLog(@"Failed to create bitmap context");
}
CGColorSpaceRelease(colorSpace);
CGImageRef imageRef = bmp.CGImage;
CGRect rect = CGRectMake(0, 0, width, height);
CGContextDrawImage(context, rect, imageRef);
CGContextRelease(context);
}
#End If