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

  • Home
  • SEARCH
  • 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 3979920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:45+00:00 2026-05-20T05:13:45+00:00

I created a custom View, with two Bitmaps. When I use the Bitmap outside

  • 0

I created a custom View, with two Bitmaps. When I use the Bitmap outside of my View, in an ImageView, the image is OK. I have to call setDensity(240) (hdpi device), but it’s ok.
However, in the custom View, when I draw the same Bitmap on a canvas, in the onDraw(Canvas) overridden method, it’s scaled again, the same way when I don’t call setDensity(240).
Via debugging, I ensured that the density of the canvas and bitmap is 240, after the call.

Code:

@Override
protected void onDraw(Canvas canvas) {    
    _ingredient.setDensity(240);
    canvas.setDensity(240);
    canvas.drawBitmap(_ingredient, new Matrix(), new Paint());
    Matrix refMatrix = new Matrix();
    refMatrix.postTranslate(0, _ingredient.getHeight()-35);
    Paint paint = new Paint();
    paint.setAlpha(60);
}

The working ImageView, outside of my View.

Bitmap tertr = _cocktail.getCocktailBitmapImage();
tertr.setDensity(240);
ImageView in = new ImageView(this);
in.setScaleType(ScaleType.CENTER);
in.setImageBitmap(tertr);
RelativeLayout relativeLayout = RelativeLayout)findViewById(R.id.cocktail_date_image_layout);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
relativeLayout.addView(in, params);

The first one is showing the image scaled up, just like the second one, without the setDensity call. The images were created at 72dpi. These images are given, I cannot change them. Am I missing one thing, or this is how Canvas works? The device used for testing is a DROID2.

  • 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-05-20T05:13:46+00:00Added an answer on May 20, 2026 at 5:13 am

    I solved the problem. The code snippet that caused the trouble was in the manifest file.
    We changed <supports-screens android:anyDensity="false"/> to true. True is the default, but unfortunately I changed that while I was trying different approaches. With the new value, and the setDensity() methods, it’s working.

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

Sidebar

Related Questions

I have created one gridview and use custom adapter for that. I added two
I have created one gridview and use custom adapter for that. I added two
I have created a custom view by extending Relative Layout and it looks like
I have my main program with MainAppDelegate.h,MainAppDelegate.m . I have created two custom navigation
I have created a custom view hierarchy in an XIB that I want to
I've created a custom view class and right now just want to draw an
In a word, how? I have a view controller that creates a few custom
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I currently have a simple list view adapter that holds two rows of text.

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.