gamarra Posted July 5, 2012 at 09:11 PM Report Share #467557 Posted July 5, 2012 at 09:11 PM Boas, antes de mais obrigado. A minha duvida e o seguinte queria fazer uma aplicação para android, que e um detector de cores. tem uma imagem e nessa imagem tenho que detectar as cores. se alguem me poder ajudar agradeço Obrigado mais uma vez =) Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 5, 2012 at 09:45 PM Report Share #467566 Posted July 5, 2012 at 09:45 PM o que pretendes fazer com as cores ? tipo um histograma, um gráfico (2D/3D/4D) de incidência de cores, criar layers com separação das cores encontradas, etc... ? podes ser mais específico ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 5, 2012 at 09:50 PM Author Report Share #467567 Posted July 5, 2012 at 09:50 PM queria ter uma imagem no telemovel, e conseguir detectar as cores dessa imagem clicando em cima. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 5, 2012 at 10:02 PM Report Share #467570 Posted July 5, 2012 at 10:02 PM o que pretendes fazer com as cores ? tipo um histograma, um gráfico (2D/3D/4D) de incidência de cores, criar layers com separação das cores encontradas, etc... ? podes ser mais específico ? mas o que queres fazer com essas cores, porque isso pode levar a diferentes implementações/abordagens ao problema !!! porque "detectar" a cor de um pixel é de caras, no entanto, dependendo do que pretendes fazer, o que é necessário fazer envolve bem mais do que simplesmente saber a cor de um pixel IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 5, 2012 at 10:09 PM Author Report Share #467571 Posted July 5, 2012 at 10:09 PM basicamente era so isso detectar a cor do pixel, depois mostrava a cor que estava la Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 5, 2012 at 10:40 PM Report Share #467576 Posted July 5, 2012 at 10:40 PM poderás guardar um ponteiro para a View da tua Activity getWindow().getDecorView().findViewById(android.R.id.content) depois registas um listener para detectar e tratar eventos do toque no ecrã no final é só tratar dos eventos, determinando onde no ecra foi tocado ficando somente para determinar a cor que tens na view nesse ponto 1 Report IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 6, 2012 at 10:48 AM Author Report Share #467649 Posted July 6, 2012 at 10:48 AM nao estou a conseguir colocar a imagem visivel alguem me pode ajudar obrigado Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 6, 2012 at 10:54 AM Report Share #467653 Posted July 6, 2012 at 10:54 AM tens a imagem como uma resource, ou estas a usar uma imagem tirada da câmera ? no entanto, poderás sempre usar a ImageView para facilmente apresentares uma imagem na tua aplicação IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 6, 2012 at 12:10 PM Author Report Share #467674 Posted July 6, 2012 at 12:10 PM (edited) package com.example.colordetect; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.support.v4.app.NavUtils; public class ColorDetect extends Activity implements OnTouchListener{ View v; float x,y; Bitmap ball; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_color_detect); getWindow().getDecorView().findViewById(android.R.id.content); v = new View(this); v.setOnTouchListener(this); ball = BitmapFactory.decodeResource(getResources(), R.drawable.fantasy1); x = y = 0; setContentView(v); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_color_detect, menu); return true; } public boolean onTouch(View v, MotionEvent me) { x= me.getX(); y= me.getY(); return false; } } nao aparece a imagem Edited July 6, 2012 at 12:12 PM by gamarra Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 6, 2012 at 01:09 PM Report Share #467681 Posted July 6, 2012 at 01:09 PM o view da tua activity tem um método onde pode aplicar a imagem http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas) http://developer.android.com/reference/android/graphics/Canvas.html#drawBitmap(android.graphics.Bitmap, float, float, android.graphics.Paint) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 6, 2012 at 01:58 PM Author Report Share #467689 Posted July 6, 2012 at 01:58 PM nao estou a conseguir lol Link to comment Share on other sites More sharing options...
gamarra Posted July 6, 2012 at 02:39 PM Author Report Share #467702 Posted July 6, 2012 at 02:39 PM (edited) package com.example.colordetect; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.TextView; public abstract class ColorDetect extends Activity implements OnTouchListener{ MyBringBackSurFace ourSurFaceView; float x,y; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ourSurFaceView = new MyBringBackSurFace(this); ourSurFaceView.setOnTouchListener(this); x = 0; y = 0; setContentView(ourSurFaceView); setContentView(R.layout.activity_color_detect); } @Override public void onPause() { super.onPause(); ourSurFaceView.pause(); } public void onResume() { super.onResume(); ourSurFaceView.resume(); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_color_detect, menu); return true; final TextView textView = (TextView)findViewById(R.id.textView1); final TextView textViewCol = (TextView)findViewById(R.id.textViewcolor); targetImage.setOnTouchListener(new ImageView.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel(0, 200000); int redValue = Color.red(pixel); int blueValue = Color.blue(pixel); int greenValue = Color.green(pixel); if(pixel == Color.RED){ textViewCol.setText("It is RED"); } /*if(redValue == 255){ if(blueValue == 0) if(greenValue==0) textViewCol.setText("It is Red"); }*/ return true; } }); return false; } tem um erro no target e no colordetect , nao consigo resolver Edited July 6, 2012 at 03:37 PM by gamarra Link to comment Share on other sites More sharing options...
gamarra Posted July 8, 2012 at 05:56 PM Author Report Share #467932 Posted July 8, 2012 at 05:56 PM package com.example.colordetect; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.view.Menu; import android.view.MotionEvent; import android.view.View; //import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.TextView; public class ColorDetect extends Activity { //MyBringBackSurFace ourSurFaceView; float x,y; @SuppressLint("ParserError") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ourSurFaceView = new MyBringBackSurFace(this); // ourSurFaceView.setOnTouchListener(this); x = 0; y = 0; setContentView(R.layout.activity_color_detect); final TextView textView = (TextView)findViewById(R.id.textView1); final TextView textViewCol = (TextView)findViewById(R.id.textViewcolor); final ImageView image = (ImageView)findViewById(R.id.imageView1); image.setOnTouchListener(new ImageView.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel((int)event.getX(),(int)event.getY()); int redValue = Color.red(pixel); int blueValue = Color.blue(pixel); int greenValue = Color.green(pixel); if(pixel == Color.RED){ textViewCol.setText("It is RED"); } if(redValue == 255){ if(blueValue == 0) if(greenValue==0) textViewCol.setText("It is Red"); } return true; } }); } @Override public void onPause() { super.onPause(); // ourSurFaceView.pause(); } public void onResume() { super.onResume(); //ourSurFaceView.resume(); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_color_detect, menu); return false; } } ele neste momento esta a dar as cordenadas mas queria que desse nome das cores como, se algume me poder ajudar obrigado Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 8, 2012 at 06:01 PM Report Share #467934 Posted July 8, 2012 at 06:01 PM imagina: cada componente de cor pode ser de 0 a 255, logo existem 255*255*255 cores diferentes = 16581375 para isso necessitas de ter uma lista de cores a serem avaliadas, atribuir o nome (os nomes não existem em código só por si), e depois tentar verificar a qual cor selecionada mais parece. IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 8, 2012 at 08:31 PM Author Report Share #467969 Posted July 8, 2012 at 08:31 PM mas e o que esta la, so que esta me a dar as coordenadas =/, nao estou mesmo a perceber =( se poderes explicar melhor obrigado Link to comment Share on other sites More sharing options...
gamarra Posted July 9, 2012 at 10:15 AM Author Report Share #468012 Posted July 9, 2012 at 10:15 AM tens algum site que explique isso das cores obrigado Link to comment Share on other sites More sharing options...
pmg Posted July 9, 2012 at 10:20 AM Report Share #468013 Posted July 9, 2012 at 10:20 AM Picuinhice 🙂 imagina: cada componente de cor pode ser de 0 a 255, logo existem ... 256*256*256 cores diferentes = 16777216 What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
gamarra Posted July 9, 2012 at 10:29 AM Author Report Share #468015 Posted July 9, 2012 at 10:29 AM Picuinhice 🙂 256*256*256 cores diferentes = 16777216 mas como vou colocar isso em codigo Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 9, 2012 at 10:44 AM Report Share #468018 Posted July 9, 2012 at 10:44 AM Picuinhice 🙂 256*256*256 cores diferentes = 16777216 eu bem achei o número estranho, mas como era domingo e estava com pressa ... mas como vou colocar isso em codigo não se faz, achas que existem esse número de nomes para cores diferentes ??? para isso necessitas de ter uma lista de cores a serem avaliadas, atribuir o nome (os nomes não existem em código só por si), e depois tentar verificar a qual cor selecionada mais parece. vais por aproximação, já te disse IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 9, 2012 at 10:46 AM Author Report Share #468021 Posted July 9, 2012 at 10:46 AM mas o codigo esta bem so tenho mudar nesta parte do codigo correcto if(redValue == 0){ if(blueValue == 0) if(greenValue == 0) textViewCol.setText("It is Red"); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now