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 |
Mips | mips |
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.
Products |
Support |
Feedback: Loading and Displaying Images in Android |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.