Search code examples
androidimagetint

Tint effect in Android


I need to apply tint effect on image in Android. But the tint effect will only have ORANGE COLOR tint. If anyone has done this type of effect, please help me.

I have seen all the web links found by searching tint effect, but all the links and resources are applying all color tint.

I need to implement this effect on seekbar progress.

Thanks in advance.


Solution

  • I have done that and here is the code. Its done on the seekbar progress and generates Yellow Tint effect on the image.

    skTint.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    
            @Override
            public void onStopTrackingTouch(SeekBar arg0) {
            }
    
            @Override
            public void onStartTrackingTouch(SeekBar arg0) {
            }
    
            @Override
            public void onProgressChanged(SeekBar arg0, int progress,
                    boolean arg2) {
                skTint.setProgress(progress);
                String hex = Integer
                        .toHexString((progress - 255 < 0 ? (progress - 255)
                                * -1 : (progress - 255)));
                hex = (hex.length() == 1 ? "0" + hex : hex);
                hex = (hex.length() > 2 ? hex.substring(0, 1) : hex);
    
                String g_factor = Integer
                        .toHexString((int) (255 - (progress / 3)));
                g_factor = (g_factor.length() == 1 ? "0" + g_factor : g_factor);
    
                String colorcode = "#FFFF" + g_factor + hex;
    
                Bitmap alteredBitmap = Bitmap.createBitmap(
                        resized_bitmap.getWidth(), resized_bitmap.getHeight(),
                        resized_bitmap.getConfig());
                Canvas canvas = new Canvas(alteredBitmap);
                Paint paint = new Paint();
                ColorFilter cf = new PorterDuffColorFilter(Color
                        .parseColor(colorcode), Mode.MULTIPLY);
                paint.setColorFilter(cf);
                Matrix matrix = new Matrix();
                canvas.drawBitmap(resized_bitmap, matrix, paint);
                imgeffect.setImageBitmap(alteredBitmap);
            }
        });