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 8786161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:32:46+00:00 2026-06-13T21:32:46+00:00

I have this code snippet. I don’t understand the Matrix.preScale and the Bitmap.createBitmap with

  • 0

I have this code snippet. I don’t understand the Matrix.preScale and the Bitmap.createBitmap with the matrix passed. What does it mean? Is there any simulation website to understand matrix calculation? Could you give me some websites about mathematics used for graphics? I’m sorry I’m not good at mathematics. 🙂

public Bitmap createReflectedImages(final Bitmap originalImage) {
    final int width = originalImage.getWidth();
    final int height = originalImage.getHeight();
    final Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    final Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, (int) (height * imageReflectionRatio),
            width, (int) (height - height * imageReflectionRatio), matrix, false);
    final Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (int) (height + height * imageReflectionRatio + 400),
            Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(originalImage, 0, 0, null);
    final Paint deafaultPaint = new Paint();
    deafaultPaint.setColor(color.transparent);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}
  • 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-13T21:32:47+00:00Added an answer on June 13, 2026 at 9:32 pm

    Don’t think about it too hard, at least not at the early stages.

    Just think of a matrix as an array of numbers. In this case, an Android Matrix has 3 rows of 3 numbers. Each number tells an Android graphics function what to do to scale (bigger/smaller), translate (move), rotate (turn) or skew (distort in a 2D plane) the "thing" which the matrix is applied to.

    The matrix looks like this (see the docs here).

    {Scale X, Skew X, Transform X
    Skew Y, Scale Y, Transform Y
    Perspective 0, Perspective 1, Perspective 2}
    

    The good news is that you don’t need to know any matrix maths, indeed almost no maths, to use matrices in Android. That’s what methods like preScale() do for you. To understand the maths behind is not that hard, for most things you only need add, multiply and SOHCAHTOA.

    matrix-transform-for-the-mathematically-challenged/

    When you read the Matrix documentation, you will see methods for rotate, translate etc with prefixes of ‘set’, ‘post’ or ‘pre’.

    Imagine that you create a new matrix. You then use setRotate() to setup the matrix to do a rotation. You then use preTranslate() to do a translation. Because you used ‘pre’, the translation happens before the rotation. Had you used ‘post’, the rotation would happen first. ‘set’ clears whatever is in the matrix and starts again.

    To answer your specific question, new Matrix() creates the ‘identity matrix’

    {1, 0, 0
     0, 1, 0
     0, 0, 1}
    

    which scales by 1 (therefore same size) and does no translation, rotation or skew. Therefore, applying the identity matrix will do nothing. The next method is preScale() which is applied to this identity matrix and in the case you’ve shown, results in a matrix that scales, and does nothing else so could also be done using setScale() or postScale().

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

Sidebar

Related Questions

In a code-snippet I have seen this: size_t w = CGImageGetWidth(inImage); The docs don't
I have this code snippet: $(function() { $('.toolbar [id^=button]').on('click', function () { $(this) .css('background-color',
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
I have this code snippet inside a function that checks if an object exists
I have this code snippet: DateFormat formatter1; formatter1 = new SimpleDateFormat(mm/DD/yyyy); System.out.println((Date)formatter1.parse(08/16/2011)); When I
I have this code snippet in an email layout: <div> <?php echo $this->Html->image('Layouts/default/Logo.png', array(
VS 2008 I have this code snippet I found on a VB website. But
I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
Let us say if I have a Perl module Resounces.pm with this code snippet
I have this snippet of code: var ShopLogicOptions = {}; ShopLogicOptions.params = {orderId: '

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.