• Advertisement
Sign in to follow this  

Retrieving a fullsize camera preview from URI

This topic is 1673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

 

I'd like my app to let the user take or choose a picture, have that picture saved in the memory, and be able to edit the picture via the URI.

 

Here's a general outline:

In the main activity: take a picture or choose a picture from library, and send the URI to editing activity


public void openCamera(View view)
	{
		Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
		startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
	}
	
	public void openLibrary(View view)
	{
		Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
		photoPickerIntent.setType("image/*");
		startActivityForResult(photoPickerIntent, LIBRARY_PIC_REQUEST);
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) 
	{
		Uri path = data.getData();
		
	    Intent intent = new Intent(this, StickerActivity.class);
	    intent.putExtra(EXTRA_MESSAGE, path);

	    startActivity(intent);
	}

In editing activity: drawClass is a custom View class

protected void onCreate(Bundle savedInstanceState)    
	{ 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_editing);
		drawClass = (DrawClass) findViewById(R.id.myDrawClass);		
		
		Bundle retrievedExtras = getIntent().getExtras();
		int stickerType = retrievedExtras.getInt(StickerActivity.SELECTED_MESSAGE);
		Uri picturePath = retrievedExtras.getParcelable(MainActivity.EXTRA_MESSAGE);
		
		drawClass.setStickerType(stickerType);
.....

in drawClass.java:

drawClass extends screen, and I'm currently able to view the picture that the user chose by resizing the image.  However this makes the image skewed and uneven; I'd like to have the picture be the same resolution and dimensions as the preview is.

private Bitmap getResizedBitmap(Bitmap bm) 
	{ 
		int width = bm.getWidth();		 
		int height = bm.getHeight();		 
		float scaleWidth = ((float) this.viewWidth) / width;		 
		float scaleHeight = ((float) this.viewHeight) / height;		 
		// create a matrix for the manipulation		 
		Matrix matrix = new Matrix();
		 
		// resize the bit map		 
		matrix.postScale(scaleWidth, scaleHeight);
		 
		// recreate the new Bitmap		 
		Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);		 
		
		return resizedBitmap;		 
	}

public void setChosenPicture(Bitmap bitmap)
	{
		this.chosenPicture = this.getResizedBitmap(bitmap);
	}

So, right now I'm successfully displaying a resized version of the chosen picture to fit the whole screen, which makes it skewed and awkward.  I'd like to retrieve the same picture that gets displayed in the preview after taking a picture, send it through an activity, and display it on a custom view.

 

Also, I plan on making buttons such as "Save"and "Clear" at the bottom of the picture in a small horizontal frame (for example, 1/10th of the screen height and all of the screen width); would I have to make another View class on top of the drawClass to do this?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement