object c code
b4i code
B4X:
-(void)freeImage:(UIImage *)bitmap {
//Get CGImage from UIImage
CGImageRef img = bitmap.CGImage;
//These two lines get get the data from the CGImage
CGDataProviderRef inProvider = CGImageGetDataProvider(img);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider);
//clean up
CFRelease(inBitmapData);
CGImageRelease(img);
}
b4i code
B4X:
Public Sub changePic(bmp As Bitmap,w As Int,h As Int)As Bitmap
Dim img As ImageView
Dim f As Float
img.Initialize("")
img.Width = w
img.Height = h
Dim cvs As Canvas
f= bmp.Height/bmp.Width
cvs.Initialize(img)
cvs.TargetRect.Initialize(0,0,w,f*w)
cvs.DrawColor(Colors.White)
cvs.DrawBitmap(bmp, cvs.TargetRect)
Dim res As Bitmap = cvs.CreateBitmap
cvs.Refresh
'bmp=Null 'A memory leak occurs when the image is a lot.
freeImageData(bmp)'this is error
Return res
End Sub
Public Sub freeImageData(bmp As Bitmap)
Dim no As NativeObject = Me
no.RunMethod("freeImage:", Array(bmp))
End Sub