대학 기말로 그림판 저장, 호출과제인데 너무 어려워요. 어디를 고쳐야할지 모르겠습니다ㅠ
고쳐야 하는 부분을 고쳐 적어주실수 있으신가요? 제발 부탁드립니다ㅠ...
저장, 읽기 버튼
ibSave = (ImageButton) findViewById(R.id.ibSave);
ibSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//View view = getWindow().getDecorView();
//View view = activity.findViewById(android.R.id.content);
View view = findViewById(R.id.img);
//View view = pictureLayout.getRootView();
//View view = pictureLayout.getChildAt(0);
String folder = "TEST";
String name = "test";
saveBitmaptoJpeg(view,folder, name);
}
});
ibLoad = (ImageButton) findViewById(R.id.ibLoad);
ibLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
curShape = READ;
graphicView.invalidate();
mPaint.setColor(Color.RED);
graphicView.invalidate();
}
});
====================================================================
저장관련
public void saveBitmaptoJpeg(View view, String folder, String name) {
String ex_storage =Environment.getExternalStorageDirectory().getAbsolutePath();
// Get Absolute Path in External Sdcard
String foler_name = "/"+folder+"/";
String file_name = name+".jpg"; //저장할 파일 이름
String string_path = ex_storage+foler_name;
File file_path;
view.setDrawingCacheEnabled(true);
// view.buildDrawingCache();
Bitmap screenBitmap = view.getDrawingCache();
try{
file_path = new File(string_path, file_name);
//File file = new File(string_path+file_name);
if(!file_path.isDirectory()){
file_path.mkdirs();
}
//if(file.isFile())
// file.delete();
FileOutputStream out = new FileOutputStream(string_path+file_name);
screenBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
view.setDrawingCacheEnabled(false);
Toast.makeText(getApplicationContext(),
file_name + " 이 저장됨", Toast.LENGTH_SHORT).show();
}catch(FileNotFoundException exception){
Log.e("FileNotFoundException", exception.getMessage());
}catch(IOException exception){
Log.e("IOException", exception.getMessage());
}
}
====================================================================
case READ:
//Paint paint = new Paint();
//paint.setColor(Color.WHITE);
String ex_storage =Environment.getExternalStorageDirectory().getAbsolutePath();
// Get Absolute Path in External Sdcard
String tmp = ex_storage + "/TEST/test.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(tmp);
canvas.drawBitmap(bitmap,0,0,null);
bitmap.recycle();
curShape = LINE;
break;