안드로이드 개발 질문/답변
(글 수 45,052)
텍스트 에디트에서 입력받은 글자를 각각 하나의 bmp 파일로 저장할려고 합니다.
아래 코드에서 주석 처리된 부분 대신 count = 0을 주면 한개의 텍스트를 이미지로 저장은 됩니다.
여러 글자를 각각의 이미지로 저장할려면 어떻게 해야 할까요?
핸들러로 쓰면 되는지 자체를 모르겠습니다.
핸들러를 쓴 이유는 에디트 텍스트에 값을 주고 딜레이 후에 값을 저장 해야된다고 어드바이스 해 주셔서 핸들러를 사용하였습니다.
답변 부탁드립니다.
package kingphil.Intent_test;
import java.io.FileNotFoundException; import java.io.FileOutputStream;
import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast;
public class view_test extends Activity{
TextView tv;
private LinearLayout container;
private int count;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
String a;
container = (LinearLayout)findViewById(R.id.main_container);
tv = (TextView)findViewById(R.id.tv);
a = getIntent().getStringExtra("input");
Handler mHandler;
mHandler = new Handler();
count = 0;
////////////////////////// 여기가 안됩니다. ///////////////////////////////////////////////
//for(count = 0; count < a.length(); count++)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
tv.setText(String.valueOf(a.charAt(count)));
mHandler.postDelayed(xr, 10);
}
}
Runnable xr = new Runnable() {
public void run() {
container.buildDrawingCache();
Bitmap captureView = container.getDrawingCache();
FileOutputStream fos;
try
{
fos = new FileOutputStream(Environment.getExternalStorageDirectory().toString()+"/capture" + count +".jpeg");
captureView.compress(Bitmap.CompressFormat.JPEG, 100, fos);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "Captured"+count+"!", Toast.LENGTH_SHORT).show();
}
};
}




intent를 불러오는 부분에서 순환 처리하여 해결 하였습니다.