protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
} else if (requestCode == PICK_FROM_ALBUM && resultCode == RESULT_OK) {
try{
File path = new File("/sdcard/image/test");
if(!path.isDirectory())
{
path.mkdir();
}
Uri uri = data.getData();
bmp = Images.Media.getBitmap(getContentResolver(), uri);
String str = "/sdcard/image/test/test2.jpg";
SaveBitmap(bmp,str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void SaveBitmap(Bitmap bitmap, String path)
{
File fileCache = new File(path);
OutputStream out = null;
try
{
fileCache.createNewFile();
out = new FileOutputStream(path);
bmp.compress(CompressFormat.JPEG, 100, out);
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try{
out.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
1번파일에서 저렇게 이미지를 파일로 저장을합니다. 이클립스에서 저장하고 이미지파일로 제대로 열리는것 까지 확인했습니다.
다음 2번파일에서
imageV = (ImageView) findViewById(R.id.image_view);
bmp=BitmapFactory.decodeFile("/sdcard/image/test/test2.jpg");
imageV.setImageBitmap(bmp);
이렇게줘서 받아올려고하는데 어떻게 하면 될까요 정말 미치겠습니다...
이미지뷰가 열려야하는데 안열립니다....
부탁드립니다.
혹시 imageView가 xml에서 wrap_content로 되어있는지 확인해보세요.
v.setImageBitmap(BitmapFactory.decodeFile("sdcard/image/1.jpg"));
v.setImageURI(Uri.fromFile(new File("/sdcard/image/1.jpg")));
둘다 잘 되는걸로 봐서는 xml에서 실수 했을 확률이 큰거 같습니다.
wrap_content으로 되어있으면 imageView에 이미지가 없으면 0으로 잡혀서 소스안에서 이미지를 넣는다고 해도 이미지크기가 0이라서 안보이게 됩니다.
fill_content로했어도 안되네요...
이미지 파일이 큰것같아서 오류나나해서
BitmapFactory.Options option = new BitmapFactory.Options();
option.inSampleSize = 2;
bmp=BitmapFactory.decodeFile("/sdcard/image/test/test2.jpg",option);
Bitmap resize = Bitmap.createScaledBitmap(bmp, width, height, true);
imageV.setImageBitmap(resize); 이것까지 추가했는데고 계속 저 로그캣이 뜨네요
저 주황색 경고는 저도 뜨는데 이미지는 출력 잘 되네요.. 불러오는데 문제가 있는거 같진않고 레이아웃 설정 문제인거 같은데 xml좀 올려주세요.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id = "@+id/layout" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="top">
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/save"
android:text ="저장" />
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/crop"
android:text ="자르기"
/>
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/linecolor"
android:text ="선색"
/>
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/undo"
android:text ="Undo"
/>
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/image_view"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom">
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/share"
android:text ="공유" />
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/bbosasasi"
android:text ="뽀샤시"
/>
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/black"
android:text ="흑백"
/>
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/mozaik"
android:text ="모자이크"
/>
<Button
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id ="@+id/stiker"
android:layout_toRightOf ="@+id/mozaik"
/>
</LinearLayout>
</FrameLayout>
이게 두번재파일의 레이아웃이에ㅛ
제가 첫번째파일에서 버튼을 누르면 2번째파일로 넘거가게했는데요
저장됐으면 기존 비트맵은 recycle 하세요
bmp.compress(CompressFormat.JPEG, 100, out);
이후에
bmp.recycle();
에러 로그도 없다고 하시니..
문제를 좀 더 자세히 알려주시는 것이 좋을 것 같은데요..
1. 카메라에서 찍은 사진 받아오기 전에 ImageView 가 제대로 표시되는지 xml 에서 android:src="@drawable/ic_launcher" 등으로 설정해서 이미지가 잘 보이는지 부터 확인해 보시는 건 어떠신가요..
2. 브레이크 걸어서 디버깅은 해 보신건가요..
요렇게 하면 안될려나요??
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:orientation="horizontal" >
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="저장" />
<Button
android:id="@+id/crop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="자르기" />
<Button
android:id="@+id/linecolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="선색" />
<Button
android:id="@+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Undo" />
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="공유" />
<Button
android:id="@+id/bbosasasi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="뽀샤시" />
<Button
android:id="@+id/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="흑백" />
<Button
android:id="@+id/mozaik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="모자이크" />
<Button
android:id="@+id/stiker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="@+id/mozaik" />
</LinearLayout>
</LinearLayout>




로그캣없나요?