Crop and Zoom Image without Moving Overlay View Instead Move Image in ImageView
Finally I got the solution by combining Cropper library and PhotoView libraries.
https://github.com/rameshkec85/AndroidCropMoveScaleImage
How to TOP CROP Image using PhotoView Android?
You can achieve a TopCrop scale changing the CENTER_CROP scale under updateBaseMatrix() in PhotoViewAttacher of Chris Banes`s PhotoView.
Here is the code:
else if (mScaleType == ScaleType.CENTER_CROP) {
float scale = Math.max(widthScale, heightScale);
mBaseMatrix.postScale(scale, scale);
//Changed dy = 0 for top crop
mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, 0);
Source: http://www.widecodes.com/fxSzNWPeVX/android-image-view-top-crop.html
Since I so that people are requesting more scaleTypes in ImageView: https://code.google.com/p/android/issues/detail?id=58468 I added custom scale types to Chris Banes`s PhotoView.
I send a PR to him. Since I don't know if he will accept the PR(or when), you can get the project in my github: https://github.com/jonathanrz/PhotoView/ and add the aar to your project manually.
You can see an example of usage in CropTypeActivity in the sample project inside the library.
Objective-C iOS Crop Image Using Zoom?
I found an answer here that helped me do what I wanted
iOS: Cropping a still image grabbed from a UIImagePickerController camera with overlay
Code Snippet for those interested
float zoomScale = 1.0 / [scrollView zoomScale];
CGRect rect;
NSLog(@"contentOffset is :%f,%f",[scrollView contentOffset].x,[scrollView contentOffset].y);
rect.origin.x = fabsf([scrollView contentOffset].x * zoomScale);
rect.origin.y = fabsf([scrollView contentOffset].y * zoomScale);
rect.size.width = fabsf([scrollView bounds].size.width * zoomScale);
rect.size.height = fabsf([scrollView bounds].size.height * zoomScale);
UIGraphicsBeginImageContextWithOptions( CGSizeMake( rect.size.width,
rect.size.height),
NO,
0.);
[[imageView image] drawAtPoint:CGPointMake( -rect.origin.x, -rect.origin.y)
blendMode:kCGBlendModeCopy
alpha:1.];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
How do I capture a zoomed UIImageView inside of a Scrollview to crop?
UIImage* imageFromView(UIImage* srcImage, CGRect* rect)
{
CGImageRef cr = CGImageCreateWithImageInRect(srcImage.CGImage, *rect);
UIImage* cropped = [UIImage imageWithCGImage:cr];
CGImageRelease(cr);
return cropped;
}
-(void) doneEditing
{
//Calculate the required area from the scrollview
CGRect visibleRect;
float scale = 1.0f/scrollView.zoomScale;
visibleRect.origin.x = scrollView.contentOffset.x * scale;
visibleRect.origin.y = scrollView.contentOffset.y * scale;
visibleRect.size.width = scrollView.bounds.size.width * scale;
visibleRect.size.height = scrollView.bounds.size.height * scale;
FinalOutputView* outputView = [[FinalOutputView alloc] initWithNibName:@"FinalOutputView" bundle:[NSBundle mainBundle]];
outputView.image = imageFromView(imageView.image, &visibleRect);
[self.navigationController pushViewController:outputView animated:YES];
[outputView release];
}
Loading Orginal Image:
Zooming Image:
Finally Capturing the Image
Related Topics
Build Android Release APK on Phonegap 3.X Cli
Value <Br of Type Java.Lang.String Cannot Be Converted to JSONobject on Android
How to Display List of Resource Drawables
How to Get Preview in Composable Functions That Depend on a View Model
Android Httpclient File Upload Data Corruption and Timeout Issues
Email Verification Using Firebase 3.0 on Android
Disable Android Browser's Input Overlays
Using Asynctask to Speed Up Android App Launch Time
Android/Java: How to Delay Return in a Method
How to Read All The Coming Notifications in Android
How to Highlight the Table Row on Click
Parsing Date/Time to Localtimezone
How to Store Hashmap So That It Can Be Retained It Value After a Device Reboot
How to Add Network_Security_Config.Xml to Manifest in Expo App Without Ejecting
Sqlitedatabase Close() Function Causing Nullpointerexception When Multiple Threads
When Do I Use Setstate in Flutter
Android: HTML in Textview with Link Clickable
Background-Attachment: Fixed Interfering with Background-Size