質問編集履歴
3
文字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
①Intentで画像をギャラリーから読み込む
|
2
2
|
|
3
|
-
②読み込んだ画像をBitmap aに格納する
|
3
|
+
②読み込んだ画像をBitmap bitmapに格納する
|
4
4
|
|
5
5
|
③あらかじめ用意されているボタンを押す
|
6
6
|
|
7
|
-
④aが加工される
|
7
|
+
④bitmapが加工される
|
8
|
-
|
8
|
+
|
9
|
-
⑤加工されたaをImageviewとして表示する
|
9
|
+
⑤加工されたbitmapをImageviewとして表示する
|
10
10
|
|
11
11
|
|
12
12
|
|
@@ -18,7 +18,13 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
|
21
|
+
自分が作ったソースコードです↓
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
今のところintentからギャラリーを開いてbitmapに画像を格納
|
26
|
+
|
27
|
+
その後、表示するところまで作れました。
|
22
28
|
|
23
29
|
|
24
30
|
|
2
分かりやすくするため
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,181 @@
|
|
15
15
|
中々うまくいきません
|
16
16
|
|
17
17
|
何方かソースコードの例など、教えていただけませんか?
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
今のところ自分が作ったソースコードです↓
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
###ソースコード
|
26
|
+
|
27
|
+
package com.example.myapplication_image6;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
import android.app.Activity;
|
32
|
+
|
33
|
+
import android.content.Intent;
|
34
|
+
|
35
|
+
import android.graphics.Bitmap;
|
36
|
+
|
37
|
+
import android.graphics.BitmapFactory;
|
38
|
+
|
39
|
+
import android.graphics.drawable.BitmapDrawable;
|
40
|
+
|
41
|
+
import android.net.Uri;
|
42
|
+
|
43
|
+
import android.os.Bundle;
|
44
|
+
|
45
|
+
import android.provider.MediaStore;
|
46
|
+
|
47
|
+
import android.support.v7.app.AppCompatActivity;
|
48
|
+
|
49
|
+
import android.view.View;
|
50
|
+
|
51
|
+
import android.widget.Button;
|
52
|
+
|
53
|
+
import android.widget.ImageView;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
import java.io.IOException;
|
60
|
+
|
61
|
+
import java.io.InputStream;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
public class MainActivity extends AppCompatActivity {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
private static final int READ_REQUEST_CODE = 42;
|
70
|
+
|
71
|
+
ImageView imageView;
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
@Override
|
76
|
+
|
77
|
+
protected void onCreate(Bundle savedInstanceState) {
|
78
|
+
|
79
|
+
super.onCreate(savedInstanceState);
|
80
|
+
|
81
|
+
setContentView(R.layout.activity_main);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
imageView = (ImageView) findViewById(R.id.imageView);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
Bitmap bitmap =
|
90
|
+
|
91
|
+
BitmapFactory.decodeResource(
|
92
|
+
|
93
|
+
MainActivity.this.getResources(),
|
94
|
+
|
95
|
+
//グレースケール化する画像名
|
96
|
+
|
97
|
+
//『res』→『drawable』に入っている画像
|
98
|
+
|
99
|
+
R.drawable.lenna
|
100
|
+
|
101
|
+
);
|
102
|
+
|
103
|
+
((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
////////////////////////////ギャラリーの呼び出し////////////////////////////
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
112
|
+
|
113
|
+
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
114
|
+
|
115
|
+
intent.setType("image/*");
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
startActivityForResult(intent, READ_REQUEST_CODE);
|
120
|
+
|
121
|
+
////////////////////////////////////////////////////////////////////////////
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
//ボタンの宣言
|
126
|
+
|
127
|
+
Button b1 =(Button) this.findViewById(R.id.button1);
|
128
|
+
|
129
|
+
Button b2 =(Button) this.findViewById(R.id.button);
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
///////////////////////原画像////////////////////////////////////
|
134
|
+
|
135
|
+
((Button)findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
|
136
|
+
|
137
|
+
@Override
|
138
|
+
|
139
|
+
public void onClick(View v) {
|
140
|
+
|
141
|
+
// ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
});
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
/////////////////////////////////読み込み/////////////////////////////////////////////////////
|
156
|
+
|
157
|
+
@Override
|
158
|
+
|
159
|
+
public void onActivityResult(int requestCode, int resultCode,
|
160
|
+
|
161
|
+
Intent resultData) {
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
166
|
+
|
167
|
+
Uri uri = null;
|
168
|
+
|
169
|
+
if (resultData != null) {
|
170
|
+
|
171
|
+
uri = resultData.getData();
|
172
|
+
|
173
|
+
try {
|
174
|
+
|
175
|
+
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
|
176
|
+
|
177
|
+
imageView.setImageBitmap(bitmap);
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
} catch (IOException e) {
|
182
|
+
|
183
|
+
e.printStackTrace();
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
}
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
}
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
①Intentで画像をギャラリーから読み込む
|
2
2
|
|
3
|
-
②Bitmap aに格納する
|
3
|
+
②読み込んだ画像をBitmap aに格納する
|
4
4
|
|
5
|
-
③あらかじめ用意されているボタンを押す
|
5
|
+
③あらかじめ用意されているボタンを押す
|
6
6
|
|
7
7
|
④aが加工される
|
8
8
|
|