b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.new_main);
String editTextStr = text.getText().toString();
Toast msg = Toast.makeText(getBaseContext(),"/sdcard/Stored_Images/" + editTextStr + ".jpg", Toast.LENGTH_LONG);
msg.show();
Bitmap bmp = BitmapFactory.decodeFile("/sdcard/Stored_Images/" + editTextStr + ".jpg");
ImageView img = (ImageView) findViewById(R.id.ImageView01);
img.setImageBitmap(bmp);
}
});
The code above displays an image on the screen that is saved on the sd card.
Canvas c = holder.lockCanvas();
c.drawARGB(255,0,0,0);
onDraw(c);
holder.unlockCanvasAndPost(c);
This code creates a canvas to draw on (black screen).
I want to be able to combine the two to set/display an image as the canvas so that I can draw on it. So if i take a picture of someones face, I want to be able to display that image so that I can draw a mustache or something on it.
Luckily, drawing on photos on your Android is super easy! Google Photos is a free default app that comes pre-installed on most Androids and has a few new features that will allow Android users to markup and draw on existing photos. If you have a Samsung phone, you also have a photo editor pre-installed on your Android!
You are probably better off creating the canvas, adding the bitmap image to it and then handling the user touch/drawing from there.
Bitmap bmp = BitmapFactory.decodeFile("/sdcard/Stored_Images/" + editTextStr + ".jpg");
mCanvas = new Canvas(bmp);
then for the drawing... sound like you have that figured out, but if not you can check out the fingerPaint samples from the api demos that demonstrate drawing on a canvas (which you would have your image on at that point.)
You may customize the ImageView and made drawing on your image in onDraw(Canvas canvas)
For Example:
In your Activity:
1)create Bitmap from the image
2)set the Bitmap to customized ImageView
a) create object for customized ImageView
MyImageView view =new MyImageView(this);
b) set the bitmap
view.setImageBitmap(bmp);
MyImageView.java:
class MyImagView extends ImageView{
//constructor
public MyImageView(Context context){
}
//onDraw()
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//drawlines where ever you want using canvas.drawLine()
}
@Override
public void setImageBitmap(Bitmap bm)
{
super.setImageBitmap(bm);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With