質問編集履歴
3
ソースコードの更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
FileDescriptor fileDescriptor = pfDescriptor.getFileDescriptor();
|
67
67
|
Bitmap bmp2 = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
68
68
|
pfDescriptor.close();
|
69
|
-
imageView.setImageBitmap(bmp2);
|
69
|
+
((ImageView) findViewById(R.id.imageView)).setImageBitmap(bmp2);
|
70
70
|
}
|
71
71
|
} catch (IOException e) {
|
72
72
|
e.printStackTrace();
|
2
追記の消去
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,15 +7,7 @@
|
|
7
7
|
しかし自分の知識では、どこがダメなのかわかりません
|
8
8
|
何方かご教示ください。
|
9
9
|
|
10
|
-
//////////////////追記//////////////////
|
11
|
-
アプリケーション自体は起動しました。
|
12
|
-
しかし、読み込みボタンを押してギャラリーを開き
|
13
|
-
任意の画像を選択した瞬間に「問題が発生したため・・・」
|
14
|
-
とエラーが起きてしまいます。
|
15
10
|
|
16
|
-
ソースコードは更新しました。
|
17
|
-
たびたび申し訳ありません、ご教示ください。
|
18
|
-
|
19
11
|
以下は問題のソースコードです。
|
20
12
|
|
21
13
|
##ソースコード
|
1
ソースコードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,13 +7,21 @@
|
|
7
7
|
しかし自分の知識では、どこがダメなのかわかりません
|
8
8
|
何方かご教示ください。
|
9
9
|
|
10
|
+
//////////////////追記//////////////////
|
11
|
+
アプリケーション自体は起動しました。
|
12
|
+
しかし、読み込みボタンを押してギャラリーを開き
|
13
|
+
任意の画像を選択した瞬間に「問題が発生したため・・・」
|
14
|
+
とエラーが起きてしまいます。
|
15
|
+
|
16
|
+
ソースコードは更新しました。
|
17
|
+
たびたび申し訳ありません、ご教示ください。
|
18
|
+
|
10
19
|
以下は問題のソースコードです。
|
11
20
|
|
12
21
|
##ソースコード
|
13
22
|
public class MainActivity extends AppCompatActivity {
|
14
23
|
|
15
24
|
private static final int RESULT_PICK_IMAGEFILE = 1000;
|
16
|
-
Button button = findViewById(R.id.button1); //読み込み
|
17
25
|
ImageView imageView;
|
18
26
|
|
19
27
|
@Override
|
@@ -21,16 +29,18 @@
|
|
21
29
|
super.onCreate(savedInstanceState);
|
22
30
|
setContentView(R.layout.activity_main);
|
23
31
|
|
32
|
+
Button button = findViewById(R.id.button1); //読み込み
|
33
|
+
|
24
|
-
Bitmap
|
34
|
+
Bitmap bmp1 = BitmapFactory.decodeResource(
|
25
35
|
MainActivity.this.getResources(),
|
26
36
|
R.drawable.gazou
|
27
37
|
);
|
28
38
|
|
29
39
|
|
30
|
-
((ImageView) findViewById(R.id.imageView)).setImageBitmap(
|
40
|
+
((ImageView) findViewById(R.id.imageView)).setImageBitmap(bmp1);
|
31
41
|
|
32
42
|
|
33
|
-
/////////読み込みボタン//////////
|
43
|
+
/////////////読み込みボタン///////////
|
34
44
|
button.setOnClickListener(new View.OnClickListener() {
|
35
45
|
@Override
|
36
46
|
public void onClick(View view1) {
|
@@ -38,15 +48,19 @@
|
|
38
48
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
39
49
|
intent.setType("image/*");
|
40
50
|
|
51
|
+
//onActivityResultを起動
|
41
52
|
startActivityForResult(intent, RESULT_PICK_IMAGEFILE);
|
42
|
-
imageView.setImageBitmap(bmp);
|
43
53
|
|
54
|
+
|
55
|
+
|
44
56
|
}
|
45
57
|
});
|
46
|
-
}
|
47
|
-
}
|
48
|
-
////////////////////////////////
|
58
|
+
/////////////////////////////////////
|
49
59
|
|
60
|
+
|
61
|
+
|
62
|
+
}
|
63
|
+
|
50
64
|
@Override
|
51
65
|
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
|
52
66
|
if (requestCode == RESULT_PICK_IMAGEFILE && resultCode == Activity.RESULT_OK) {
|
@@ -58,9 +72,9 @@
|
|
58
72
|
pfDescriptor = getContentResolver().openFileDescriptor(uri, "r");
|
59
73
|
if (pfDescriptor != null) {
|
60
74
|
FileDescriptor fileDescriptor = pfDescriptor.getFileDescriptor();
|
61
|
-
Bitmap
|
75
|
+
Bitmap bmp2 = BitmapFactory.decodeFileDescriptor(fileDescriptor);
|
62
76
|
pfDescriptor.close();
|
63
|
-
imageView.setImageBitmap(
|
77
|
+
imageView.setImageBitmap(bmp2);
|
64
78
|
}
|
65
79
|
} catch (IOException e) {
|
66
80
|
e.printStackTrace();
|