마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

카메라에서 색상반전을 하는 기능을 넣고싶습니다.

0 추천
package com.cookandroid.project9_2;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class Project9_2Activity extends Activity {

	ImageButton ibZoomin, ibZoomout, ibRotate, ibBright, ibDark, ibGray, ibNegative;
	MyGraphicView graphicView;

	static float scaleX = 1, scaleY = 1;
	static float angle = 0;
	static float color = 1;
	static float satur = 1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		setTitle("미니 포토샵");

		LinearLayout pictureLayout = (LinearLayout) findViewById(R.id.pictureLayout);
		graphicView = (MyGraphicView) new MyGraphicView(this);
		pictureLayout.addView(graphicView);

		clickIcons();
	}

	private void clickIcons() {
		ibZoomin = (ImageButton) findViewById(R.id.ibZoomin);
		ibZoomin.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				scaleX = scaleX + 0.2f;
				scaleY = scaleY + 0.2f;
				graphicView.invalidate();
			}
		});

		ibZoomout = (ImageButton) findViewById(R.id.ibZoomout);
		ibZoomout.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				scaleX = scaleX - 0.2f;
				scaleY = scaleY - 0.2f;
				graphicView.invalidate();
			}
		});

		ibRotate = (ImageButton) findViewById(R.id.ibRotate);
		ibRotate.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				angle = angle + 20;
				graphicView.invalidate();
			}
		});

		ibBright = (ImageButton) findViewById(R.id.ibBright);
		ibBright.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				color = color + 0.2f;
				graphicView.invalidate();
			}
		});

		ibDark = (ImageButton) findViewById(R.id.ibDark);
		ibDark.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				color = color - 0.2f;
				graphicView.invalidate();
			}
		});

		ibGray = (ImageButton) findViewById(R.id.ibGray);
		ibGray.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (satur == 0)
					satur = 1;
				else
					satur = 0;
				graphicView.invalidate();
			}
		});
		ibNegative = (ImageButton) findViewById(R.id.ibNegative);
		ibNegative.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				color -= color;
				graphicView.invalidate();
			}
		});

	}

	private static class MyGraphicView extends View {
		public MyGraphicView(Context context) {
			super(context);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);

			int cenX = this.getWidth() / 2;
			int cenY = this.getHeight() / 2;
			canvas.scale(scaleX, scaleY, cenX, cenY);
			canvas.rotate(angle, cenX, cenY);

			Paint paint = new Paint();
			float[] array = { color, 0, 0, 0, 0, 0, color, 0, 0, 0, 0, 0,
					color, 0, 0, 0, 0, 0, 1, 0 };
			ColorMatrix cm = new ColorMatrix(array);

			if (satur == 0)
				cm.setSaturation(satur);

			paint.setColorFilter(new ColorMatrixColorFilter(cm));

			Bitmap picture = BitmapFactory.decodeResource(getResources(),
					R.drawable.lena256);
			int picX = (this.getWidth() - picture.getWidth()) / 2;
			int picY = (this.getHeight() - picture.getHeight()) / 2;
			canvas.drawBitmap(picture, picX, picY, paint);

			picture.recycle();
		}
	}
}

 

ibNegative 부분에 어떤식으로 작성을해야 색상이 반전되는 효과를 볼수있을까요?

ㅠㅠ

소지롱스타킹 (140 포인트) 님이 2013년 5월 3일 질문

1개의 답변

0 추천
영상처리를 하시려고 하네요. 영상처리 색상 반전 플로우차트가 있습니다.

참고 해 보세요.
센스가이 (2,010 포인트) 님이 2013년 5월 6일 답변
...