Example usage for android.graphics Paint setAlpha

List of usage examples for android.graphics Paint setAlpha

Introduction

In this page you can find the example usage for android.graphics Paint setAlpha.

Prototype

public void setAlpha(int a) 

Source Link

Document

Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.

Usage

From source file:Main.java

/**
 * Changes the paint color to transparent
 *
 * @param paint the object to mutate with the new color
 *//*w w  w  .  j  a v  a 2 s .c  o m*/
public static void changePaintTransparent(Paint paint) {
    paint.setAlpha(0x00);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
}

From source file:Main.java

public static Bitmap setShadow(Bitmap bitmap, int radius) {
    BlurMaskFilter blurFilter = new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER);
    Paint shadowPaint = new Paint();
    shadowPaint.setAlpha(50);
    shadowPaint.setColor(0xff424242);//ww  w . j a  v  a2 s.c om
    shadowPaint.setMaskFilter(blurFilter);
    int[] offsetXY = new int[2];
    Bitmap shadowBitmap = bitmap.extractAlpha(shadowPaint, offsetXY);
    Bitmap shadowImage32 = shadowBitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas c = new Canvas(shadowImage32);
    c.drawBitmap(bitmap, -offsetXY[0], -offsetXY[1], null);
    return shadowImage32;
}

From source file:Main.java

public static final Bitmap complementedBitmapByAlpha(Bitmap bitmap) {
    if (null == bitmap) {
        return null;
    }/*from www . j  a  v  a  2 s  . c om*/

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (width == height) {
        return bitmap;
    }

    int len = width > height ? width : height;
    Bitmap output = Bitmap.createBitmap(len, len, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setAlpha(0);
    canvas.drawPaint(paint);

    if (width > height) {
        int devide = (width - height) / 2;
        canvas.drawBitmap(bitmap, 0, devide, paint_comm);
    } else {
        int devide = (height - width) / 2;
        canvas.drawBitmap(bitmap, devide, 0, paint_comm);
    }
    return output;
}

From source file:com.daycle.daycleapp.custom.swipelistview.itemmanipulation.dragdrop.BitmapUtils.java

/**
 * Returns a bitmap showing a screenshot of the view passed in.
 *//*w w  w .j ava2  s  .  c om*/
@NonNull
static Bitmap getBitmapFromView(@NonNull final View v) {
    Bitmap bitmap = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Paint p = new Paint();
    p.setColor(ContextCompat.getColor(v.getContext(), R.color.colorAccent));
    p.setAlpha(50);
    //v.setBackgroundColor(ContextCompat.getColor(v.getContext(), android.R.color.transparent));
    v.draw(canvas);
    //canvas.drawCircle((float)(v.getWidth() / 2), (float)(v.getHeight() / 2), 10, p);
    canvas.drawRect(new Rect(0, 0, v.getWidth(), v.getHeight()), p);
    return bitmap;
}

From source file:Main.java

/**
 * Changes the paint color to the specified value.
 *
 * @param paint the object to mutate with the new color
 * @param argb a 32-bit integer with eight bits for alpha, red, green, and blue,
 *        respectively/*from  w  w w. j a va  2s . c om*/
 */
public static void changePaint(Paint paint, int argb) {
    // TODO(user): can the following two lines can be replaced by:
    // paint.setColor(argb)?
    paint.setColor(argb & 0x00FFFFFF);
    paint.setAlpha((argb >> 24) & 0xFF);
    paint.setXfermode(null);
}

From source file:ca.psiphon.ploggy.Robohash.java

public static Bitmap getRobohash(Context context, boolean cacheCandidate, byte[] data)
        throws Utils.ApplicationError {
    try {/*from   w w  w  .  ja  v  a 2  s  . c  o  m*/
        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
        byte[] digest = sha1.digest(data);

        String key = Utils.formatFingerprint(digest);
        Bitmap cachedBitmap = mCache.get(key);
        if (cachedBitmap != null) {
            return cachedBitmap;
        }

        ByteBuffer byteBuffer = ByteBuffer.wrap(digest);
        byteBuffer.order(ByteOrder.BIG_ENDIAN);
        // TODO: SecureRandom SHA1PRNG (but not LinuxSecureRandom)
        Random random = new Random(byteBuffer.getLong());

        AssetManager assetManager = context.getAssets();

        if (mConfig == null) {
            mConfig = new JSONObject(loadAssetToString(assetManager, CONFIG_FILENAME));
        }

        int width = mConfig.getInt("width");
        int height = mConfig.getInt("height");

        JSONArray colors = mConfig.getJSONArray("colors");
        JSONArray parts = colors.getJSONArray(random.nextInt(colors.length()));

        Bitmap robotBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas robotCanvas = new Canvas(robotBitmap);

        for (int i = 0; i < parts.length(); i++) {
            JSONArray partChoices = parts.getJSONArray(i);
            String selection = partChoices.getString(random.nextInt(partChoices.length()));
            Bitmap partBitmap = loadAssetToBitmap(assetManager, selection);
            Rect rect = new Rect(0, 0, width, height);
            Paint paint = new Paint();
            paint.setAlpha(255);
            robotCanvas.drawBitmap(partBitmap, rect, rect, paint);
            partBitmap.recycle();
        }

        if (cacheCandidate) {
            mCache.set(key, robotBitmap);
        }

        return robotBitmap;

    } catch (IOException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    } catch (JSONException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    } catch (NoSuchAlgorithmException e) {
        throw new Utils.ApplicationError(LOG_TAG, e);
    }
}

From source file:Main.java

public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);/*  w w  w .ja v a2 s.  c  o m*/
    paint.setColor(Color.WHITE);
    paint.setDither(false);
    Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    Matrix m = new Matrix();
    m.setScale(contour.getWidth() * 1.0f / background.getWidth(),
            contour.getHeight() * 1.0f / background.getHeight());
    paint.setAlpha((int) (alpha * 0xff));
    canvas.drawBitmap(background, m, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    paint.setAlpha(0xff);
    canvas.drawBitmap(contour, 0, 0, paint);
    return bitmap;
}

From source file:ee.ioc.phon.android.speak.Utils.java

static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) {
    final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(b);
    final Paint paint = new Paint();
    paint.setColor(0xFFFFFFFF); // 0xAARRGGBB
    paint.setAntiAlias(true);// ww w.j  ava  2s.  com
    paint.setStyle(Paint.Style.STROKE);
    paint.setAlpha(80);

    final PathEffect effect = new CornerPathEffect(3);
    paint.setPathEffect(effect);

    final int numSamples = waveBuffer.remaining();
    int endIndex;
    if (endPosition == 0) {
        endIndex = numSamples;
    } else {
        endIndex = Math.min(endPosition, numSamples);
    }

    int startIndex = startPosition - 2000; // include 250ms before speech
    if (startIndex < 0) {
        startIndex = 0;
    }
    final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples
    final float scale = 10.0f / 65536.0f;

    final int count = (endIndex - startIndex) / numSamplePerWave;
    final float deltaX = 1.0f * w / count;
    int yMax = h / 2;
    Path path = new Path();
    c.translate(0, yMax);
    float x = 0;
    path.moveTo(x, 0);
    for (int i = 0; i < count; i++) {
        final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave);
        int sign = ((i & 01) == 0) ? -1 : 1;
        final float y = Math.min(yMax, avabs * h * scale) * sign;
        path.lineTo(x, y);
        x += deltaX;
        path.lineTo(x, y);
    }
    if (deltaX > 4) {
        paint.setStrokeWidth(2);
    } else {
        paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05)));
    }
    c.drawPath(path, paint);
    return b;
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvas//w  ww. ja va  2s.co  m
 */
private void drawRadar(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setAlpha(100);

    float rotation = currentRotation; //gRotationZ_deg + initialMapRotation;

    for (int i = -35; i < 35; i = i + 2) {
        float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45);
        float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45);
        canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint);

    }

    paint.setAlpha(100);
    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 7, paint);

    paint.setColor(Color.YELLOW);
    canvas.drawCircle(translateX, translateY, 6, paint);

    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 1, paint);
}

From source file:project.pamela.slambench.fragments.TemperaturePlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }/* w  w  w  . j  a  v a  2  s .com*/

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setBackgroundColor(Color.WHITE);
    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_degrees));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    int strokecolor = Color.rgb(67, 137, 192);
    int fillcolor = Color.rgb(213, 229, 255);

    Double temperatureNumbers[] = value.gettemperatureList();
    XYSeries series = new SimpleXYSeries(Arrays.asList(temperatureNumbers),
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, this.getResources().getString(R.string.legend_degrees));
    LineAndPointFormatter seriesFormat = new LineAndPointFormatter(strokecolor, strokecolor, null, null);

    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    DisplayMetrics metrics = new DisplayMetrics();
    super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    lineFill.setShader(
            new LinearGradient(0, 0, 0, metrics.heightPixels, Color.WHITE, fillcolor, Shader.TileMode.MIRROR));
    seriesFormat.setPointLabeler(new PointLabeler() {
        @Override
        public String getLabel(XYSeries series, int index) {
            return "o";
        }
    });
    seriesFormat.setFillPaint(lineFill);
    plot.addSeries(series, seriesFormat);

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF minXY = new PointF(plot.getCalculatedMinX().floatValue(), plot.getCalculatedMinY().floatValue());
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(Math.min(0, minXY.y), maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}