Getting the pixel color value of a point on an Android View that includes a Bitmap-backed Canvas
How about load the view to a bitmap (at some point after all your drawing/sprites etc is done), then get the pixel color from the bitmap?
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
then use getPixel(x,y) on the result?
http://developer.android.com/reference/android/graphics/Bitmap.html#getPixel%28int,%20int%29
Can a pixel also store information regarding strokes drawn on that part of the image?
Any shape in a bitmap is a combination of pixels and every pixel has a specific position(x,y) in a plane. A pixel only has a color code information. To get a color code of a specific pixel:
int color = bitmap.getPixel(x,y)
How to get the pixel value of the display in Android?
First of all you need the root container of your activity. Suppose xml of your activity looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- All your stuff-->
</RelativeLayout>
Then in the activity find the root and using jkhouw1
method get Bitmap
which has method getPixel
:
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
View container = findViewById(R.id.container);
Bitmap bitmap = loadBitmapFromView(container);
int pixel = bitmap.getPixel(100, 100);
int r = Color.red(pixel);
int b = Color.blue(pixel);
int g = Color.green(pixel);
}
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
Getting the color of a point on the screen
In the end I used getDrawingCache on the view and then getPixel on the bitmap with the coordinates received in the onTouchEvent function.
View Select a background image and draw on it
You just need to draw the selected image on mExtraCanvas
mdb.mExtraCanvas.drawBitmap(image, 0, 0, null)
And for the scaled part create a scaled bitmap like.
Bitmap.createScaledBitmap(image,
mdb.mExtraBitmap.getWidth(),
mdb.mExtraBitmap.getHeight(), false);
Related Topics
Android: Listview.Getscrolly() - Does It Work
Using Multiple Text Colors in Android's Textview [ HTML.Fromhtml() ]
How to Develop Android App Completely Using Python
How to Access Adb in Os X Through Terminal, "Command Not Found"
Android: Change Tab Text Color Programmatically
How to Show a Preview of a Recyclerview's Contents in The Android Studio Editor
How to Set The Font Style to Bold, Italic and Underlined in an Android Textview
Android Linearlayout Gradient Background
Failed to Find Style 'Mapviewstyle' in Current Theme
CSS Overflow and Absolute Positioning Issue on Android Browser
How to Set Text Color of a Textview Programmatically
Background-Attachment: Fixed Interfering with Background-Size
Is Fcm (Firebase Cloud Messaging) Token for One Device or for One Account
Android: Velocity-Based Viewpager Scrolling
How to Make a Dialog Slide from Bottom to Middle of Screen in Android
App Crashes on Startup Due to Java.Lang.Illegalargumentexception: Column '_Id' Does Not Exist