[JAVA] How to judge the click of any area of the image

What you are trying to do

I want to click on an image and decide to get the item if it is within a certain range. I implemented it by referring to the following site.

http://www110.kir.jp/Android/ch0505.html

Clogged part

try and catch

try is the basic operation method to handle ** exception ** in java.


try{
Processing that may throw an exception
}
catch(Exception class type Argument name){
Exception handling(Exception handler)
} 
finally {
The last process that must be executed//Can be executed without fainally
}

What is running in try this time is opening the file with Inputstream and passing it to mBitmap. The code in catch is executed when the specified file does not exist in the assets folder (explained below). In the code I was referring to, nothing was executed when an exception occurred, but by executing e.printStackTrace (), the cause is output to the standard output.

try {
   InputStream is = getResources().getAssets().open("sirokuma.jpg ");
   mBitmap = BitmapFactory.decodeStream(is);
} catch (Exception e) {
   e.printStackTrace();
}

InputStream is = getResources (). getAssets (). open ("sirokuma.jpg ");

What is Inputstream

A class that reads a binary file. is is named after the acronym.

Assets folder

A folder located inside \ AndroidStudioProjects \ Test_Application (app name) \ app \ src \ main. You can store multiple image files together. I'm not sure what's different from res / drawable.

スクリーンショット (20)_LI.jpg If you put it here, you can open it with getResources (). GetAssets (). Open ("filename"). If you want to write multiple files such as reading multiple files, you can improve readability by collecting the getResources (). GetAssets () part as AssetManager. AssetManager assetManager = getResources().getAssets(); assetManager.open ("file 1"); assetManager.open ("file 2");

How to create an Assets folder

Select the main file and right-click / New / Folder / Assets Folder to create it. スクリーンショット (21)_LI.jpg

_ Referenced site _ http://pentan.info/android/app/sample/asset_manager.html

Recommended Posts

How to judge the click of any area of the image
How to determine the number of parallels
How to sort the List of SelectItem
How to output the sum of any three numbers, excluding the same value
How to find the cause of the Ruby error
Customize how to divide the contents of Recyclerview
Output of how to use the slice method
How to display the result of form input
[Java] How to get the authority of the folder
[Java] How to get the URL of the transition source
How to delete / update the list field of OneToMany
How to write Scala from the perspective of Java
How to move to the details screen by clicking the image
[Ruby] How to find the sum of each digit
How to install the root certificate of Centos7 (Cybertrust)
[Java] How to get the maximum value of HashMap
[Rails] How to change the column name of the table
Mandels to create an image of the Mandelbrot set
[SwiftUI] How to specify the abbreviated position of Text
[Android] How to get the setting language of the terminal
[Rails] How to get the contents of strong parameters
How to download the old version of Apache Tomcat
[Swift] How to get the document ID of Firebase
[Rails] How to display an image in the view
How to display the select field of time_select every 30 minutes
How to get the longest information from Twitter as of 12/12/2016
How to change the setting value of Springboot Hikari CP
How to add elements without specifying the length of the array
Let's summarize how to extend the expiration date of Rails
How to solve the problems of Java's three Blocking Queues
[Rails] How to display the list of posts by category
How to mock some methods of the class under test
How to change the contents of the jar file without decompressing
How to check the extension and size of uploaded files
[jsoup] How to get the full amount of a document
How to check the database of apps deployed on Heroku
How to use the link_to method
[Rails] How to convert the URI of the image sent by http to https when using Twitter API
[Swift] How to dynamically change the height of the toolbar on the keyboard
How to use the include? method
[Rails] How to get the URL of the transition source and redirect
How to find the average angle
[Swift5] How to get an array and the complement of arrays
How to set the IP address and host name of CentOS8
How to enclose any character with "~"
How to use the wrapper class
How to display 0 on the left side of the standard input value
How to use setDefaultCloseOperation () of JFrame
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku
[Ruby] How to use any? Method
[Swift UI] How to get the startup status of the application [iOS]
How to get the contents of Map using for statement Memorandum
[Rails] How to omit the display of the character string of the link_to method
[Rails] How to change the page title of the browser for each page
How to get the id of PRIMAY KEY auto_incremented in MyBatis
[JQuery] How to preview the selected image immediately + Add image posting gem
I examined the concept of the process to understand how Docker works
How to add the delete function
[chown] How to change the owner of a file or directory
How to check for the contents of a java fixed-length string
How to distinguish ubuntu cloud image