IKImageViewControlMBS question

I figured out how to use IKImageViewControlMBS.View.zoomFactor to change the scale/size of an image.

But I’m not having any luck figuring out how to move or drag the image around inside the IKImageViewControlMBS. Is there an example somewhere I’ve missed?

well, you zoom in and then scroll to the area you like to show.

So you use scrollToRect method with a rectangle. And you may need convertImageRectToViewRect to calculate the rectangle.

I put this code into a button expecting it to move the zoomed image to the top left corner of the image. It doesn’t do anything. Image stays zoomed in and centered on the bottom left corner of the image.

Var k As IKImageViewControlMBS = IKImageViewControlMBS1
Var x, y, h, w As Integer

Var v As IKImageViewMBS = IKImageViewControlMBS1.View

w = v.Image.Width * v.zoomFactor
h = v.Image.Height * v.zoomFactor

Var r As NSRectMBS = New NSRectMBS(0,0, w , h)

r = v.convertImageRectToViewRect(r)
v.scrollToRect(r)

Let me try:

Var k As IKImageViewControlMBS = IKImageViewControlMBS1
Var v As IKImageViewMBS = IKImageViewControlMBS1.View
v.zoomFactor = 3

this zooms in to 3x.

Then

Var k As IKImageViewControlMBS = IKImageViewControlMBS1
Var v As IKImageViewMBS = IKImageViewControlMBS1.View

Var r As NSRectMBS = v.bounds
var imageVisibleRect as NSRectMBS = v.convertViewRectToImageRect(r)

MessageBox imageVisibleRect.String

gives “{{0, 0}, {200, 117.33333333333333}}” as the visible portion of the image.

But I think there is something broken in IKImageView with scrolling.

I tried to add a NSScrollview, but that didn’t work well.
Maybe don’t zoom there. Use other controls for that.

I tried a couple of other things as well:

scrollToPoint(p)'  nothing happens.

Var centerPoint As NSPointMBS
centerPoint = New NSPointMBS(0,0)
Var z As Double = v.zoomFactor
v.setImageZoomFactor(z, centerPoint)' it always zoomed to center, no matter what centerpoint is set to

Looks like I may have to abandon this project. Thanks for your suggestions.

I am sorry for this mess. I tried a few more things, but I think something broke in Apple’s framework. I will deprecate the class.

Maybe useful?
ZoomScrollCanvasJT.xojo_binary_code.zip (5.9 KB)

I may be missing something, but it looks like it uses Picture, which changes the display color to a generic RBG color profile instead of using the sRGB color profile in the image.

Yeah, I don’t know what IKImageViewControlMBS does, but on the off chance you just needed a canvas that can be zoomed and panned with the mouse/scrollwheel/trackpad, I happened to have that :slight_smile: