An ImageView that supports different kind of cropping rather than the only Android is currently supporting: centerCrop
Using this library, you can crop your desired image by sides described below:
Development idea borns at the point in [Kerad Games] we needed images cropped by somewhere no matter the image size.
The original images we had to deal with (we wanted the half size of the ball shown whatever screen size), below
Here are some screenshots what we got thanks to this widget :-)
dependencies {
compile 'com.cesards.android:cropimageview:1.0.1'
}
<dependency>
<groupId>com.cesards.android</groupId>
<artifactId>cropimageview</artifactId>
<version>1.0.1</version>
<type>aar</type>
</dependency>
Define in xml:
<com.cesards.cropimageview
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/imageView1"
android:src="@drawable/photo1"
custom:crop="value" />
where value
can take values
topLeft|centerLeft|bottomLeft|topRight|centerRight|bottomRight|centerTop|centerBottom
Or in code:
CropImageView cropImageView = new CropImageView(CropActivity.this);
final Resources res = getResources();
cropImageView.setImageDrawable(res.getDrawable(images[position]));
final CropImageView.CropType cropType = imageCrops[position];
cropImageView.setCropType(cropType);
Performance tests (using Hugo)
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1701)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1701)
V/TestForegroundImageView﹕ ⇠ setFrame [0ms] = true`
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1557)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = false
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=0, t=0, r=1080, b=1701)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
V/TestForegroundCropImageView﹕ ⇢ setFrame(l=1080, t=0, r=2160, b=1701)
V/TestForegroundCropImageView﹕ ⇠ setFrame [0ms] = true
Results: code used does not cause overhead in the UI thread.
- 1.0.1 (2015-02-17)
- Changed Samples UI and removed unused resources.
- Added performance tests to Samples
- Added code styles for contributions
- Improved CropImageView
widget. Removed
onLayout()overhead.
ImageView's
onLayout()is emoty, so we only need logic in
setFrame()` method
- 1.0.0 (2015-02-15)
- Initial release. (
minSdkVersion="14"
)
- Initial release. (
- César Díez Sánchez - [email protected]
- Golden Manager (Beta)
- Does your app use CropImageView? Let me know if you want to be featured in this list :-)
I'm pretty sure you there are some awesome hidden features you need in your daily dev life. Just let me know or collaborate to improve this librar
I'd like to improve this library with your help, there are some new features to implement waiting for you ;)
If you want to contribut, you should use my code styles available in the root of the project!
Copyright 2015 César Díez Sánchez
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.