I wanted to to ask how could i store an image, that will take from gallery and store it to a specific folder.
the location i want to store is Shortcut/Images
i'm posting my code and i want solution after this how to store this image into the location above (The location is not yet created)..
Please keep in mind i want to store image in internal storage so that my app could run in hybrid phone as well
package com.example.mohitgupta.shortcut;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
public class GetImage extends AppCompatActivity {
EditText imageName;
private ImageButton img;
private String name;
private Uri selectedImage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_image);
imageName = (EditText) findViewById(R.id.ImageName);
name = imageName.getText().toString().trim();
}
public void GetImageIntent(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK) {
selectedImage = data.getData();
img = (ImageButton) findViewById(R.id.imageSelected);
img.setImageURI(selectedImage);
}
}
public void SaveButtonClicked(View view){
BitmapDrawable drawable = (BitmapDrawable) img.getDrawable();
Bitmap bitmap = drawable.getBitmap();
//Toast.makeText(GetImage.this,"Image Saved",Toast.LENGTH_SHORT).show();
}
}
layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.mohitgupta.shortcut.GetImage">
<ImageButton
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_margin="15dp"
android:layout_gravity="center"
android:id="#+id/imageSelected"
android:onClick="GetImageIntent"
android:scaleType="fitCenter"
android:backgroundTint="#000000"
android:src="#drawable/ic_add_a_photo_white_24dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_margin="15dp"
android:hint="Enter Name of Image"
android:id="#+id/ImageName"
android:padding="10dp"
android:background="#drawable/shapes"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Save"
android:onClick="SaveButtonClicked"/>
</LinearLayout>
Related
`Hello everyone, I'm here again.
I was given a task to load an image in .tif file format in android studio and then do a method of image tranformation (python code to handle image tranformation, such as gabor filter/transformation).
My problem: The android studio phone first has to load the .tif image from the real phone one imageview to display it in the app.
I have a question,
do .tif images really show up properly on the phone screen, because I can't see the .tif images on the screen?
what I used
Image transformation libry:
https://github.com/Beyka/Android-TiffBitmapFactory
python code run in Android Studio:
https://github.com/chaquo/chaquopy
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.chaquo.python.PyObject;
import com.chaquo.python.Python;
import com.chaquo.python.android.AndroidPlatform;
import org.beyka.tiffbitmapfactory.TiffBitmapFactory;
import java.io.FileNotFoundException;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
TextView textView8;
//private static final int Read_Permission= 101;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button gallery = findViewById(R.id.gallery);
gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent,3);
}
});
/*if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Read_Permission);
}
*/
textView8 = (TextView) findViewById(R.id.textView8);
if(!Python.isStarted()){
Python.start(new AndroidPlatform(this));
}
Python py = Python.getInstance();
PyObject pyobj = py.getModule("hello");
// give python script name
// now call this function
PyObject obj = pyobj.callAttr("main");
// now set return text to textview
textView8.setText(obj.toString());
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && data != null){
try {
// from the Beyla original code
ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(data.getData(), "r");
Bitmap bmp = TiffBitmapFactory.decodeFileDescriptor(parcelFileDescriptor.getFd());
ImageView imageView = findViewById(R.id.imageView);
imageView.setImageBitmap(bmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Uri selectedImage = data.getData();
// ImageView imageView = findViewById(R.id.imageView);
// imageView.setImageURI(selectedImage);
}
}
}
And the activity_main-xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MissingClass">
<ImageView
android:id="#+id/imageView"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
tools:layout_editor_absoluteX="80dp"
tools:layout_editor_absoluteY="194dp"
tools:ignore="MissingConstraints" />
<Button
android:id="#+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Pick Image"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="125dp"
tools:layout_editor_absoluteY="556dp" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="33dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.436"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/pick"
app:layout_constraintVertical_bias="0.2"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
`
Could anybody help me with a problem that I have?
I would like to make an activity in which i have a make photo button (imageButton_add_playground_image) and after pressing it my app opens up camera for me to take a photo (just one photo).
After making a photo I would like to send it to this activity and change make photo button to a photo made by user (but with leaving make photo button activity on it so the photo could be replaced with different one if this one isn't good enough).
My code in *.java file is as follows:
<!-- begin snippet -->
import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RatingBar;
import android.widget.Toast;
import static ???.MainActivity.REQUEST_IMAGE_CAPTURE;
public class AddPlayground extends AppCompatActivity {
EditText playGroundName;
RatingBar rate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
setContentView(R.layout.activity_add_playground);
playGroundName = (EditText) findViewById(R.id.editText_playground_name);
rate = (RatingBar) findViewById(R.id.ratingBar);
Double message = intent.getDoubleExtra(MainActivity.EXTRA_MESSAGE, 0);
Toast.makeText(this, String.valueOf(message), Toast.LENGTH_SHORT).show();
}
public void addPhoto(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
<!-- end snippet -->
And my code in *.xml file is as follows:
<!-- begin snippet -->
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="???.AddPlayground">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="368dp"
android:layout_height="495dp"
android:weightSum="1"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp">
<EditText
android:id="#+id/editText_playground_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Name of playground" />
<ImageButton
android:id="#+id/imageButton_add_playground_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.52"
android:onClick="addPhoto"
app:srcCompat="#drawable/ic_menu_camera" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:visibility="visible" />
<EditText
android:id="#+id/editText_playground_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:hint="Playground description" />
<Button
android:id="#+id/button_add_playground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="addNewPlayground"
android:text="Add" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<!-- end snippet -->
Under the ??? there is something else but I removed it as it is not crucial to this question.
when you are starting with tutorials you should read whole text... HERE you have full doc (your method addPhoto is 1:1 copy of dispatchTakePictureIntent method in there)
in short you also need to handle returned bitmap (thumbnail)
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
yourImageView.setImageBitmap(imageBitmap);
}
}
receiving full sized Bitmap is described in Save the Full-size Photo section of above linked doc
The Android Camera application encodes the photo in the return Intent delivered to onActivityResult() as a small Bitmap in the extras, under the key "data".
Use below code to retrieve image and displays it in an ImageButton.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageButton.setImageBitmap(imageBitmap);
}
}
Here is the full code:
import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RatingBar;
import android.widget.Toast;
public class AddPlayground extends AppCompatActivity {
EditText playGroundName;
RatingBar rate;
ImageButton imageButton;
private static final int REQUEST_IMAGE_CAPTURE = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_playground);
playGroundName = (EditText) findViewById(R.id.editText_playground_name);
rate = (RatingBar) findViewById(R.id.ratingBar);
imageButton = (ImageButton) findViewById(R.id.imageButton_add_playground_image);
Intent intent = getIntent();
Double message = intent.getDoubleExtra(MainActivity.EXTRA_MESSAGE, 0);
Toast.makeText(this, String.valueOf(message), Toast.LENGTH_SHORT).show();
}
public void addPhoto(View view) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
if(extras != null) {
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageButton.setImageBitmap(imageBitmap);
}
}
}
}
Make sure you have added below uses-feature tag in AndroidManifest.xml to use the Camera feature:
<manifest ... >
<uses-feature android:name="android.hardware.camera"
android:required="true" />
.......
..................
</manifest>
Hope this will help~
How can I make that all the pictures from my gallery appear in one view in Android Studio? I need all of my pictures to use after face recognition on them.
Here is the begining of my code:
package com.face.user.faceapplication;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
//import static android.widget.ImageView.*;
public class FirstClass extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
// private ImageView image;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_activity);
Button button = (Button) findViewById(R.id.button);
// ImageView image = (ImageView) findViewById(R.id.image);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
private static int LOAD_IMAGE_RESULTS = 1;
#Override
//semmi
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
}
and the xml:
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Click here" />
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
but if I run this I can just pick one photo from my gallery and I need all of them in a view.
you need to use putExtra on intent like this:
// ImageView image = (ImageView) findViewById(R.id.image);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
N.B. Works in API 18 and higher.
I am doing an app in which user selects an image from gallery and goes to second activity with the selected image from gallery and displays it in second activity.But it takes some time(approx 3 sec) to go to second activity after user clicks on an image in gallery.I want to display progress bar circle for that much of time after the user selects an image from gallery and want to make progress bar circle invisible when execution moves to second activity.I am not getting any idea how to do my task?Should I use any AsyncTask?Please help me.I am stuck here.
I am providing my sample code.
My first Activity is
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class LauncherActivity extends Activity
{
private static int RESULT_LOAD_IMAGE = 2;
ImageButton gallery;
Bitmap bitmap_for_gallery;
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(R.layout.launcher);
gallery = (ImageButton)findViewById(R.id.select_photo);
gallery.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent gallery_intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(gallery_intent, RESULT_LOAD_IMAGE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
ProgressDialog progress=new ProgressDialog(getApplicationContext());
progress.setIndeterminate(true);
progress.setTitle("Please wait");
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progress.show();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
progress.dismiss();
Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
intent.putExtra("path", picturePath);
startActivity(intent);
}
}
}
my first activity xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/homepage"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"/>
<ImageButton
android:id="#+id/select_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="126dp"
android:background="#android:color/transparent"
android:src="#drawable/select_photo" />
</RelativeLayout>
my second activity is
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;
public class MainActivity extends Activity {
ImageView background;
Bitmap transfered;
FrameLayout.LayoutParams layoutParams;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
background=(ImageView)findViewById(R.id.imageView1);
layoutParams=new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
Bundle extras = getIntent().getExtras();
String picturePath=extras.getString("path");
transfered=BitmapFactory.decodeFile(picturePath);
background.setImageBitmap(transfered);
background.setAdjustViewBounds(true);
background.setLayoutParams(layoutParams);
}
}
My second activity xml is
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.progressbarcircle.MainActivity"
tools:ignore="MergeRootFrame" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_gravity="center" />
</FrameLayout>
Thanks in advance.please help me.
If your first Activity is taking too much time create a ProgressDialog object and show() it after
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
and dismiss() it before startActivity(intent);
You can do the same for the second Activity if it takes too long.
making a simple app, the problem I am having now is that when im using an intent to launch the camera app to take a picture, the app is supposed to take the picture and overwrite the imageview which was for the background image. What its doing is bring the freshly taken picture and displaying it sideways.
this is my main java file:
package com.example.piktuur;
import java.io.File;
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.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
public class PiktuurMain extends Activity {
private Uri outputFileUri;
private static int TAKE_PICTURE = 1;
private ImageView image;
private SeekBar adjust;
public int height, width;
public boolean proceede;
public File file;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.piktuur_main);
image = (ImageView) findViewById(R.id.imageView1);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.piktuur_main, menu);
return true;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
BitmapFactory.Options options = new BitmapFactory.Options();
String file = Environment.getExternalStorageDirectory() + "/image.png";
Bitmap bitmap = BitmapFactory.decodeFile(file, options);
image.setImageBitmap(bitmap);
}
}
public void cameraClicked(View V){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "image.png");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
public void shareClicked(View V){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "stephen.w.protzman#gmail.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Piktuur");
intent.putExtra(Intent.EXTRA_TEXT, "Here is a picture for you!");
startActivity(Intent.createChooser(intent, "Send Email"));
}
}
and here is the main xml with the imageview in it:
<RelativeLayout 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"
tools:context=".PiktuurMain" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="fitXY"
android:src="#drawable/pic" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp" >
<ImageButton
android:id="#+id/takepic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/round"
android:onClick="cameraClicked"
android:src="#android:drawable/ic_menu_camera" />
<ImageButton
android:id="#+id/editpic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_weight="1"
android:background="#drawable/round"
android:src="#android:drawable/ic_menu_edit" />
<ImageButton
android:id="#+id/sharepic"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/round"
android:onClick="shareClicked"
android:src="#android:drawable/ic_menu_share" />
</LinearLayout>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentLeft="true" />
</RelativeLayout>
I have zero ideas why this is happening any clue?
try this
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
image.setImageBitmap(bitmap);
}
}