Re: From a view rect to a screen rect
Re: From a view rect to a screen rect
- Subject: Re: From a view rect to a screen rect
- From: Development <email@hidden>
- Date: Sat, 02 Jul 2011 15:17:08 -0700
Ok so the coordinate system is flipped with the CGDisplayCaptureImage method.
I thought something like this would invert the y axis for me:
y = displayRect.origin.y;
selection.origin.y = y - adjusted.y; (Where adjusted y has been changed to correspond with the screen from the preview)
Perhaps I don't understand how rectangles work but since width and height are constant, and the X axis as far as I understand always works left to right, the only thing I had to change was the y so that It was being change from the upper left to the lower left.
This does not even begin to fix the selected area.
So I used this and it fixes the selection issue:
cgImage = CGDisplayCreateImage([selectedDisplay intValue]);
NSImage * oi = [[NSImage alloc]initWithCGImage:cgImage size:theScreen.frame.size];
screenImage = [[NSImage alloc]initWithSize:imageView.frame.size];
[screenImage lockFocus];
[oi compositeToPoint:NSMakePoint(0, 0) fromRect:selected operation:NSCompositeSourceOver];
[screenImage unlockFocus];
And even better, the selection does not get distorted if it does not match the aspect ratio of the screen.
However it is ungodly slow.
It cut my FPS in half. Which I knew it probably would… So my question now is, can I make this more efficent?
and this will only get worse when I scale the image to make it fit the area better
On Jul 1, 2011, at 8:34 PM, Andy Lee wrote:
> On Jul 1, 2011, at 5:47 PM, Development wrote:
>> These don't seem to work. The origin is still way way way off
>>
>>
>> NSRect n1=[imageView convertRect:selection toView:nil];
>> NSPoint p1 = [window convertBaseToScreen:n1.origin];
>>
>> Does any one know how to take a selected area within a view and translate it so that it resizes itself and then adjusts it's origin.
>> Maybe I didn't explain well enough.
>>
>> I have a 800X600 rectangle which contains an image capture of the full screen.
>> Within the 800X600 rectangle you can select a smaller area.
>> This smaller selection should then become the area of the actual full screen that is captured.
>
> The Cocoa methods we have been talking about use different coordinate systems to specify the same physical point on screen. Look at the period in the previous sentence, which is being displayed by a view. It has (x,y) coordinates within the view's coordinate system. That same period has *different* coordinates within the window's coordinate system, and still different coordinates in the screen's coordinate system. Same point -- it didn't move anywhere. Different coordinates. That's what the convert methods are for.
>
> You don't want that. You want to calculate the physical point on the screen (in "display coordinates" as it turns out, not "screen coordinates") that corresponds proportionally to a physical point in your view (given in view coordinates). This is almost always a *different* physical point. You can put a finger on one of these points and a different finger on the other.
>
>> Right now, nothing I do will allow me to capture the correct area. And although my conversion creates a rectangle of the correct size.
>>
>> Is this possibly a case where my coordinates are upside down?
>> And if this is the case, how to I apply a transform to flip the origin's x coordinate?
>> I attempted an affine transform however it doesn't work the same in Mac as iPhone so I'm clueless on how to use affine transform
>
> I don't think this has anything to do with affine transform.
>
> You implied that your original code was generating the proper screen coordinates. You mentioned that you changed to using CGDisplayCreateImageForRect and that's what broke the code.
>
> * What coordinate system does CGDisplayCreateImageForRect use?
> * Where is the origin in that coordinate system?
> * Where is the origin in the screen coordinate system?
>
> I *think* you can fix the problem by fixing the math in your original post, which generated a result in screen coordinates. I suggest you draw a picture.
>
> --Andy
>
>>
>>
>>
>>
>> On Jul 1, 2011, at 1:52 PM, Lee Ann Rucker wrote:
>>
>>>
>>> On Jul 1, 2011, at 1:14 PM, Andy Lee wrote:
>>>
>>>> On Jul 1, 2011, at 2:43 PM, Development wrote:
>>>>> I have tried having the view itself use convertRectToBase passing the screen bounds.
>>>>
>>>> That method doesn't do what you think it does. The docs say pretty clearly you should pass it a rect "in the receiver’s coordinate system". This is a method of NSView, so the receiver is the view, and question is what is the rect being converted to?
>>>>
>>>> I *partly* blame the docs and/or the method name, because it isn't clear what "base" means in the method name. This has always bugged me. As far as I can tell it means the window's coordinate system, so I don't know why they didn't name the method "convertRectToWindow:".
>>>
>>>
>>> http://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/6b989dcbb79e9ba/029eeb633c5287cc
>>>
>>> Quote:
>>> If you want to convert to/from the window's base coordinate system, use the
>>> original -convert[xx]:[to|from]View: and pass in a nil view.
>>>
>>> What those "base" calls do is a conversion to the "base" coordinate system
>>> which isn't the "window base" coordinate system. This will not get you the
>>> coordinates you want. Don't use them. (The "base" coordinate system has to
>>> do with resolution independence; go look it up.)
>>>
>>>
>>>>
>>>> Anyway, check out NSView's window method, and NSWindow's convertBaseToScreen: method. See the docs for what these methods return.
>>>>
>>>> --Andy
>>>>
>>>>
>>>>> This creates a rectangle of the correct size but the origin is always, no matter what, 15,183.
>>>>> I'm totally lost here and don't even know what to search for now that my other attempts have failed.
>>>>> Could some one help me out?
>>>>> I'm hoping to find something with low overhead as clicks are a factor._______________________________________________
>>>>>
>>>>> Cocoa-dev mailing list (email@hidden)
>>>>>
>>>>> Please do not post admin requests or moderator comments to the list.
>>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>>
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>
>>>>> This email sent to email@hidden
>>>>
>>>> _______________________________________________
>>>>
>>>> Cocoa-dev mailing list (email@hidden)
>>>>
>>>> Please do not post admin requests or moderator comments to the list.
>>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>>
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden