Note that there are some explanatory texts on larger screens.

plurals
  1. POPass image from activity to custom view edit
    text
    copied!<p>I had create an Activity class and CustomView class. The Activity class able retrieve image from local storage(gallery) and show as ImageView. The CustomView class is build with basic drawing feature such as doodle, erase, save.</p> <p>The question is: After I get the image from gallery, I need to pass the image from Activity class to CustomView class for edit. How should I do that ?</p> <p>Here is my CustomView class (I had remove the unnecessary code, only show the method name):</p> <pre><code>class DrawView extends View { public DrawView(Context context, AttributeSet attrs){ super(context, attrs); setupDrawing(); } private void setupDrawing(){ } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); drawCanvas = new Canvas(canvasBitmap); } @Override public boolean onTouchEvent(MotionEvent event) { float touchX = event.getX(); float touchY = event.getY(); //respond to down, move and up events //redraw the view } //draw view - after touch event @Override protected void onDraw(Canvas canvas) { canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); canvas.drawPath(drawPath, drawPaint); } } </code></pre> <p>And this is my MainActivity class:</p> <pre><code>public class MainActivity extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //call the custom drawing view drawView = (DrawView)findViewById(R.id.drawable); } @Override public void onClick(View view){ if(view.getId()==R.id.Go){ Intent i = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_IMAGE); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; 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(); Intent i = new Intent(this, DrawView.class); i.putExtra(picturePath, true); } } </code></pre> <p>I had testing the get image method by using ImageView and it is success. The question is how i pass the image to CustomView and edit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload