agens-no / aggeometrykit Goto Github PK
View Code? Open in Web Editor NEWQuadrilaterals on CALayer, CGGeometry-functions, UIView/CALayer properties and other invaluable tools.
License: Other
Quadrilaterals on CALayer, CGGeometry-functions, UIView/CALayer properties and other invaluable tools.
License: Other
AGKQuad AGKQuadInsetBottom(AGKQuad q, CGFloat inset)
{
q.tl.y -= inset;
q.tr.y -= inset;
return q;
}
Shouldn't this say q.bl.y and q.br.y ? Can you please push a new fix on CocoaPods or should I create a pull request with the fix?
Whether macos support or not?
Hello. Thanks for a great work.
I'd like to implement some additional functionality. I want user to interact with view by pinch and rotate gestures. I've implemented it.
var initialQuadrilateral: AGKQuad?
@IBAction func handlePinch(_ recognizer : UIPinchGestureRecognizer) {
if (recognizer.state == .began) {
initialQuadrilateral = target.layer.quadrilateral
}
let transform = CGAffineTransform.identity.scaledBy(x: recognizer.scale, y: recognizer.scale)
target.layer.quadrilateral = AGKQuadApplyCGAffineTransform(initialQuadrilateral!, transform)
updateControlPoints()
}
@IBAction func handleRotation(_ recognizer : UIRotationGestureRecognizer) {
if (recognizer.state == .began) {
initialQuadrilateral = target.layer.quadrilateral
}
target.layer.quadrilateral = AGKQuadRotateAroundPoint(initialQuadrilateral!, target.frame, recognizer.rotation)
updateControlPoints()
}
The only problem is that view rotates and scales around zero anchor point instead of center. Could you provide an example of how to implement expected behavior.
Hi,
I download the project but the AGGeometryKitTests.m in the Tests folder seems missing.
Regards
Claudio
Hello, when i set quadrilateral, the position of the layer is shifted, how to remove the quadrilateral settings, I use a uiimageview to achieve the quadrilateral deformation function, uiimageview can be dragged within a certain range, but as long as using quadrilateral, Accurate, so i need to remove the quadrilateral settings after the deformation
I would like to make 3D transform with one image, then merge with another image and save the final result into photo album.
But I can't get the transformed quad view as I want. It only get the original view.
Any help?
Getting a bunch of linker errors trying to run Demo on a device (iPad mini, iOS 8.2).
Can't guess how to fix this.
Hey,
first of all thanks for this great toolkit!
I tried to use AGGeometryKit in Playground, but no transformation seems to be applied, if I look at the result. What I'm doing wrong? Thanks in advance!
Here is my code:
import UIKit
import XCPlayground
import AGGeometryKit
var rect = CGRectMake(0, 0, 200, 200)
var rect2 = CGRectMake(0, 0, 100, 100)
var topView: UIView = UIView(frame: rect);
var test: UIView;
test = UIView(frame: rect2);
test.backgroundColor = UIColor.blueColor()
test.layer.anchorPoint = CGPoint(x: 0,y: 0);
var quad: AGKQuad;
quad = test.layer.quadrilateral;
quad.tr.x += 200; // shift bottom right x-value with 20 pixels
quad.br.y += 20; // shift bottom right y-value with 50 pixels
test.layer.quadrilateral = quad;
topView.addSubview(test);
topView.bringSubviewToFront(test)
- (NSNumber *)defaultMember {
if (!_defaultMember) { // **Converting a pointer value of type 'NSNumber *' to a primitive boolean value; instead, either compare the pointer to nil or call -boolValue**
_defaultMember = @0;
}
return [_defaultMember copy];
}
- (void)resetMatrixToDefault:(NSNumber *)defaultValue {
if (defaultValue) { // **Converting a pointer value of type 'NSNumber *' to a primitive boolean value; instead, either compare the pointer to nil or call -boolValue**
self.defaultMember = defaultValue;
}
self.members = nil;
}
- (NSArray *)allMembers {
NSMutableArray *allMembers = [NSMutableArray arrayWithCapacity:self.count];
for (NSUInteger index = 0; index < self.count; index++) {
[allMembers addObject:self[index]]; // **Argument to 'NSMutableArray' method 'addObject:' cannot be nil**
}
return allMembers;
}
- (UIImage *)imageByCroppingToRect:(CGRect)rect
{
CGImageRef croppedImage = CGImageCreateWithImageInRect([self CGImage], rect);
return [UIImage imageWithCGImage:croppedImage scale:self.scale orientation:self.imageOrientation]; // **Potential leak of an object stored into 'croppedImage'**
}
UIImage+AGKQuad.m
Line 53:
croppedImage is not released.
Hi, thank you for this very useful project.
I've run into a minor issue resolving which would make the library better: NSValue+AGQuad encoding is based on union type and thus not NSCoder friendly.
I'm not sure what is the most elegant way of fixing this.
We've moved the repo to agens-no organization. Let me know if there's any issues regarding this transfer.
Hi and first of all thanks for that magnificent library!
I've started playing around with it a bit and realized that the edges of my transformed image happen to be quite.. rough.
Do you have any suggestions how it would be possible to implement some anti-aliasing, especially for the edges? Thanks a lot for any hints.
Firstly, I would like to state that I understand that this issue is in the Xcode beta, and therefore should be treated as low priority. I did check that this issue does not occur in Xcode 5 with the iOS 7.1 Simulator.
That being said I am experiencing an issue with Xcode 6 and the iOS 8 Simulator and the quad demo where dragging from any corner other than the upper left results in a crash. Here's what I'm seeing:
And the console in text:
2014-06-11 17:30:17.257 AGGeometryKit[14762:346482] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSSetM addObject:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x01e1b916 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01ab98d9 objc_exception_throw + 44
2 CoreFoundation 0x01d3152b -[__NSSetM addObject:] + 699
3 UIKit 0x0032570c _UIApplicationHandleEventFromQueueEvent + 1522
4 UIKit 0x002feb64 _UIApplicationHandleEventQueue + 1561
5 CoreFoundation 0x01d4030f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
6 CoreFoundation 0x01d34c99 __CFRunLoopDoSources0 + 249
7 CoreFoundation 0x01d341f8 __CFRunLoopRun + 952
8 CoreFoundation 0x01d33b7b CFRunLoopRunSpecific + 443
9 CoreFoundation 0x01d339ab CFRunLoopRunInMode + 123
10 GraphicsServices 0x03922500 GSEventRunModal + 192
11 GraphicsServices 0x0392233d GSEventRun + 104
12 UIKit 0x00302dee UIApplicationMain + 3727
13 AGGeometryKit 0x0000b11c main + 76
14 libdyld.dylib 0x034a9ac5 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Dragging from the upper left handle seemed to work. Additionally all of the other demos seemed to work.
Thanks for taking a look, please let me know if I can provide any more information, or help out in any way.
As of today we are just using nearest neighbor algorithm. This looks really bad both when downsampling and upscaling.
Creating an alternative version of AGKTransformPixelMapper using some more sophisticated algorithm would be awesome. Here's some code hosted on google which does bicubic interpolation.
In the example code you have a tab that transforms a skewed section of a given UIImage back to square (the "AGKCATransform3DWithUIImageExample"). In that example you provide a couple hard coded quads with a comment that you are working on a way to calculate those numbers for image adjustment.
Has there been any progress in this area? Or do you have any math resources that I could look at and maybe provide a pull request?
Thanks!
Hi!
I've been playing with 'imageWithPerspectiveCorrectionFromQuad' function to perform perspective correction for images and faced lots of cases when source image was corrupted. I spent some time debugging and found out that "aspectRatioForQuad" returned 'NaN' sometimes. Further digging led me to 'NaN' in sqrt operation caused by negative 'f2' param in '' f2 = step1 * (step2 + step3) ", where 'step1' and 'step2' were positive and 'step3' was negative.
Here's the quad:
AGKQuad {
tl: {212.51999437014263, 233.44500000000016},
tr: {877.67997674942012, 217.19250000000011},
br: {1023.9599728743235, 1668.0975000000001},
bl: {91.079997587203991, 1693.2150000000001}
}
Source image size is: (width = 1242, height = 1773))
Unfortunately, this is a gamestopper for me.
I hope this info is usefull.
Hello, first congratulations for the project. Sorry for my English.
I tried to save the image in the album but does not save the transformed image.
UIImageWriteToSavedPhotosAlbum([self captureView:self.view], self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (UIImage *)captureView:(UIView *)view
{
CGRect rect = [self.view bounds];
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
Thank you very much.
Can you add support for tvOS on the podspec ?
Thanks.
Should we have a swift version? Which parts should be ported which should not be?
Xcode 5 can't compile an app for iOS devices with AGGeometryKit attached. It seems that there is an issue with Xcode 5 (see http://stackoverflow.com/questions/17542092/iokit-not-found). A simple solution would be to just remove this dependency as it is not used anyway.
In your demo video you show an image with 4 corners being dragged and morphed.
Is it possible to have more than one drag point to transform the view ? also is it possible to load a video inside instead of an image ?
You basically can't just copy/paste the README sample code. Took me looking at this for a minute to see the difference, but in the readme the animateFromPresentedStateToQuadrilateral:
... method signature uses interpolationFunction:
, but in the actual method, it's easeFunction:
.
Also, and this is only tangentially related: (Note that I don't use cocoapods, so I don't know what happens if you use that, but...) I basically just drug the AGGeometryKit
folder into my project, and that was a sub-par experience for a couple of reasons:
SenTestingKit
Not sure if you want to do anything about those issues, they were easy to fix, just mentioning 'em.
I noticed an issue with UIImage scale and "imageWithPerspectiveCorrectionFromQuad". If I pass an image with scale factor 3.0f (iPhone6 Plus) it crops only portion of an image. As far as I traced the rects it appears to act weird here:
(Line 164:) UIImage *correctedImage = [self imageWithTransform:transform anchorPoint:CGPointZero];
(Line 165:) UIImage *resultImage = [correctedImage imageByCroppingToRect:destinationRect];
Here, imageWithTransform returns an image with scale 1.0f (so its size in points = size in pixels) and destinationRect is still in points. So the result image is 1/3 upper part of the source image.
Of course, you can always transform your @3x image into @1x by drawing it to image context with scale 1.0 and triple source size. However in situation where you're really low on available memory this could be a hussle.
When you apply auto-layout and make all constrains, everything broke for crop action.
I have a UIView that I'm moving around with the following:
[self.layer animateFromPresentedStateToQuadrilateral:quad
forNumberOfFrames:duration * 60
duration:duration
delay:0.0
animKey:@"demo"
easeFunction:interpolationFunction
onComplete:onComplete];
(Code mostly stolen from the sample project.)
Anyway, the UIView contains a UIButton, and the button essentially does not receive touches after the quad animation. I've tried a couple of things in the onComplete, and verified that the button is still enabled, but using the following workaround for now:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if ([self.gameMenuButton.layer.presentationLayer hitTest:touchLocation])
{
[self gameMenuButtonPressed:nil];
}
}
Hello , Thanks for providing AGGeometryKit ,
Well i am facing issues in saving CAtransformed3d Image view i am using the following code
AGQuad quad = AGQuadMakeWithCGPoints(self.topLeftControl.frame.origin,
self.topRightControl.frame.origin,
self.bottomRightControl.frame.origin,
self.bottomLeftControl.frame.origin);
UIImage *rawImage = [self.imageView.image imageWithQuad:quad scale:1];
When attempting to install via cocoapods, I get the following error running pod install:
[!] Unable to satisfy the following requirements:
AGAssert (~> 0.2)
required by AGGeometryKit/Dependencies (1.0.4)
I need to take an image and transform it into a new quad to give the image a perspective distortion. I want to take a rectangular image and skew. So far I haven't been able to determine how to do this. Ideally this transformation would not require the image to be added to a view since my purposes don't require me to display the image on the screen but do require me to process hundreds of these as fast as possible.
I appreciate any help or advice, thanks!
AGTransformPixelMapper assumes that bytesPerRow == 4 * width. This frequently isn't the case - CGImages are often padded for 16byte alignment. For example, 300x150 UIImage captured with UIGraphicsGetImageFromCurrentImageContext has row width of 1216. Thus, CGImageGetBytesPerRow should be used to determine alignment of input bitmap.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.