Take the following steps to start a project and add some code that demonstrates loading and displaying an image in an Android application.
Start Eclipse IDE.
From the menu, choose File -> New -> Android Application Project....
In the New Android Application dialog box, specify the project name by typing "Android LoadDisplay" in the Application Name field, and type "leadtools.androidloaddisplay" in the Package Name field. Then keep clicking on the Next button until you have finished creating the project.
In the Project Explorer window, right-click on the AndroidLoadDisplay project and select Properties... from the context menu. In the Project Properties dialog box, select the Java Build Path node, then select the Libraries tab, and click Add External JARs. Select the following .jar files:
In the Order and Export tab, make sure all the check boxes for the .jar files that have been added are selected.
In the Project Explorer window, right-click on the AndroidLoadDisplay project and select New -> Folder... from the context menu. Then type "libs" in the Folder name and click OK.
Create subfolders under libs. The ones created depend on the target CPU, as shown in the following table:
CPU | Folder Name |
Arm | armeabi |
Arm-v7a | armeabi-v7a |
X86 | x86 |
Note: adding multiple CPU support in one project is allowed.
Copy the following libs to the target CPU folders:
In the Project Explorer window, select the res/layout/*activity_main.xml* file, and replace its content with the following:
[XAML]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0"
android:background="@android:color/black">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Image From Gallery"
android:onClick="onSelectImage"/>
<leadtools.controls.ImageViewer
android:id="@+id/imageviewer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".96"
android:background="@android:color/white"/>
</LinearLayout>
In the Project Explorer window, edit the src/leadtools.androidloaddisplay/*MainActivity.java* file, and add the following lines before the Main activity class:
[Java]
import android.view.View;
import android.widget.Toast;
import leadtools.ILeadStream;
import leadtools.LeadStreamFactory;
import leadtools.RasterImage;
import leadtools.RasterSupport;
import leadtools.codecs.RasterCodecs;
import leadtools.controls.ImageViewerPanZoomInteractiveMode;
import leadtools.controls.ImageViewer;
Add the following member variables to the MainActivity class:
[Java]
private static final int IMAGE_GALLERY = 0x0001;
private ImageViewer mViewer;
Update the onCreate() function as shown below:
[Java]
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// RasterSupport
RasterSupport.initialize(this);
// Init viewer
mViewer = (ImageViewer) findViewById(R.id.imageviewer);
mViewer.setTouchInteractiveMode(new ImageViewerPanZoomInteractiveMode());
Add the following functions:
[Java]
public void onSelectImage(View v)
{
Intent gallery = new Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI);
startActivityForResult(gallery, IMAGE_GALLERY);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
if(requestCode == IMAGE_GALLERY)
{
Uri imageUri = data.getData();
try
{
// Create Lead Stream
ILeadStream stream = LeadStreamFactory.create(getContentResolver().openInputStream(imageUri), true);
// Create RasterCodecs
RasterCodecs codecs = new RasterCodecs(String.format("%s/lib/", getApplicationInfo().dataDir));
// Load image
RasterImage image = codecs.load(stream);
// Set the loaded image in the viewer
mViewer.setImage(image);
}
catch(Exception ex)
{
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
Build and run the program.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document