AndroidでGlideを使用して画像を読み込む
グライドの例に入る前に、グライドとは何かを知っておく必要があります。グライドはムヤンミンによって開発された画像処理ライブラリです。グライドライブラリを使用すると、画像の表示、画像のデコード、画像のキャッシュ、アニメーションGIFなどを行うことができます。
この例は、Androidにグライドを統合する方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 − build.gradle(Module:app)。に次のコードを追加します
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.andy.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
} ステップ3 − build.gradle(Project:Myapplication)に次のコードを追加します。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
} ステップ4 −次のコードをres / layout/activity_main.xmlに追加します。
<?xml version = "1.0" encoding = "utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android = "https://schemas.android.com/apk/res/android" xmlns:tools = "https://schemas.android.com/tools" android:layout_width = "match_parent" android:layout_height = "match_parent"> <LinearLayout android:layout_width = "match_parent" android:layout_height = "match_parent" android:background = "#797979" android:gravity = "center" android:orientation = "vertical"> <ImageView android:id = "@+id/imageView" android:layout_width = "wrap_content" android:layout_height = "wrap_content" /> </LinearLayout> </android.support.constraint.ConstraintLayout>
ステップ5 −次のコードをsrc / MainActivity.java
に追加しますimport android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = findViewById(R.id.imageView);
Glide.with(this)
.load("https://www.tutorialspoint.com/images/tp-logo-diamond.png")
.into(imageView);
}
}
アプリケーションを実行してみましょう。実際のAndroidモバイルデバイスをコンピューターに接続していると思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、[実行]をクリックします ツールバーの
アイコン。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します
-
Pillowライブラリを使用した画像の読み込みと表示
このプログラムでは、枕ライブラリを使用して画像を読み取ったり読み込んだりします。ピローライブラリは、Image.open()というメソッドで構成されています。この関数は、ファイルパスまたはファイル名を文字列として受け取ります。画像を表示するには、別の関数show()を使用します。パラメータは必要ありません。 サンプルコード from PIL import Image im = Image.open('testimage.jpg') im.show() 出力
-
AndroidでOCRを使用して画像をテキストに変換する方法
OCR(光学式文字認識)技術は、近年かなり進歩しています。画像からテキストをより正確にスキャンできるようになりました。モバイルデバイスで画像をテキストに変換できたらいいのではないでしょうか。これにより、画像をコンピュータにアップロードしてオンラインで変換する手間を省くことができます。この記事では、Androidデバイスを使用して画像をテキストに変換する方法を紹介します。 Androidで画像をテキストに変換する Playストアには多くのOCRベースのアプリがありますが、すべてが希望どおりに正確に機能するわけではありません。ただし、十分なテストを行った結果、正常に機能するアプリがいくつか見つか