The method createBitmapFromURI(uri) in the type ShowPhoto is not applicable for the arguments(string)

I am making an app which can make and save a photo, and I want to display the photo which is made, im this class below. But I am getting the error: “The method createBitmapFromURI(uri) in the type ShowPhoto is not applicable for the arguments(string)”. Any idea for I can fix this?

ShowPhoto.java:

package com.example.photoviewer;

import java.io.FileNotFoundException;

import com.example.keyfinder.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;


public class ShowPhoto extends Activity{

    ImageView iv;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.watch_pic);

        iv = (ImageView) findViewById(R.id.imageView1);

        String uriOfPicture = getIntent().getStringExtra("uri");        
        Bitmap image=createBitmapFromURI(uriOfPicture); //error here
        iv.setImageBitmap(image);
        }

    public Bitmap createBitmapFromURI(Uri uriOfPicture) {

        Bitmap bitmap = null;
        try {
            bitmap = BitmapFactory.decodeStream(getApplicationContext()
                    .getContentResolver().openInputStream(uriOfPicture));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (bitmap != null)
            return Bitmap.createScaledBitmap(bitmap, 100, 100, true);
        else {
            return null;
        }
    }


    }

EDIT: Another error occured meanwhile in my PhotoMaker.java class This is the logcat: http://imgur.com/3K5loY0

This is the Photomaker.java class:

package com.example.photoviewer;

import java.io.FileNotFoundException;

import com.example.keyfinder.R;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.net.Uri;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;


public class FotoMaker extends Activity 
    { 
    ImageView iv;
    Uri uriOfPicture;


    @Override 
    protected void onCreate(Bundle savedInstanceState) 
        { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_pic);

        iv = (ImageView) findViewById(R.id.imageView);
        Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener()
        { 


            @Override 
            public void onClick (View v){
                takeImageFromCamera();

            } 
        }); 
        } 
        @Override 
        protected void onActivityResult(int requestCode, int resultCode, Intent data)
        { 
            if(requestCode == 0)
            { 
                Bitmap image=createBitmapFromURI(uriOfPicture);
                iv.setImageBitmap(image);
            } 
            Intent intent = new Intent(this,ShowPhoto.class);
            intent.putExtra("uri", uriOfPicture);
            startActivity(intent);
        } 
@Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (uriOfPicture != null) {
            outState.putString("cameraImageUri", uriOfPicture.toString());
        }
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (savedInstanceState.containsKey("cameraImageUri")) {
            uriOfPicture = Uri.parse(savedInstanceState.getString("cameraImageUri"));
        }
    }
/*********************************** method to take URI of the picture *******************/
public void takeImageFromCamera(){
        String fileName = "new-photo-name.jpg";
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION,
                "Image captured by camera");

        uriOfPicture = getContentResolver()
                .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        values);  
        Log.i("uri",uriOfPicture.toString());
        Intent intent = new Intent(
                MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uriOfPicture);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent,
                0);


    }
public Bitmap createBitmapFromURI(Uri uriOfPicture) {

    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeStream(getApplicationContext()
                .getContentResolver().openInputStream(uriOfPicture));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (bitmap != null)
        return Bitmap.createScaledBitmap(bitmap, 100, 100, true);
    else {
        return null;
    }
}




    }

Answer

Get Uri from String using Uri parse function :

Bitmap image=createBitmapFromURI(Uri.parse(uriOfPicture));

Leave a Reply

Your email address will not be published. Required fields are marked *