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

특정 지점 RGB값 추출 하는 방법

0 추천

휴대폰의 카메라 앱을 사용하지않고,

 

현재 카메라 앱을 만들어서 따로 앱에서 사진을 찍어서 

 

비동기로 사진을 저장하고 있습니다.

 

여기서 사진을 촬영 후 특정 위치의 rgb값을 추출하고 싶은데... 어떻게 해야할지 감이 오지 않아서 이렇게 글을 남깁니다.

도움 부탁드립니다.

 

아래는 비동기로 촬영한 사진을 폰에 저장을 합니다.

 

저장을 하고 getpixel로 특정지역의 값을 추출 하고 싶은데..

 

어떻게 해야할지 감이 오지 않아서 이렇게 글을 남깁니다.

 

	private void refreshGallery(File file) {
		Intent mediaScanIntent = new Intent( Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
		mediaScanIntent.setData(Uri.fromFile(file));
		sendBroadcast(mediaScanIntent);
	}
private class SaveImageTask extends AsyncTask<byte[], Void, Void> {

		@Override
		protected Void doInBackground(byte[]... data) {
			FileOutputStream outStream = null;

			// Write to SD Card
			try {
				File sdCard = Environment.getExternalStorageDirectory();
				File dir = new File (sdCard.getAbsolutePath() + "/camtest");

				dir.mkdirs();				

				String fileName = String.format("%d.jpg", System.currentTimeMillis());
				File outFile = new File(dir, fileName);
			
				
				outStream = new FileOutputStream(outFile);
				outStream.write(data[0]);
				outStream.flush();
				outStream.close();

				Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length + " to " + outFile.getAbsolutePath());
				//갤러리에 등록 
				refreshGallery(outFile);

				int rgb = bitmap.getpixel(500,500);
				int a=Color.alpha(rgb); //투명도
				int b=Color.red(rgb); 	//빨강
				int c=Color.green(rgb); //초록
				int d=Color.blue(rgb);  //파랑
				
				Toast.makeText(ctx, "RGB 값-A:"+a+" R:"+b+" G:"+c+" B:"+d, Toast.LENGTH_LONG).show();
				
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
			}
			return null;
		}
	}

 

쿠쿠부다스 (6,470 포인트) 님이 2017년 6월 16일 질문

1개의 답변

0 추천
이렇게 하면 되지 않을까요?

String pathName = "/path/to/file/xxx.jpg";

Bitmap bitmap = BitmapFactory.decodeFile(pathName);

int color = bitmap.getPixel(100, 100);  // x=100, y=100
디자이너정 (42,810 포인트) 님이 2017년 6월 18일 답변
...