android


Crop a drawable image by android gallery cropping method


Onclick of my Imageview,I want to crop the background image of the imageview which is in drawable folder of my app by default cropping technique of android gallery and the cropped image should set in same once it is cropped.
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(Uri.parse("android.resource://com.example.croppingactivity/drawable/apple"), "image/*");
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 400);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("crop", true);
//intent.putExtra("output", Uri.parse("android.resource://com.example.croppingactivity/drawable/apple"));
startActivityForResult(intent, 1);
}
and this is my stacktrace.
12-04 10:21:28.812: E/AndroidRuntime(2553): FATAL EXCEPTION: main
12-04 10:21:28.812: E/AndroidRuntime(2553): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT dat=android.resource://com.example.croppingactivity2130837504 typ=image/* (has extras) }
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.app.Activity.startActivityForResult(Activity.java:3370)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.app.Activity.startActivityForResult(Activity.java:3331)
12-04 10:21:28.812: E/AndroidRuntime(2553): at com.example.croppingactivity.MainActivity$1.onClick(MainActivity.java:52)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.view.View.performClick(View.java:4202)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.view.View$PerformClick.run(View.java:17340)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.os.Handler.handleCallback(Handler.java:725)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.os.Handler.dispatchMessage(Handler.java:92)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.os.Looper.loop(Looper.java:137)
12-04 10:21:28.812: E/AndroidRuntime(2553): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-04 10:21:28.812: E/AndroidRuntime(2553): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 10:21:28.812: E/AndroidRuntime(2553): at java.lang.reflect.Method.invoke(Method.java:511)
12-04 10:21:28.812: E/AndroidRuntime(2553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-04 10:21:28.812: E/AndroidRuntime(2553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-04 10:21:28.812: E/AndroidRuntime(2553): at dalvik.system.NativeStart.main(Native Method)
but it doesn't work.I am getting activity not found Exception.
What I am doing wrong please help me.
Well, this is the code I'm using to do such thing. Maybe you can try it :
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 400);
// Scale the image down to 400 x 400
intent.putExtra("scale", true);
intent.putExtra("windowTitle", "My_title");
// You need to use a temporary file for cropping to work
File tempFile = File.createTempFile("crop", "png",
myActivity.getCacheDir());
mSavedUri = Uri.fromFile(tempFile);
intent.putExtra("output", mSavedUri);
intent.putExtra("outputFormat", "PNG");
profileActivity.startActivityForResult(intent, INTENT_PICK_PICTURE);
I guess you'll have to change intent.setType(...) to intent.setDataAndType(Uri.parse("android.resource://..."), "image/*")

Related Links

Titanium Android module: notification click shows nothing
SearchVIew in android
Android: How to position image correctly
PhoneGap FileTransfer.upload returns null (on Android)
Parse XML android
Delete files from SDcard using my App doesn't affect until i reboot or unmount and mount the sd card? [duplicate]
Android aplication stop responing when adding a onclick event
How Can I call startIntentSenderForResult in Service properly?
How to randomly choose between two choices
Android app crashed after scrolling the list
Check if a device google account is authenticated, only then allow access to my offline app
Android Version settings
calling an activity from a fragment class with an onclick method
Clicking an Item in a listview, to bring up a new view
SharedPreferences not updating
Android VideoView and ImageView rotate image

Categories

HOME
asp.net-web-api
cygwin
xml
apache-jena
pagination
rdbms
static
components
bitbucket-api
spring-data-mongodb
tail
nested-if
zip
jetty
iis-6
nstableheaderview
recordrtc
siddhi
cmdb
ipmitool
rtf
symmetricds
docx
azure-powershell
standards
red5
solrcloud
imagemap
cgbitmapcontext
roslyn
comparator
syntax-highlighting
linked-data
firebase-analytics
iis-express
custom-controls
kudu
jmockit
dumpbin
quickfixj
linkedhashmap
xajax
xdocreport
filesystemwatcher
odroid
metawidget
print-css
knime
strftime
plan-9
openal
opennms
tinymce-3
dt
cup
template-toolkit
bootstrap-tags-input
cudd
custom-lists
async.js
ng-grid
dimension
android-dateutils
gogs
php-socket
redis-cluster
createprocess
yajsw
intel-c++
liquid-layout
linked-tables
exceldatareader
sonarqube-5.0
jqmodal
winginx
alternate
buffering
jeromq
asdf
facebook-timeline
octal
wp7test
booksleeve
dopostback
frameworkelementfactory
boost-signals
window-decoration
floating-point-exceptions
google-maps-mobile
qglwidget
undefined-index
cruisecontrol.rb
updatesourcetrigger
dot-emacs
blender-2.49
sun
cldc
product-management
movieplayer

Resources

Encrypt Message