android - Cloning an image, pixel by pixel -


i want create app reads image, pixel pixel, , use information build clone image. using 2 imageviews, 1 has artistic picture , other has empty picture( white background ).

when click button start image cloning, message:

unfortunately, app has stopped

i tried several changes suggested in several posts not sort out problem.

import android.graphics.bitmap; import android.graphics.color; import android.graphics.drawable.bitmapdrawable; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.imageview;   public class mainactivity extends appcompatactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          cloneanimagepixelbypixel();     }      public void cloneanimagepixelbypixel()     {              final button btn = (button) findviewbyid(r.id.button);              btn.setonclicklistener(new view.onclicklistener()             {                 @override                 public void onclick(view v)                 {                     imageview artimg = (imageview) findviewbyid(r.id.art);                     imageview emptyimg = (imageview) findviewbyid(r.id.emptyim);                      bitmap bitmap1 = ((bitmapdrawable) artimg.getdrawable()).getbitmap();                     bitmap bitmap2 = ((bitmapdrawable) emptyimg.getdrawable()).getbitmap();                      int img_height = bitmap1.getheight();                     int img_width = bitmap1.getwidth();                      (int = 0; < img_height; i++)                     {                         (int k = 0; k < img_width; k++)                         {                             int pixel = bitmap1.getpixel(i, k);                              int = color.alpha(pixel);                             int r = color.red(pixel);                             int g = color.green(pixel);                             int b = color.blue(pixel);                              bitmap2.setpixel(i, k, color.argb(a,r,g,b));                          }                     }                 }             });     } } 

and here xml code:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.mypc.creatingacloneimagefrompixels.mainactivity">      <imageview         android:id="@+id/art"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         app:srccompat="@drawable/sandart"         tools:layout_editor_absolutex="125dp"         tools:layout_editor_absolutey="57dp"         android:layout_alignparenttop="true"         android:layout_centerhorizontal="true"         android:layout_margintop="42dp" />      <imageview         android:id="@+id/emptyim"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         app:srccompat="@drawable/empty"         tools:layout_editor_absolutex="125dp"         tools:layout_editor_absolutey="205dp"         android:layout_centervertical="true"         android:layout_alignend="@+id/art" />      <button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="clone image"         android:textsize="18sp"         android:textstyle="bold"         tools:layout_editor_absolutex="122dp"         tools:layout_editor_absolutey="380dp"         android:layout_marginbottom="83dp"         android:layout_alignparentbottom="true"         android:layout_alignstart="@+id/emptyim" /> </relativelayout>  

the event log here:

28-jul-17 10:18    executing tasks: [:app:assembledebug]  10:18    gradle build finished in 11s 988ms  10:38    executing tasks: [:app:assembledebug]  10:38    gradle build finished in 4s 956ms  10:38    adb rejected shell command (cat /proc/2560/stat): closed  gradle console here:      executing tasks: [:app:generatedebugsources, :app:generatedebugandroidtestsources, :app:mockableandroidjar, :app:preparedebugunittestdependencies]  configuration on demand incubating feature. ndk missing "platforms" directory. if using ndk, verify ndk.dir set valid ndk directory.  set c:\users\easypc\appdata\local\android\sdk\ndk-bundle. if not using ndk, unset ndk variable android_ndk_home or local.properties remove warning.  incremental java compilation incubating feature. :app:prebuild up-to-date :app:predebugbuild up-to-date :app:checkdebugmanifest :app:prereleasebuild up-to-date :app:preparecomandroidsupportanimatedvectordrawable2600alpha1library :app:preparecomandroidsupportappcompatv72600alpha1library :app:preparecomandroidsupportconstraintconstraintlayout102library :app:preparecomandroidsupportsupportcompat2600alpha1library :app:preparecomandroidsupportsupportcoreui2600alpha1library :app:preparecomandroidsupportsupportcoreutils2600alpha1library :app:preparecomandroidsupportsupportfragment2600alpha1library :app:preparecomandroidsupportsupportmediacompat2600alpha1library :app:preparecomandroidsupportsupportv42600alpha1library :app:preparecomandroidsupportsupportvectordrawable2600alpha1library :app:preparedebugdependencies :app:compiledebugaidl up-to-date :app:compiledebugrenderscript up-to-date :app:generatedebugbuildconfig up-to-date :app:generatedebugresvalues up-to-date :app:generatedebugresources up-to-date :app:mergedebugresources up-to-date :app:processdebugmanifest up-to-date :app:processdebugresources up-to-date :app:generatedebugsources up-to-date :app:predebugandroidtestbuild up-to-date :app:preparecomandroidsupporttestespressoespressocore222library :app:preparecomandroidsupporttestespressoespressoidlingresource222library :app:preparecomandroidsupporttestexposedinstrumentationapipublish05library :app:preparecomandroidsupporttestrules05library :app:preparecomandroidsupporttestrunner05library :app:preparedebugandroidtestdependencies :app:compiledebugandroidtestaidl up-to-date :app:processdebugandroidtestmanifest up-to-date :app:compiledebugandroidtestrenderscript up-to-date :app:generatedebugandroidtestbuildconfig up-to-date :app:generatedebugandroidtestresvalues up-to-date :app:generatedebugandroidtestresources up-to-date :app:mergedebugandroidtestresources up-to-date :app:processdebugandroidtestresources up-to-date :app:generatedebugandroidtestsources up-to-date :app:mockableandroidjar up-to-date :app:predebugunittestbuild up-to-date :app:preparedebugunittestdependencies  build successful  total time: 2.717 secs executing tasks: [:app:assembledebug]  configuration on demand incubating feature. ndk missing "platforms" directory. if using ndk, verify ndk.dir set valid ndk directory.  set c:\users\easypc\appdata\local\android\sdk\ndk-bundle. if not using ndk, unset ndk variable android_ndk_home or local.properties remove warning.  incremental java compilation incubating feature. :app:buildinfodebugloader :app:prebuild up-to-date :app:predebugbuild up-to-date :app:checkdebugmanifest :app:preparecomandroidsupportanimatedvectordrawable2600alpha1library :app:preparecomandroidsupportappcompatv72600alpha1library :app:preparecomandroidsupportconstraintconstraintlayout102library :app:preparecomandroidsupportsupportcompat2600alpha1library :app:preparecomandroidsupportsupportcoreui2600alpha1library :app:preparecomandroidsupportsupportcoreutils2600alpha1library :app:preparecomandroidsupportsupportfragment2600alpha1library :app:preparecomandroidsupportsupportmediacompat2600alpha1library :app:preparecomandroidsupportsupportv42600alpha1library :app:preparecomandroidsupportsupportvectordrawable2600alpha1library :app:preparedebugdependencies :app:compiledebugaidl up-to-date :app:compiledebugrenderscript up-to-date :app:generatedebugbuildconfig up-to-date :app:generatedebugresvalues up-to-date :app:generatedebugresources up-to-date :app:mergedebugresources up-to-date :app:processdebugmanifest :app:processdebugresources :app:generatedebugsources :app:incrementaldebugjavacompilationsafeguard up-to-date :app:javaprecompiledebug :app:compiledebugjavawithjavac up-to-date :app:mergedebugshaders up-to-date :app:compiledebugshaders up-to-date :app:generatedebugassets up-to-date :app:mergedebugassets up-to-date :app:processdebugjavares up-to-date :app:transformresourceswithmergejavaresfordebug up-to-date :app:packageinstantrunresourcesdebug :app:fastdeploydebugextractor up-to-date :app:generatedebuginstantrunappinfo up-to-date :app:checkmanifestchangesdebug :app:transformclasseswithextractjarsfordebug up-to-date :app:transformclasseswithinstantrunverifierfordebug up-to-date :app:transformclasseswithdependencycheckerfordebug up-to-date :app:compiledebugndk up-to-date :app:mergedebugjnilibfolders up-to-date :app:transformnativelibswithmergejnilibsfordebug up-to-date :app:transformnativelibsandresourceswithjavaresourcesverifierfordebug up-to-date :app:transformclasseswithinstantrunfordebug :app:transformclassesenhancedwithinstantreloaddexfordebug :app:incrementaldebugtasks :app:precoldswapdebug :app:transformclasseswithinstantrunslicerfordebug :app:transformclasseswithdexfordebug :app:validatesigningdebug :app:transformdexwithinstantrundependenciesapkfordebug :app:transformdexwithinstantrunslicesapkfordebug :app:packagedebug :app:buildinfogeneratordebug :app:compiledebugsources up-to-date :app:assembledebug  build successful  total time: 11.919 secs executing tasks: [:app:assembledebug]  configuration on demand incubating feature. ndk missing "platforms" directory. if using ndk, verify ndk.dir set valid ndk directory.  set c:\users\easypc\appdata\local\android\sdk\ndk-bundle. if not using ndk, unset ndk variable android_ndk_home or local.properties remove warning.  incremental java compilation incubating feature. :app:buildinfodebugloader :app:prebuild up-to-date :app:predebugbuild up-to-date :app:checkdebugmanifest :app:preparecomandroidsupportanimatedvectordrawable2600alpha1library :app:preparecomandroidsupportappcompatv72600alpha1library :app:preparecomandroidsupportconstraintconstraintlayout102library :app:preparecomandroidsupportsupportcompat2600alpha1library :app:preparecomandroidsupportsupportcoreui2600alpha1library :app:preparecomandroidsupportsupportcoreutils2600alpha1library :app:preparecomandroidsupportsupportfragment2600alpha1library :app:preparecomandroidsupportsupportmediacompat2600alpha1library :app:preparecomandroidsupportsupportv42600alpha1library :app:preparecomandroidsupportsupportvectordrawable2600alpha1library :app:preparedebugdependencies :app:compiledebugaidl up-to-date :app:compiledebugrenderscript up-to-date :app:generatedebugbuildconfig up-to-date :app:generatedebugresvalues up-to-date :app:generatedebugresources up-to-date :app:mergedebugresources up-to-date :app:processdebugmanifest up-to-date :app:processdebugresources up-to-date :app:generatedebugsources :app:incrementaldebugjavacompilationsafeguard up-to-date :app:javaprecompiledebug :app:compiledebugjavawithjavac up-to-date :app:mergedebugshaders up-to-date :app:compiledebugshaders up-to-date :app:generatedebugassets up-to-date :app:mergedebugassets up-to-date :app:processdebugjavares up-to-date :app:transformresourceswithmergejavaresfordebug up-to-date :app:packageinstantrunresourcesdebug up-to-date :app:fastdeploydebugextractor up-to-date :app:generatedebuginstantrunappinfo up-to-date :app:checkmanifestchangesdebug :app:transformclasseswithextractjarsfordebug up-to-date :app:transformclasseswithinstantrunverifierfordebug up-to-date :app:transformclasseswithdependencycheckerfordebug up-to-date :app:compiledebugndk up-to-date :app:mergedebugjnilibfolders up-to-date :app:transformnativelibswithmergejnilibsfordebug up-to-date :app:transformnativelibsandresourceswithjavaresourcesverifierfordebug up-to-date :app:transformclasseswithinstantrunfordebug up-to-date :app:transformclassesenhancedwithinstantreloaddexfordebug up-to-date :app:incrementaldebugtasks up-to-date :app:precoldswapdebug :app:transformclasseswithinstantrunslicerfordebug up-to-date :app:transformclasseswithdexfordebug up-to-date :app:validatesigningdebug :app:transformdexwithinstantrundependenciesapkfordebug up-to-date :app:transformdexwithinstantrunslicesapkfordebug up-to-date :app:packagedebug up-to-date :app:buildinfogeneratordebug :app:compiledebugsources up-to-date :app:assembledebug  build successful  total time: 4.89 secs 

the android monitor here:

07-28 10:38:46.196 2560-2560/? e/libprocessgroup: failed make , chown /acct/uid_10080: read-only file system 07-28 10:38:46.196 2560-2560/? w/zygote: createprocessgroup failed, kernel missing config_cgroup_cpuacct? 07-28 10:38:46.197 2560-2560/? i/art: not late-enabling -xcheck:jni (already on) 07-28 10:38:46.211 2560-2570/? e/art: failed sending reply debugger: broken pipe 07-28 10:38:46.211 2560-2570/? i/art: debugger no longer active 07-28 10:38:46.293 2560-2560/? i/instantrun: starting instant run server: main process 07-28 10:38:46.334 2560-2560/? w/art: before android 4.1, method android.graphics.porterduffcolorfilter android.support.graphics.drawable.vectordrawablecompat.updatetintfilter(android.graphics.porterduffcolorfilter, android.content.res.colorstatelist, android.graphics.porterduff$mode) have incorrectly overridden package-private method in android.graphics.drawable.drawable 07-28 10:38:46.426 2560-2583/? d/openglrenderer: use egl_swap_behavior_preserved: true                                                   [ 07-28 10:38:46.427  2560: 2560 d/         ]                                                  hostconnection::get() new host connection established 0xb3ee71f0, tid 2560                                                    [ 07-28 10:38:46.428  2560: 2560 w/         ]                                                  unrecognized gles max version string in extensions: android_emu_checksum_helper_v1  07-28 10:38:46.428 2560-2560/? d/atlas: validating map... 07-28 10:38:46.451 2560-2583/? i/openglrenderer: initialized egl, version 1.4 07-28 10:38:46.452 2560-2583/? w/openglrenderer: failed choose config egl_swap_behavior_preserved, retrying without... 07-28 10:38:46.460 2560-2583/? d/egl_emulation: eglcreatecontext: 0xb3eb8940: maj 2 min 0 rcv 2 07-28 10:38:46.464 2560-2583/? d/egl_emulation: eglmakecurrent: 0xb3eb8940: ver 2 0 07-28 10:38:46.467 2560-2583/? d/openglrenderer: enabling debug mode 0 07-28 10:38:46.500 2560-2583/? d/egl_emulation: eglmakecurrent: 0xb3eb8940: ver 2 0 07-28 10:38:46.555 2560-2560/? w/art: before android 4.1, method int android.support.v7.widget.listviewcompat.lookforselectableposition(int, boolean) have incorrectly overridden package-private method in android.widget.listview 07-28 10:38:51.028 2560-2560/com.example.easypc.creatingacloneimagefrompixels d/androidruntime: shutting down vm 07-28 10:38:51.030 2560-2560/com.example.easypc.creatingacloneimagefrompixels e/androidruntime: fatal exception: main                                                                                                 process: com.example.easypc.creatingacloneimagefrompixels, pid: 2560                                                                                                 java.lang.illegalstateexception                                                                                                     @ android.graphics.bitmap.setpixel(bitmap.java:1420)                                                                                                     @ com.example.easypc.creatingacloneimagefrompixels.mainactivity$1.onclick(mainactivity.java:53)                                                                                                     @ android.view.view.performclick(view.java:4780)                                                                                                     @ android.view.view$performclick.run(view.java:19866)                                                                                                     @ android.os.handler.handlecallback(handler.java:739)                                                                                                     @ android.os.handler.dispatchmessage(handler.java:95)                                                                                                     @ android.os.looper.loop(looper.java:135)                                                                                                     @ android.app.activitythread.main(activitythread.java:5254)                                                                                                     @ java.lang.reflect.method.invoke(native method)                                                                                                     @ java.lang.reflect.method.invoke(method.java:372)                                                                                                     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903)                                                                                                     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) 

i believe problem bitmap2 not mutable. can create mutable bitmap use bitmap.copy() ismutable set true or using bitmap.create(width,height,config). can load mutable bitmap setting inmutable true in bitmapfactory.options using bitmapfactory


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -