質問編集履歴
5
コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,169 +16,79 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
###該当のソースコード
|
19
|
+
###該当のソースコード(追記)
|
20
|
+
|
21
|
+
```xml
|
22
|
+
|
23
|
+
<?xml version="1.0" encoding="utf-8"?>
|
24
|
+
|
25
|
+
<FrameLayout
|
26
|
+
|
27
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
28
|
+
|
29
|
+
android:layout_height="match_parent"
|
30
|
+
|
31
|
+
android:layout_width="match_parent">
|
32
|
+
|
33
|
+
<jpdb.shoichi_vono_kono.airchainsaw.C
|
34
|
+
|
35
|
+
android:id="@+id/display"
|
36
|
+
|
37
|
+
android:layout_width="match_parent"
|
38
|
+
|
39
|
+
android:layout_height="match_parent" />
|
40
|
+
|
41
|
+
</FrameLayout>
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
上はsurfaceViewを扱っているファイルを含むxmlファイルです。
|
46
|
+
|
47
|
+
Cがファイル名です。
|
20
48
|
|
21
49
|
```java
|
22
50
|
|
23
|
-
tr
|
51
|
+
protected void onCreate(Bundle savedInstanceState) {
|
24
52
|
|
25
|
-
|
53
|
+
super.onCreate(savedInstanceState);
|
26
54
|
|
27
|
-
|
55
|
+
Intent ii = getIntent();
|
28
56
|
|
29
|
-
|
57
|
+
BIngo = ii.getBooleanExtra("BINGOOO", false);
|
30
58
|
|
31
|
-
|
59
|
+
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
32
60
|
|
33
|
-
|
61
|
+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
34
62
|
|
35
|
-
|
63
|
+
setNavigationbarHide(this, true);
|
36
64
|
|
37
|
-
|
65
|
+
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
38
66
|
|
39
|
-
|
67
|
+
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
40
68
|
|
41
|
-
|
69
|
+
mAccele = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
42
70
|
|
43
|
-
|
71
|
+
LayoutInflater factory = LayoutInflater.from(this);
|
44
72
|
|
45
|
-
|
73
|
+
FrameLayout root = new FrameLayout(this);
|
46
74
|
|
47
|
-
|
75
|
+
View view = factory.inflate(R.layout.mix, root);
|
48
76
|
|
49
|
-
|
77
|
+
setContentView(view);
|
50
78
|
|
51
|
-
|
79
|
+
cccc = (C) findViewById(R.id.display);
|
52
80
|
|
53
|
-
|
81
|
+
String h1 = (String) getText(R.string.radar);
|
54
82
|
|
55
|
-
|
83
|
+
cccc.setUr(h1);
|
56
84
|
|
57
|
-
```
|
58
|
-
|
59
|
-
上記が該当の箇所で、コメントアウトしているのは元々の記述を残すためです、というのも第二、第三引数が原因かと思ったからでした。しかし違うようです。
|
60
|
-
|
61
|
-
下記からは関連する記述になります。
|
62
|
-
|
63
|
-
```java
|
64
|
-
|
65
|
-
DisplayMetrics metrics = new DisplayMetrics();
|
66
|
-
|
67
|
-
windowManager.getDefaultDisplay().getMetrics(metrics);
|
68
|
-
|
69
|
-
int _wDpi = (int)metrics.densityDpi;
|
70
|
-
|
71
|
-
res = this.getContext().getResources();
|
72
|
-
|
73
|
-
try {
|
74
|
-
|
75
|
-
ufo = makeBitmap(_wDpi, res, R.drawable.ufocomp, getWidth(), getHeight());
|
76
|
-
|
77
|
-
starmaemae = makeBitmap(_wDpi, res, R.drawable.starskymaemae, getWidth(), getHeight());
|
78
|
-
|
79
|
-
starmae = makeBitmap(_wDpi, res, R.drawable.starskymae, getWidth(), getHeight());
|
80
|
-
|
81
|
-
starushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiro, getWidth(), getHeight());
|
82
|
-
|
83
|
-
starushiroushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiroushiro, getWidth(), getHeight());
|
84
|
-
|
85
|
-
ya = makeBitmap(_wDpi, res, R.drawable.yajirushi, getWidth(), getHeight());
|
86
|
-
|
87
|
-
}catch (OutOfMemoryError e) {
|
88
|
-
|
89
|
-
Log.d("OutOfMemory", "happen");
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
```
|
94
|
-
|
95
|
-
上は一番上のコードより上に記述してあります。
|
96
|
-
|
97
|
-
下は関連するメソッドです。
|
98
|
-
|
99
|
-
```java
|
100
|
-
|
101
|
-
public Bitmap makeBitmap(int wDpi,Resources resources,int id,int MaxWidth,int MaxHeight){
|
102
|
-
|
103
|
-
BitmapFactory.Options options = new BitmapFactory.Options();
|
104
|
-
|
105
|
-
options.inJustDecodeBounds = true;
|
106
|
-
|
107
|
-
BitmapFactory.decodeResource(resources, id, options);
|
108
|
-
|
109
|
-
int _oDpi = options.inDensity;
|
110
|
-
|
111
|
-
float scale = (float)_oDpi/wDpi;
|
112
|
-
|
113
|
-
options.inJustDecodeBounds = false;
|
114
|
-
|
115
|
-
/*if (id == R.drawable.ufocomp) {
|
116
|
-
|
117
|
-
ufooutw = options.outWidth;
|
118
|
-
|
119
|
-
ufoouth = options.outHeight;
|
120
|
-
|
121
|
-
}else if (id == R.drawable.starskymaemae) {
|
122
|
-
|
123
|
-
starmaemaeoutw = options.outWidth;
|
124
|
-
|
125
|
-
starmaemaeouth = options.outHeight;
|
126
|
-
|
127
|
-
}else if (id == R.drawable.starskymae) {
|
128
|
-
|
129
|
-
starmaeoutw = options.outWidth;
|
130
|
-
|
131
|
-
starmaeouth = options.outHeight;
|
132
|
-
|
133
|
-
}else if (id == R.drawable.starskyushiro) {
|
134
|
-
|
135
|
-
starushioutw = options.outWidth;
|
136
|
-
|
137
|
-
starushiouth = options.outHeight;
|
138
|
-
|
139
|
-
}else if (id == R.drawable.starskyushiroushiro) {
|
140
|
-
|
141
|
-
starushiushioutw = options.outWidth;
|
142
|
-
|
143
|
-
starushiushiouth = options.outHeight;
|
144
|
-
|
145
|
-
}*/
|
146
|
-
|
147
|
-
float max = Math.max((float)options.outWidth * scale / MaxWidth, (float)options.outHeight * scale / MaxHeight);
|
148
|
-
|
149
|
-
max = (float) Math.floor(max);
|
150
|
-
|
151
|
-
if(max > 1){
|
152
|
-
|
153
|
-
options.inSampleSize = (int)max;
|
154
|
-
|
155
|
-
Log.e("size", Float.toString(max));
|
156
|
-
|
157
|
-
}else if(max < 1){
|
158
|
-
|
159
|
-
Log.e("makeBitmap", "low Size");
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
//options.inPurgeable=true;
|
164
|
-
|
165
|
-
Bitmap _bm = BitmapFactory.decodeResource(resources, id, options);
|
166
|
-
|
167
|
-
Matrix matrix = new Matrix();
|
168
|
-
|
169
|
-
matrix.postScale(scale*scale, scale*scale);
|
170
|
-
|
171
|
-
Bitmap bmp = Bitmap.createBitmap(_bm, 0, 0, _bm.getWidth(), _bm.getHeight(), matrix, true);
|
172
|
-
|
173
|
-
|
85
|
+
cccc.setBINGo(BIngo);
|
174
|
-
|
175
|
-
_bm = null;
|
176
|
-
|
177
|
-
return bmp;
|
178
86
|
|
179
87
|
}
|
180
88
|
|
181
89
|
```
|
90
|
+
|
91
|
+
使用元のonCreateの部分です
|
182
92
|
|
183
93
|
|
184
94
|
|
4
追記の拡大
test
CHANGED
File without changes
|
test
CHANGED
@@ -252,4 +252,4 @@
|
|
252
252
|
|
253
253
|
###追記(各値)
|
254
254
|
|
255
|
-
wDpi=480, MaxWidth=1080, MaxHeight=1920
|
255
|
+
wDpi=480, MaxWidth=1080, MaxHeight=1920, scale=0.33333334, max=0.0
|
3
各値の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -249,3 +249,7 @@
|
|
249
249
|
```
|
250
250
|
|
251
251
|
呼び出し順は上の通り、makeBitmap()群が最初で次にBitmap.createScaledBitmap()群が呼ばれるようになっています。
|
252
|
+
|
253
|
+
###追記(各値)
|
254
|
+
|
255
|
+
wDpi=480, MaxWidth=1080, MaxHeight=1920
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,43 +8,7 @@
|
|
8
8
|
|
9
9
|
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
|
10
10
|
|
11
|
-
|
11
|
+
|
12
|
-
|
13
|
-
at jpdb.shoichi_vono_kono.airchainsaw.C.surfaceCreated(C.java:265)
|
14
|
-
|
15
|
-
at android.view.SurfaceView.updateWindow(SurfaceView.java:597)
|
16
|
-
|
17
|
-
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:179)
|
18
|
-
|
19
|
-
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
|
20
|
-
|
21
|
-
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2059)
|
22
|
-
|
23
|
-
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1111)
|
24
|
-
|
25
|
-
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6017)
|
26
|
-
|
27
|
-
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
|
28
|
-
|
29
|
-
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
|
30
|
-
|
31
|
-
at android.view.Choreographer.doFrame(Choreographer.java:606)
|
32
|
-
|
33
|
-
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
|
34
|
-
|
35
|
-
at android.os.Handler.handleCallback(Handler.java:739)
|
36
|
-
|
37
|
-
at android.os.Handler.dispatchMessage(Handler.java:95)
|
38
|
-
|
39
|
-
at android.os.Looper.loop(Looper.java:234)
|
40
|
-
|
41
|
-
at android.app.ActivityThread.main(ActivityThread.java:5524)
|
42
|
-
|
43
|
-
at java.lang.reflect.Method.invoke(Native Method)
|
44
|
-
|
45
|
-
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
|
46
|
-
|
47
|
-
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
|
48
12
|
|
49
13
|
```
|
50
14
|
|
@@ -221,3 +185,67 @@
|
|
221
185
|
###試したこと
|
222
186
|
|
223
187
|
引数を変数から数字に変えたりしてみました。
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
###追記(関連するメソッドについて)
|
192
|
+
|
193
|
+
まず、関連するメソッドはmakeBitmap()とBitmap.createScaledBitmap()です。
|
194
|
+
|
195
|
+
```java
|
196
|
+
|
197
|
+
DisplayMetrics metrics = new DisplayMetrics();
|
198
|
+
|
199
|
+
windowManager.getDefaultDisplay().getMetrics(metrics);
|
200
|
+
|
201
|
+
int _wDpi = (int)metrics.densityDpi;
|
202
|
+
|
203
|
+
res = this.getContext().getResources();
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
try {
|
208
|
+
|
209
|
+
ufo = makeBitmap(_wDpi, res, R.drawable.ufocomp, getWidth(), getHeight());
|
210
|
+
|
211
|
+
starmaemae = makeBitmap(_wDpi, res, R.drawable.starskymaemae, getWidth(), getHeight());
|
212
|
+
|
213
|
+
starmae = makeBitmap(_wDpi, res, R.drawable.starskymae, getWidth(), getHeight());
|
214
|
+
|
215
|
+
starushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiro, getWidth(), getHeight());
|
216
|
+
|
217
|
+
starushiroushiro = makeBitmap(_wDpi, res, R.drawable.starskyushiroushiro, getWidth(), getHeight());
|
218
|
+
|
219
|
+
ya = makeBitmap(_wDpi, res, R.drawable.yajirushi, getWidth(), getHeight());
|
220
|
+
|
221
|
+
}catch (OutOfMemoryError e) {
|
222
|
+
|
223
|
+
Log.d("OutOfMemory", "happen");
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
try {
|
230
|
+
|
231
|
+
ufo = Bitmap.createScaledBitmap(ufo, 150, 150, false);
|
232
|
+
|
233
|
+
starmaemae = Bitmap.createScaledBitmap(starmaemae, (int) (starmaemaeoutw * 2.5f), (int) (starmaemaeouth * 2.5f), false);
|
234
|
+
|
235
|
+
starmae = Bitmap.createScaledBitmap(starmae, (int) (starmaeoutw * 2.5f), (int) (starmaeouth * 2.5f), false);
|
236
|
+
|
237
|
+
starushiro = Bitmap.createScaledBitmap(starushiro, (int) (starushioutw * 2.5f), (int) (starushiouth * 2.5f), false);
|
238
|
+
|
239
|
+
starushiroushiro = Bitmap.createScaledBitmap(starushiroushiro, (int) (starushiushioutw * 2.5f), (int) (starushiushiouth * 2.5f), false);
|
240
|
+
|
241
|
+
ya = Bitmap.createScaledBitmap(ya, 175, 175, false);
|
242
|
+
|
243
|
+
}catch (OutOfMemoryError e) {
|
244
|
+
|
245
|
+
Log.d("OutOfMemory", "happen");
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
呼び出し順は上の通り、makeBitmap()群が最初で次にBitmap.createScaledBitmap()群が呼ばれるようになっています。
|
1
説明追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -128,6 +128,10 @@
|
|
128
128
|
|
129
129
|
```
|
130
130
|
|
131
|
+
上は一番上のコードより上に記述してあります。
|
132
|
+
|
133
|
+
下は関連するメソッドです。
|
134
|
+
|
131
135
|
```java
|
132
136
|
|
133
137
|
public Bitmap makeBitmap(int wDpi,Resources resources,int id,int MaxWidth,int MaxHeight){
|