Android Open Source - mobilepower-android Graphic Tools






From Project

Back to project page mobilepower-android.

License

The source code is released under:

Apache License

If you think the Android project mobilepower-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Dario Scoppelletti, <http://www.scoppelletti.it/>.
 * // w w w  .ja  v a2 s  .com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package it.scoppelletti.mobilepower.graphics;

import android.graphics.*;

/**
 * Funzioni di utilit&agrave; grafica.
 * 
 * @since 1.0
 */
public final class GraphicTools {

    /**
     * Costruttore privato per classe statica.
     */
    private GraphicTools() {        
    }
    
    /**
     * Imposta la dimensione di campionamento per la decodifica di
     * un&rsquo;immagine in funzione della dimensione di visualizzazione
     * dell&rsquo;immagine stessa.
     * 
     * @param opts       Opzioni di decodifica dell&rsquo;immagine tra le quali
     *                   deve essere gi&agrave; impostata la dimensione
     *                   originale dell&rsquo;immagine
     *                   {@code (outWidth, outHeight)} e sulla quale sar&agrave;
     *                   impostata la dimensione di campionamento
     *                   {@code inSampleSize}.  
     * @param viewWidth  Larghezza di visualizzazione dell&rsquo;immagine.
     * @param viewHeight Altezza di visualizzazione dell&rsquo;immagine.
     */
    public static void setSampleSize(BitmapFactory.Options opts, int viewWidth,
            int viewHeight) {
        int size, size2;
        float scale, scaleX, scaleY;

        if (opts == null) {
            throw new NullPointerException("Argument opts is null.");
        }
        if (opts.outWidth <= 0 || opts.outHeight <= 0) {
            throw new IllegalArgumentException(
                    "Original size is not properly determinated.");
        }
        if (viewWidth <= 0) {
            throw new IllegalArgumentException(
                    "Argument viewWidth must be > 0.");            
        }
        if (viewHeight <= 0) {
            throw new IllegalArgumentException(
                    "Argument viewWidth must be > 0.");            
        }
        
        opts.inSampleSize = 1;
        if (opts.outWidth <= viewWidth && opts.outHeight <= viewHeight) {
            return;
        }
        
        scaleX = ((float) opts.outWidth) / ((float) viewWidth);
        scaleY = ((float) opts.outWidth) / ((float) viewWidth);
        scale = (scaleX < scaleY) ? scaleX : scaleY;
        if (scale <= 1.0) {
            return;            
        }
        
        // La decodifica e' piu' veloce e' efficiente se la dimensione di
        // campionamento e' una potenza di 2        
        size2 = Math.round(Math.getExponent(scale));
        if (size2 <= 1) {
            return;                        
        }
        
        size = 1;
        size <<= size2;
        opts.inSampleSize = size;
    }
}




Java Source Code List

it.scoppelletti.mobilepower.app.AboutActivity.java
it.scoppelletti.mobilepower.app.AbstractActivity.java
it.scoppelletti.mobilepower.app.AbstractDialogFragment.java
it.scoppelletti.mobilepower.app.AbstractFragment.java
it.scoppelletti.mobilepower.app.AbstractPreferenceActivity.java
it.scoppelletti.mobilepower.app.ActionBarCompat.java
it.scoppelletti.mobilepower.app.ActionBarSupport.java
it.scoppelletti.mobilepower.app.ActivitySupport.java
it.scoppelletti.mobilepower.app.AppUtils.java
it.scoppelletti.mobilepower.app.CommonMenuFragment.java
it.scoppelletti.mobilepower.app.ConfirmDialogFragment.java
it.scoppelletti.mobilepower.app.DatePickerDialogFragment.java
it.scoppelletti.mobilepower.app.FragmentLayoutController.java
it.scoppelletti.mobilepower.app.FragmentSupport.java
it.scoppelletti.mobilepower.app.HelpActivity.java
it.scoppelletti.mobilepower.app.HelpDialogFragment.java
it.scoppelletti.mobilepower.app.MarketTagHandler.java
it.scoppelletti.mobilepower.app.ProgressDialogFragment.java
it.scoppelletti.mobilepower.app.ReleaseNoteActivity.java
it.scoppelletti.mobilepower.app.bluetooth.ActivityBTManager.java
it.scoppelletti.mobilepower.app.data.DatabaseConnectionManager.java
it.scoppelletti.mobilepower.app.data.DatabaseUpgradeTask.java
it.scoppelletti.mobilepower.app.security.ActivityLicenseClient.java
it.scoppelletti.mobilepower.app.security.LicenseBuyDialogFragment.java
it.scoppelletti.mobilepower.app.security.LicenseDemoDialogFragment.java
it.scoppelletti.mobilepower.app.security.LicenseRetryDialogFragment.java
it.scoppelletti.mobilepower.bluetooth.BTManager.java
it.scoppelletti.mobilepower.bluetooth.BTTask.java
it.scoppelletti.mobilepower.bluetooth.OnBTListener.java
it.scoppelletti.mobilepower.data.DatabaseUpgrader.java
it.scoppelletti.mobilepower.data.OnDatabaseConnectionListener.java
it.scoppelletti.mobilepower.graphics.GraphicTools.java
it.scoppelletti.mobilepower.graphics.SizeF.java
it.scoppelletti.mobilepower.io.IOTools.java
it.scoppelletti.mobilepower.media.DefaultOnScanCompletedListener.java
it.scoppelletti.mobilepower.os.AbstractAsyncTask.java
it.scoppelletti.mobilepower.os.AsyncTaskController.java
it.scoppelletti.mobilepower.os.AsyncTaskHost.java
it.scoppelletti.mobilepower.os.BuildCompat.java
it.scoppelletti.mobilepower.preference.AbstractDialogPreference.java
it.scoppelletti.mobilepower.preference.BTDevicePreference.java
it.scoppelletti.mobilepower.preference.ColorPreference.java
it.scoppelletti.mobilepower.preference.EditTextPreferenceEx.java
it.scoppelletti.mobilepower.preference.IntegerSpinnerPreference.java
it.scoppelletti.mobilepower.preference.PreferenceSavedState.java
it.scoppelletti.mobilepower.preference.SeekBarPreference.java
it.scoppelletti.mobilepower.provider.ContactsContractCompat.java
it.scoppelletti.mobilepower.reflect.MemberCache.java
it.scoppelletti.mobilepower.security.LicenseClient.java
it.scoppelletti.mobilepower.types.SimpleDate.java
it.scoppelletti.mobilepower.types.StringTools.java
it.scoppelletti.mobilepower.types.TimeTools.java
it.scoppelletti.mobilepower.types.ValueTools.java
it.scoppelletti.mobilepower.types.ValueType.java
it.scoppelletti.mobilepower.view.ViewSavedState.java
it.scoppelletti.mobilepower.widget.CompoundControl.java
it.scoppelletti.mobilepower.widget.DateControl.java
it.scoppelletti.mobilepower.widget.ImageButtonCompat.java
it.scoppelletti.mobilepower.widget.IntegerSpinner.java
it.scoppelletti.mobilepower.widget.IntegerTextWatcher.java
it.scoppelletti.mobilepower.widget.WidgetTools.java