different getPath for different images

WannaBeGeek

I need to set different getPath() for different images . Below is the sample describing getPath for one image . I am not able to understand how to use it for setting 2 images .

public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if (cursor != null) {
            // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
            // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
            int column_index = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else
            return null;
    }

Bitmap :-

public void decodeFile(String filePath) {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, o);

        // The new size we want to scale to
        final int REQUIRED_SIZE = 70;

        // Find the correct scale value. It should be the power of 2.
        int width_tmp = o.outWidth, height_tmp = o.outHeight;
        int scale = 1;
        while (true) {
            if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
                break;
            width_tmp /= 2;
            height_tmp /= 2;
            scale *= 2;
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        bitmap = BitmapFactory.decodeFile(filePath, o2);
        bitmap2 = BitmapFactory.decodeFile(filePath, o2);
        imgView.setImageBitmap(bitmap);

        imgView2.setImageBitmap(bitmap2);
InnocentKiller

No actually you do not have to use different getPath for multiple images, you can have single method only for n number of images,

Look at this below example,

//Button's click event i am openong phone's gallery

but1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                openGallery(SELECT_FILE1);
            }
        });

        but2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                openGallery(SELECT_FILE2);
            }
        });

where here is a open gallery function.

public void openGallery(int req_code) {
        Intent i = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
        startActivityForResult(i, req_code);
    }

and inside onActivity result i am setting different path which from which i get images,

public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {
            Uri selectedImageUri = data.getData();

            if (requestCode == SELECT_FILE1) {
                selectedPath1 = getPath(selectedImageUri);
                editText1.setText(selectedPath1);
            }
            if (requestCode == SELECT_FILE2) {
                selectedPath2 = getPath(selectedImageUri);
                editText2.setText(selectedPath2);
            }

        }
    }

and here at last

public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        @SuppressWarnings("deprecation")
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Loading different images in to different pictureboxes

From Dev

Different images for different dimensions on iOS

From Dev

Swift different images for Annotation

From Dev

bxslider images with different widths

From Dev

Tonal equalization on different images

From Dev

bootstrap different shaped images

From Dev

Grid with different height images

From Dev

Issue with images in different browsers

From Dev

specifying different images in xCode

From Dev

bxslider images with different widths

From Dev

Blending different images in canvas

From Dev

Tonal equalization on different images

From Dev

Writing images into a different folder

From Dev

Keras ImageDataGenerator different images

From Dev

Images sizes for different screen

From Dev

Responsive design: different images for different screen sizes

From Dev

Is is possible to run knnMatch for different images on different threads?

From Dev

Show different number of images in different resolutions

From Dev

how to display different images on different infowindow

From Dev

How to assign different images to different vertices in an igraph?

From Dev

Different tile images on different OS versions

From Dev

Show different number of images in different resolutions

From Dev

Is is possible to run knnMatch for different images on different threads?

From Dev

Associating different pin images with different locations iOS

From Dev

Looping different images in different cells of a table with different times

From Dev

MapBox iOS different marker images?

From Dev

Owl carousel for images with different sizes?

From Dev

Different border images top and bottom

From Dev

Expandablelistview different images for groups and childs

Related Related

HotTag

Archive