Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9091223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:33:34+00:00 2026-06-16T22:33:34+00:00

I have a Bitmap object in my main class. I need to send this

  • 0

I have a Bitmap object in my main class. I need to send this bitmap to my custom view class to set it as a background for further processing on canvas.

For example, there is a method called setPicture that receives bitmap as a parameter. So, how it is possible to draw this bitmap on the canvas?

Please see the code below:

public class TouchView extends View {

 final int MIN_WIDTH = 75;
 final int MIN_HEIGHT = 75;
 final int DEFAULT_COLOR = Color.RED;
 int _color;
 final int STROKE_WIDTH = 2;

private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private float x, y;
private boolean touching = false;

public TouchView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
    init();
}

public TouchView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    init();
}

public TouchView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    init();
}

private void init() {
    setMinimumWidth(MIN_WIDTH);
    setMinimumHeight(MIN_HEIGHT);
    _color = DEFAULT_COLOR;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO Auto-generated method stub
    setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
            MeasureSpec.getSize(heightMeasureSpec));
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);

    if (touching) {
        paint.setStrokeWidth(STROKE_WIDTH);
        paint.setColor(_color);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawCircle(x, y, 75f, paint);
    }
}

public void setPicture (Bitmap bitmap) {

        ///////
         This method must receive my bitmap to draw it on canvas!!!!!!!!!!!!!!!
        ///////


}

public void setColor(int color) {
    _color = color;
}

@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
    // TODO Auto-generated method stub

    switch (motionEvent.getAction()) {
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_DOWN:
        x = motionEvent.getX();
        y = motionEvent.getY();
        touching = true;
        break;
    default:
        touching = false;
    }
    invalidate();
    return true;
}

}

How should I send this bitmap to onDraw?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:33:35+00:00Added an answer on June 16, 2026 at 10:33 pm

    Inside your onDraw() method,

    just do

    canvas.drawBitmap(myBitmap, 0, 0, null);
    

    myBitmap is your bitmap variable.

    0,0 refers to the coordinates to draw at, aka the top left corner.

    There are other Apis available, to draw to certain areas etc.

    More info can be found here in the api docs.

    Alternatively:
    extend ImageView instead, and use setImageBitmap(Bitmap src); method to achieve this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Bitmap object from this I need to extract a sub image
I have a Bitmap object that I need to sometimes flip horizontally, sometimes vertically,
I have a android.graphics.Bitmap object that I draw on my canvas, what I am
I have a bitmap object and draw some curves on it by setpixel method.
I have method that returns Drawable , and if its Bitmap object is recycled
I have a bitmap image context and want to let this appear blurry. So
I have a simple question. I have this bitmap Is there a way with
I have a bitmap that I need to rotate an arbitrary number of degrees
I have 1 bitmap object witdh : 1024px and height : 768 px I
If you have a Bitmap object that needs to be passed to numerous methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.