質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

リサイズ

コントロール、ウィンドウ、フォームやスクリーンのサイズ変更を指します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

1713閲覧

Android 座標色コード取得

schoolstudent

総合スコア5

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

リサイズ

コントロール、ウィンドウ、フォームやスクリーンのサイズ変更を指します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2021/08/26 04:02

編集2021/08/26 04:59

現在、androidにてjavaを使用し、photoview(https://github.com/Baseflow/PhotoView)からタップした場所の座標を取得し、色コード取得するプログラムを開発しています。photoviewを使用する理由はどんな端末でも画面範囲を超えた大きさの画像を扱えるようにするためです。
もともとはimageviewを表示し、カラーコードを取得していました。imageviewの場合、サイズが大きい画像のときにlayoutに設定した縮小は表面上だけで、内部では画面を超えてimageviewが表示されているため、うまく座標を取得することができません。
photoviewを使わなくても良い代案として「画像を読み込むときにリサイズする」や「画面全体を座標取得範囲とする」などを考えましたが、どれもよくわからず結果としてphotoviewが利用できるようになったところで止まっています。photoviewを使わずとも、どの端末でもどんな画像でもカラーコードを取得できる方法であれば構いません。
どなたかお力を貸していただけませんか。。。。

MainActivity2という名前です

1import android.annotation.SuppressLint; 2import android.app.Activity; 3import android.content.Intent; 4 5import android.graphics.Bitmap; 6import android.graphics.BitmapFactory; 7 8import android.net.Uri; 9import android.os.Bundle; 10import android.os.ParcelFileDescriptor; 11 12import android.util.Log; 13 14import android.view.MotionEvent; 15 16import android.view.View; 17import android.widget.Button; 18import android.widget.ImageView; 19 20import android.widget.TextView; 21 22import com.github.chrisbanes.photoview.PhotoView; 23 24import java.io.FileDescriptor; 25import java.io.IOException; 26 27 28 29public class MainActivity2 extends Activity { 30 private static final int RESULT_PICK_IMAGEFILE = 1000; 31 private static Bitmap mSourceBitmap = null; 32 33 private Bitmap bmp; 34 35 private TextView colorrgb1; 36 private NamedColor nc; 37 int x = 0; 38 int y = 0; 39 private PhotoView photoView; 40 41 42 43 44 45 46 @Override 47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 setContentView(R.layout.activity_main2); 50 51 52 53 colorrgb1 = (TextView)findViewById(R.id.colorrgb1); 54 55 photoView = (PhotoView) findViewById(R.id.photo_view); 56 57 58 59 } 60 61 62 63 64 @Override 65 public void onActivityResult(int requestCode, int resultCode, Intent resultData) { 66 super.onActivityResult(requestCode, resultCode, resultData); 67 if (requestCode == RESULT_PICK_IMAGEFILE && resultCode == RESULT_OK) { 68 Uri uri = null; 69 if (resultData != null) { 70 uri = resultData.getData(); 71 72 try { 73 bmp = getBitmapFromUri(uri); 74 photoView.setImageBitmap(bmp); 75 } catch (IOException e) { 76 e.printStackTrace(); 77 } 78 } 79 } 80 } 81 82 83 private Bitmap getBitmapFromUri(Uri uri) throws IOException { 84 ParcelFileDescriptor parcelFileDescriptor = 85 getContentResolver().openFileDescriptor(uri, "r"); 86 FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); 87 Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); 88 parcelFileDescriptor.close(); 89 return image; 90 91 } 92 93 94 95 96 97 @SuppressLint("SetTextI18n") 98 @Override 99 public boolean onTouchEvent(MotionEvent event) { 100 switch (event.getAction()) { 101 case MotionEvent.ACTION_DOWN: 102 x = (int) event.getX(); //タッチしたX座標 103 y = (int) event.getY(); //タッチしたY座標 104 105 106 int touchedRGB = bmp.getPixel(x,y); 107 colorrgb1.setText("#" + Integer.toHexString(touchedRGB)); 108 colorrgb1.setTextColor(touchedRGB); 109 110 111 break; 112 } 113 114 return true; 115 116 } 117 118 @Override 119 public void onWindowFocusChanged(boolean hasFocus) { 120 super.onWindowFocusChanged(hasFocus); 121 if (hasFocus) { 122 hideSystemUI(); 123 } 124 } 125 126 private void hideSystemUI() { 127 View decorView = getWindow().getDecorView(); 128 decorView.setSystemUiVisibility( 129 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 130 | View.SYSTEM_UI_FLAG_FULLSCREEN 131 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 132 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE 133 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 134 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 135 ); 136 decorView.setOnSystemUiVisibilityChangeListener 137 (new View.OnSystemUiVisibilityChangeListener() { 138 @Override 139 public void onSystemUiVisibilityChange(int visibility) { 140 // Note that system bars will only be "visible" if none of the 141 // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. 142 if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { 143 Log.d("debug","The system bars are visible"); 144 } else { 145 Log.d("debug","The system bars are NOT visible"); 146 } 147 } 148 }); 149 } 150 151 152 153} 154

layout

1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 android:adjustViewBounds="true" 8 tools:context=".MainActivity2"> 9 10 11 <Button 12 android:id="@+id/button2" 13 android:layout_width="68dp" 14 android:layout_height="39dp" 15 android:layout_margin="5dp" 16 android:text="画像" 17 app:layout_constraintBottom_toBottomOf="parent" 18 app:layout_constraintHorizontal_bias="0.0" 19 app:layout_constraintLeft_toLeftOf="parent" 20 app:layout_constraintRight_toRightOf="parent" 21 app:layout_constraintTop_toTopOf="parent" 22 app:layout_constraintVertical_bias="1.0" 23 tools:ignore="MissingConstraints" /> 24 25 26 27 28 <com.github.chrisbanes.photoview.PhotoView 29 android:id="@+id/photo_view" 30 android:layout_width="match_parent" 31 android:layout_height="match_parent" 32 tools:ignore="MissingClass" /> 33 34 35 36 <TextView 37 android:id="@+id/colorrgb1" 38 android:layout_width="158dp" 39 android:layout_height="22dp" 40 android:background="#F0F0F0" 41 android:text="touched color code" 42 app:layout_constraintBottom_toBottomOf="parent" 43 app:layout_constraintHorizontal_bias="0.019" 44 app:layout_constraintLeft_toLeftOf="parent" 45 app:layout_constraintRight_toRightOf="parent" 46 app:layout_constraintTop_toTopOf="parent" 47 app:layout_constraintVertical_bias="0.929" 48 tools:ignore="MissingConstraints" /> 49 50</android.support.constraint.ConstraintLayout> 51 52

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2021/08/26 06:55

photoview が画像を表示する倍率と位置のオフセットがわかれば、そこから逆算すればいいはず…。
jimbe

2021/08/26 08:30 編集

> 「画像を読み込むときにリサイズする」 というと↓の辺でしょうか。 【Android】Bitmapのリサイズhttps://qiita.com/entan05/items/6b56d8548c05455e90b0
schoolstudent

2021/08/26 11:24

hoshi-takanoriさん前回に引き続きコメントありがとうございます!試行錯誤の結果、Bitmapを簡単にリサイズできるコードを見つけたので、それを参考に完成させました!ズーム機能がなくなったのは痛いですが、画像がどんな機種でもはみ出さなくなったので満足です!
schoolstudent

2021/08/26 11:26

jimbeさん前回に引き続きコメントありがとうございます!試行錯誤の結果、貼ってくださったサイトのようにリサイズするコードを見つけたので実装できました!! 今回も丁寧な対応ありがとうございました!
guest

回答1

0

自己解決

Bitmapをリサイズしてimageviewとgetpixelに使用することで解決しました!

投稿2021/08/26 11:27

schoolstudent

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問