Example usage for android.graphics Canvas drawARGB

List of usage examples for android.graphics Canvas drawARGB

Introduction

In this page you can find the example usage for android.graphics Canvas drawARGB.

Prototype

public void drawARGB(int a, int r, int g, int b) 

Source Link

Document

Fill the entire canvas' bitmap (restricted to the current clip) with the specified ARGB color, using srcover porterduff mode.

Usage

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makeBMP(CalculationResult res) {

    Bitmap bmp = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);//  w w  w .  j  av  a 2  s. c  o  m
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    /* Path pth = new Path();
     pth.addArc(10, 20, 390, 790, 0, 360);
            
     p.setColor(Color.argb(20, 10, 10, 10));
     p.setTextSize(30);
     String watermark = "";
     for (int i = 0; i < 15; i++) {
     watermark += "  ";
     }
     canvas.drawTextOnPath(watermark, pth, 0, 0, p);*/
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.png");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "image/*");
        startActivity(intent);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
    }

}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

void makePDF(CalculationResult res) {

    PdfDocument doc = new PdfDocument();
    PdfDocument.PageInfo inf = new PdfDocument.PageInfo.Builder(400, 800, 1).create();
    PdfDocument.Page page = doc.startPage(inf);

    Canvas canvas = page.getCanvas();

    //canvas.drawARGB(155, 253, 255, 253);
    canvas.drawARGB(255, 255, 255, 255);
    Paint p = new Paint();
    p.setTypeface(Utility.getNazaninFont());
    p.setTextSize(25);//from   w ww  . j av a  2 s . co m
    p.setAntiAlias(true);

    int y = 20;
    Drawable d = getResources().getDrawable(R.drawable.abfa);
    d.setBounds(100, 10, 300, 210);
    d.draw(canvas);
    p.setTextAlign(Paint.Align.CENTER);
    y += 210;
    canvas.drawText("   ?  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText("  ", 200, y, p);
    y += 40;
    canvas.drawText(":" + Utility.NowDate(), 200, y, p);
    y += 40;
    canvas.drawText("___________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.CustomerNumber, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.Title, 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.BillAmount), 200, y, p);
    y += 40;
    canvas.drawText(" :" + Seprate3(res.PreviousDebt), 200, y, p);

    y += 40;
    Paint p1 = new Paint();
    p1.setTypeface(Utility.getNazaninFont());
    p1.setARGB(255, 0, 0, 0);
    p1.setAntiAlias(true);
    p1.setStrokeWidth(40);
    p1.setStyle(Paint.Style.STROKE);
    canvas.drawLine(10, y, 390, y, p1);
    p.setARGB(255, 255, 255, 255);
    canvas.drawText("  :" + Seprate3(res.TotalAmount) + " ", 200, y, p);
    p.setARGB(255, 0, 0, 0);

    y += 40;
    canvas.drawText("__________________________", 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.BillIdentifier, 200, y, p);
    y += 40;
    canvas.drawText(" :" + res.PaymentIdentifier, 200, y, p);

    doc.finishPage(page);
    //File file = new File(getCacheDir()+ "/billing.png");
    File file = new File("/sdcard/billing.pdf");
    FileOutputStream outfile;
    try {
        outfile = new FileOutputStream(file);
        //bmp.compress(Bitmap.CompressFormat.PNG, 100, outfile);
        doc.writeTo(outfile);
        doc.close();

        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_VIEW);
        //intent.setDataAndType(Uri.fromFile(file), "image/*");
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        startActivity(intent);
        //new RetrieveFeedTask().execute(bmp);

    } catch (Exception ex) {
        Log.e("error", ex.toString());
        new AlertDialog.Builder(this).setMessage(
                "    ? pdf    ? \n https://cafebazaar.ir/app/com.kdanmobile.android.pdfreader.google.pad/?l=fa   ")
                .show();
    }

}

From source file:me.tb.player.SkeletonActivity.java

@Override
public Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);//w w  w. j  a v  a  2  s .  c o  m
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:com.android.mms.ui.MessageUtils.java

public static Bitmap getCircularBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = bitmap.getWidth() / 2;

    paint.setAntiAlias(true);//from ww  w .  j  a  v  a2s  . c  om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}