teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

文字の修正

2018/01/19 11:03

投稿

hum
hum

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,15 +1,18 @@
1
1
  ①Intentで画像をギャラリーから読み込む
2
- ②読み込んだ画像をBitmap aに格納する
2
+ ②読み込んだ画像をBitmap bitmapに格納する
3
3
  ③あらかじめ用意されているボタンを押す
4
- aが加工される
4
+ bitmapが加工される
5
- ⑤加工されたaをImageviewとして表示する
5
+ ⑤加工されたbitmapをImageviewとして表示する
6
6
 
7
7
  という流れのアプリケーションを作成したいのですが
8
8
  中々うまくいきません
9
9
  何方かソースコードの例など、教えていただけませんか?
10
10
 
11
- 今のところ自分が作ったソースコードです↓
11
+ 自分が作ったソースコードです↓
12
12
 
13
+ 今のところintentからギャラリーを開いてbitmapに画像を格納
14
+ その後、表示するところまで作れました。
15
+
13
16
  ###ソースコード
14
17
  package com.example.myapplication_image6;
15
18
 

2

分かりやすくするため

2018/01/19 11:03

投稿

hum
hum

スコア12

title CHANGED
File without changes
body CHANGED
@@ -6,4 +6,93 @@
6
6
 
7
7
  という流れのアプリケーションを作成したいのですが
8
8
  中々うまくいきません
9
- 何方かソースコードの例など、教えていただけませんか?
9
+ 何方かソースコードの例など、教えていただけませんか?
10
+
11
+ 今のところ自分が作ったソースコードです↓
12
+
13
+ ###ソースコード
14
+ package com.example.myapplication_image6;
15
+
16
+ import android.app.Activity;
17
+ import android.content.Intent;
18
+ import android.graphics.Bitmap;
19
+ import android.graphics.BitmapFactory;
20
+ import android.graphics.drawable.BitmapDrawable;
21
+ import android.net.Uri;
22
+ import android.os.Bundle;
23
+ import android.provider.MediaStore;
24
+ import android.support.v7.app.AppCompatActivity;
25
+ import android.view.View;
26
+ import android.widget.Button;
27
+ import android.widget.ImageView;
28
+
29
+
30
+ import java.io.IOException;
31
+ import java.io.InputStream;
32
+
33
+ public class MainActivity extends AppCompatActivity {
34
+
35
+ private static final int READ_REQUEST_CODE = 42;
36
+ ImageView imageView;
37
+
38
+ @Override
39
+ protected void onCreate(Bundle savedInstanceState) {
40
+ super.onCreate(savedInstanceState);
41
+ setContentView(R.layout.activity_main);
42
+
43
+ imageView = (ImageView) findViewById(R.id.imageView);
44
+
45
+ Bitmap bitmap =
46
+ BitmapFactory.decodeResource(
47
+ MainActivity.this.getResources(),
48
+ //グレースケール化する画像名
49
+ //『res』→『drawable』に入っている画像
50
+ R.drawable.lenna
51
+ );
52
+ ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);
53
+
54
+ ////////////////////////////ギャラリーの呼び出し////////////////////////////
55
+
56
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
57
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
58
+ intent.setType("image/*");
59
+
60
+ startActivityForResult(intent, READ_REQUEST_CODE);
61
+ ////////////////////////////////////////////////////////////////////////////
62
+
63
+ //ボタンの宣言
64
+ Button b1 =(Button) this.findViewById(R.id.button1);
65
+ Button b2 =(Button) this.findViewById(R.id.button);
66
+
67
+ ///////////////////////原画像////////////////////////////////////
68
+ ((Button)findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
69
+ @Override
70
+ public void onClick(View v) {
71
+ // ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);
72
+
73
+ }
74
+ });
75
+
76
+ }
77
+
78
+ /////////////////////////////////読み込み/////////////////////////////////////////////////////
79
+ @Override
80
+ public void onActivityResult(int requestCode, int resultCode,
81
+ Intent resultData) {
82
+
83
+ if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
84
+ Uri uri = null;
85
+ if (resultData != null) {
86
+ uri = resultData.getData();
87
+ try {
88
+ Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
89
+ imageView.setImageBitmap(bitmap);
90
+
91
+ } catch (IOException e) {
92
+ e.printStackTrace();
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ }

1

誤字

2018/01/18 11:50

投稿

hum
hum

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,6 @@
1
1
  ①Intentで画像をギャラリーから読み込む
2
- ②Bitmap aに格納する
2
+ 読み込んだ画像をBitmap aに格納する
3
- ③あらかじめ用意されているボタンを押すこと
3
+ ③あらかじめ用意されているボタンを押す
4
4
  ④aが加工される
5
5
  ⑤加工されたaをImageviewとして表示する
6
6