-2

I need to convert a colour image to grayscale using Android OpenCV. And I need to show the grayscale image in ImageView. My sample image in drawable folder give me simple code.

I have already installed and configured SDK, NDK, OpenCV, and OpenCVManager in emulator.

lonesomeday
  • 215,182
  • 48
  • 300
  • 305

1 Answers1

0

Make a colormatrixlter with saturation(0), then set it to your imageview

    yourImageView.setImageResource(R.drawable.your_drawable_name);
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
    yourImageView.setColorFilter(filter);
Sripathi
  • 1,740
  • 13
  • 19
  • thanks ur answer. can u give me sample code. i dont know how to fill filter value – Prasad Mandushan May 29 '14 at 09:24
  • How to put load my picture in drawable folder to this code segment. – Prasad Mandushan May 29 '14 at 09:34
  • Use this to set image to the imageview yourImageView.setImageResource(R.drawable.your_drawable_name); and use the above code to set saturation to your imageview. – Sripathi May 29 '14 at 10:04
  • Yea it worked.but i have no previlage to i have only 1 reputation. if u dont mind can u tell me how to save that grayscale image. – Prasad Mandushan May 29 '14 at 10:22
  • Use bitmap factory and decode the image, save it to a file. – Sripathi May 29 '14 at 10:25
  • can u please give code. i try this but not work. i want save grayscale image under drwable folder. BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openOutputStream(uri ,string )), null, bmpFactoryOptions); – Prasad Mandushan May 29 '14 at 10:37
  • look at this one http://stackoverflow.com/questions/649154/save-bitmap-to-location – Sripathi May 29 '14 at 12:50