I’m trying to use the following to rotate an image in the folderItem f.
Each time I run the routine the duration gets longer (0.1sec, 1sec, 15sec …) and on the 4th run it crashes with a nil object exception at the point indicated below.
Another thing I notice is that the file size doubles on each rotation…which might explain some timing.
Can anyone shine a light on where it is going wrong?
[code]Dim t1 As Double = MillisecondsMBS
//grab the date
Dim d As date = f.CreationDate
//from mbs ciFilterAffineTransformMBS class documentation
Dim image As New CIImageMBS(f)
Dim n As New NSAffineTransformMBS
n.rotateByDegrees(If (Keyboard.AsyncOptionKey, 90, -90))
Dim transformFilter As New CIFilterAffineTransformMBS
transformFilter.inputImage = image
transformFilter.inputTransform = n
Dim resultImage As CIImageMBS = transformFilter.outputImage
Dim outputImage As NSImageMBS = resultImage.RenderNSImage(False)
//display the rotated
pic = outputImage.CopyPictureWithMask
cnvPic.Invalidate
Dim name As String = f.NameWithoutExtensionMBS
Dim extn As String = f.NameExtensionMBS
Dim parent As FolderItem = f.parent
mfo = New MacFileOperationMBS
Dim options As Integer = MacFileOperationMBS.kFSFileOperationDefaultOptions
Dim interval As Double = 1
//rename the old file
f.name = “oldfile” + “.” + extn
//check the target file is clear
Dim f1 As FolderItem = parent.child(name + “.” + extn)
If f1.exists Then
mfo.MoveObjectToTrash(f1, options, interval)
End If
Try
Dim b As BinaryStream = BinaryStream.create(f1, True)
If b = Nil Or outputImage = Nil Then
Break
Else
//can be GIF, JPEG, TIFF, PNG
b.write outputImage.JPEGRepresentation //crashes here on 4th run with Nil Object Exception
End If
b.Close
//delete the old file
mfo.MoveObjectToTrash(f, options, interval)
//repoint f at the new file
f = new folderItem( f1.NativePath, folderitem.PathTypeNative)
Catch err As IOException
Dim i As Integer = MsgBox( Str(err.ErrorNumber) + “:” + err.Message, 0)
End Try
lb1.addRow(Str( MillisecondsMBS-t1) )
[/code]