For controlling my RGB multicolor LEDlamp I try developing an app that reads color values from a RGB color wheel image and displays the values as string over serial/bluetooth/wifi to the LED controller.
The connection stuff is pretty much done bit now I'm struggling getting the "colorpicker" to work.
My basic setup is a layout with 2 edit text fields for displaying the color values in RGB and Hex and an ImageView where a BitmapDrawable (from the colorwheel.png) is created
The Touch Event is set up - i can read the x and y of the canvas but can't access and read it from the Bitmap (and the getPixel for color values does not work as well)
Using xml Syntax Highlighting
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="#ffffff">
- <TextView
- android:layout_width="40px"
- android:layout_height="wrap_content"
- android:text="Hex:"
- android:textColor="#000000"
- android:layout_marginLeft="10px"/>
- <EditText android:text="@+id/EditText01" android:layout_marginLeft="10px" android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="200px"></EditText>
- <TextView
- android:layout_width="40px"
- android:layout_height="wrap_content"
- android:text="RGB:"
- android:textColor="#000000"
- android:layout_marginLeft="10px"/>
- <EditText android:text="@+id/EditText02"
- android:id="@+id/EditText02"
- android:layout_marginLeft="10px"
- android:layout_height="wrap_content"
- android:layout_width="200px">
- </EditText>
- <ImageView android:id="@+id/ImageView01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:hapticFeedbackEnabled="true"
- android:focusableInTouchMode="true"
- android:scaleType="center"
- android:clickable="true" android:layout_gravity="center">
- </ImageView>
- </LinearLayout>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- package cap.pick.color;
- import android.app.Activity;
- import android.graphics.Bitmap;
- import android.graphics.Color;
- import android.graphics.drawable.BitmapDrawable;
- import android.os.Bundle;
- import android.view.MotionEvent;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class MyColorPicker extends Activity {
- public Float xtouch;
- public Float ytouch;
- public TextView Hex;
- public TextView RGB;
- public ImageView ImageView01;
- public BitmapDrawable bd;
- public Bitmap bitmap;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Hex = (TextView) findViewById(R.id.EditText01);
- RGB = (TextView) findViewById(R.id.EditText02);
- ImageView myImageView = null;
- myImageView = (ImageView) findViewById(R.id.ImageView01);
- BitmapDrawable bd = (BitmapDrawable) myImageView.getResources().getDrawable(R.drawable.wheel);
- Bitmap bitmap = bd.getBitmap();
- myImageView.setImageBitmap(bitmap);
- }
- public boolean dispatchTouchEvent(MotionEvent event){
- // this is canvas x/y - for testing the touch event and it works
- xtouch = event.getX();
- ytouch = event.getY();
- RGB.setText(xtouch.toString());
- Hex.setText(ytouch.toString());
- // this is bitmap get color on x/y - it doesn't work (app crashes)
- int color = bitmap.getPixel((int)event.getX(), (int)event.getY());
- RGB.setText(Color.red(color)+""+Color.green(color)+""+Color.blue(color));
- return true;
- }
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
I'm pretty stuck here - please help


