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

質問編集履歴

3

情報の追加

2020/10/27 06:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -4,10 +4,12 @@
4
4
  どのサイズの画像でも、面積平均法を使って、縦横を半分のサイズにしたいです。
5
5
 
6
6
  このような感じです。
7
+ 画像1
7
8
  ![イメージ説明](8d50852a32276d3bc836576c0e61a851.png)
8
9
 
9
10
 
10
11
  しかし、平均する方法がわかりません。以下のような方法で実行しようとしましたが、ここから先どうしたらいいかわかりません。もしかしたらそもそもこの方法が間違っているのだと思います。
12
+ 画像2
11
13
  ![イメージ説明](29a825fac23c238367c2b1a27cea59d2.png)
12
14
 
13
15
  ```

2

説明の追加

2020/10/27 06:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -17,15 +17,16 @@
17
17
  Picture newpic=new Picture(picture.getWidth()/2, picture.getHeight()/2);
18
18
  for (int c = 0; c < w; c++) {
19
19
  for (int r = 0; r < h; r++) {
20
- //copy each pixel from the old pic
20
+ //元の画像から以下をコピーする
21
21
  Pixel p1= picture.getPixel(r, c);
22
22
  Pixel p2= picture.getPixel(r+1, c);
23
23
  Pixel p3= picture.getPixel(r, c+1);
24
24
  Pixel p4= picture.getPixel(r+1, c+1);
25
25
 
26
- int total=// add up p1,p2,p3,p4
26
+ int total=// piからp4までを足す
27
- int average= // total/4
27
+ int average= // それを4でわり平均を出す
28
28
 
29
+ // コピーしたものをaverageに置き換える
29
30
  newpic.setPixel(r,c,average);
30
31
 
31
32
  }

1

書式の改善

2020/10/27 06:04

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,7 @@
11
11
  ![イメージ説明](29a825fac23c238367c2b1a27cea59d2.png)
12
12
 
13
13
  ```
14
- System.err.println("scaleDown: scale down the image by a factor of two by merging every 4 pixels into 1 pixel");
14
+
15
15
  int w = picture.getWidth();
16
16
  int h = picture.getHeight();
17
17
  Picture newpic=new Picture(picture.getWidth()/2, picture.getHeight()/2);