android - Adding an on touch coordinate and pixel color display -
my current code allows take image , display inside image view. how implement ability touch anywhere on image , display color @ pixel, color fill solid object such rectangle display is. i'm hoping solution contains rgb values need them application later on.
import android.app.activity; import android.content.intent; import android.graphics.drawable.drawable; import android.net.uri; import android.os.bundle; import android.os.environment; import android.provider.mediastore; import android.view.view; import android.widget.button; import android.widget.imageview; import java.io.file; public class mainactivity extends activity { private static final int content_request = 1337; private file output = null; button button; imageview imageview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.camerabutton); imageview = (imageview) findviewbyid(r.id.image_view); button.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent = new intent(mediastore.action_image_capture); file dir = environment.getexternalstoragepublicdirectory(environment.directory_dcim); output = new file(dir, "comp4image.jpeg"); i.putextra(mediastore.extra_output, uri.fromfile(output)); startactivityforresult(i, content_request); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { string path = environment.getexternalstoragepublicdirectory(environment.directory_dcim) + "/comp4image.jpeg"; imageview.setimagedrawable(drawable.createfrompath(path)); } }
i won't provide code solution easy implement.
add view.ontouchlistener
imageview.
this listener respond every single touch event happening on view
. (touch down, move, touch etc...)
you can retrieve coordinate of event motionevent.getx(int)
(and y equivalent). (read motionevent
documentation learn more pointers).
when have x , y coordinates of touch event, can pixel color of pointed pixel in bitmap bitmap.getpixel(int, int)
(see here bitmap
attached imageview
).
voila, have selected color. print rectangular view below image view , use color utility class extract arvb components of selected color.
hope helps.
Comments
Post a Comment