Example usage for android.graphics Canvas drawBitmap

List of usage examples for android.graphics Canvas drawBitmap

Introduction

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

Prototype

public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull Rect dst, @Nullable Paint paint) 

Source Link

Document

Draw the specified bitmap, scaling/translating automatically to fill the destination rectangle.

Usage

From source file:com.cooltechworks.views.ScratchImageView.java

@Override
protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);
    canvas.drawBitmap(mScratchBitmap, 0, 0, mBitmapPaint);
    canvas.drawPath(mErasePath, mErasePaint);

}

From source file:com.samknows.measurement.activity.SamKnowsMapActivity.java

public void addMarkers() {
    GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    try {/*www .  ja va  2 s.  c  om*/

        JSONObject jsonObject;
        String dtime_formatted = "";
        String result = "";

        for (int i = 0; i < 20; i++) {
            GPSPlace GPSPlace_result = readArchiveItem(i);
            geoPoint = GPSPlace_result.geopoint;
            result = GPSPlace_result.result;

            Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.measurement_icon);
            Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas tempCanvas = new Canvas(bmResult);

            // tempCanvas.scale(0.5f,0.5f);
            tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
            int index = i + 1;
            map.addMarker(new MarkerOptions().position(geoPoint).snippet(result).title("" + index)
                    .icon(BitmapDescriptorFactory.fromBitmap(bmResult)));

            map.setInfoWindowAdapter(new MapPopup(getLayoutInflater()));

            map.setOnInfoWindowClickListener(this);

            List<LatLng> points = new ArrayList<LatLng>();
            int totalPonts = 30; // number of corners of the pseudo-circle
            for (int c = 0; c < totalPonts; c++) {
                points.add(getPoint(geoPoint, 30, c * 2 * Math.PI / totalPonts));
            }

            map.addPolygon(new PolygonOptions().addAll(points).fillColor(0x0550A050).strokeWidth(2)
                    .strokeColor(0x100A050));

        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    if (geoPoint != null) {

        CameraPosition camPos = new CameraPosition.Builder().target(geoPoint).zoom(18f).build();

        CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
        map.moveCamera(camUpdate);
    }
}

From source file:com.example.androidmillgame.GamePanel.java

protected void onDraw(Canvas canvas) {// ...................use.active.rendering.to.put.the.buffered.image.on-screen

    try {/*  w w  w . jav  a 2  s.  c  o m*/
        //...................................................................draw.the.background:.use.the.image.or.a.black.color
        canvas.drawRGB(0, 0, 0);
        canvas.drawBitmap(imgres.getImage("background"), background, backgroundRect, null);
        for (int i = 0; i < 24; i++) {// ..............................................................render.joints
            generatedJoints.Joints[i].Draw(canvas);
        }
        DraggablePoint.Draw(canvas);
        Display.Draw(canvas);
        if (GC.getGameOver())
            canvas.drawBitmap(imgres.getImage("resumeok"), null, resumeRect, null);
        else
            canvas.drawBitmap(imgres.getImage("resumenop"), null, resumeRect, null);
    } catch (Exception e) {
        Log.d(TAG, "Graphics context error: " + e);
    }
}

From source file:eu.trentorise.smartcampus.widget.shortcuts.StackWidgetService.java

@Override
public RemoteViews getViewAt(int position) {
    // position will always range from 0 to getCount() - 1.

    // We construct a remote views item based on our widget item xml
    // file, and set the
    // text based on the position.
    RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
    ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
    sd1.getPaint().setColor(0xFFFFFFFF);
    sd1.getPaint().setStyle(Style.STROKE);
    sd1.getPaint().setStrokeWidth(1);/*from   w w  w.j  a va  2 s  .c o  m*/
    Canvas c = new Canvas();
    sd1.draw(c);
    Bitmap b = Bitmap.createBitmap(120, 120, Bitmap.Config.ARGB_8888);
    c.drawBitmap(b, 0, 0, sd1.getPaint());
    // Next, we set a fill-intent which will be used to fill-in the
    // pending intent template
    // which is set on the collection view in StackWidgetProvider.

    if (ALLPREFERENCES != null && ALLPREFERENCES[position] != null) { //ALLPREFERENCES  dimensionato come le preferenze selezionate

        BookmarkDescriptor myDescriptor = ALLPREFERENCES[position];

        // set the widgetbutton
        if (WidgetHelper.PARAM_TYPE.equals(myDescriptor.params.get(0).name)) { //controllare con gli input da config activity?
            String type = myDescriptor.params.get(0).value;
            if (WidgetHelper.TYPE_DT.equals(type)) {
                // dt -> put icons and hide text
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));

                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_dt);

            } else if (WidgetHelper.TYPE_JP.equals(type)) {
                // jp -> put text and hide icon

                rv.setViewVisibility(R.id.image_widget_item, View.GONE);
                // rv.setImageViewBitmap(R.id.text_widget_item,
                // getBackground(Color.parseColor("#6EB046")));
                if (!("0".equals(myDescriptor.params.get(2).value))) {
                    //bus
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 80);

                    rv.setTextViewText(R.id.text_widget_item, RoutesHelper.getShortNameByRouteIdAndAgencyID(
                            myDescriptor.params.get(4).value, myDescriptor.params.get(3).value)); //4,3
                    rv.setTextColor(R.id.text_widget_item, Integer.parseInt(myDescriptor.params.get(2).value));//rv.setInt(R.id.text_widget_item, "setBackgroundColor",
                    //Integer.parseInt(myDescriptor.params.get(2).value));
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                } else {
                    //train
                    rv.setTextViewTextSize(R.id.text_widget_item, TypedValue.COMPLEX_UNIT_DIP, 12);
                    //controllo contesto getRouteDescriptor i vari parametri
                    rv.setTextViewText(R.id.text_widget_item,
                            mContext.getString(
                                    RoutesHelper.getRouteDescriptorByRouteId(myDescriptor.params.get(3).value,
                                            myDescriptor.params.get(4).value).getNameResource()));
                    rv.setTextColor(R.id.text_widget_item, Color.BLACK);//Int(R.id.text_widget_item, "setBackgroundColor",Color.BLACK);
                    rv.setInt(R.id.text_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

                }

            } else if (WidgetHelper.TYPE_JP_PARKINGS.equals(type)) {
                // jp parcheggio -> put text and hide icon
                rv.setViewVisibility(R.id.text_widget_item, View.GONE);
                rv.setImageViewResource(R.id.image_widget_item,
                        Integer.parseInt(myDescriptor.params.get(2).value));
                rv.setInt(R.id.image_widget_item, "setBackgroundResource", R.drawable.rounded_border_jp);

            }
            BookmarkDescriptor bookmark = myDescriptor;
            Bundle extras = new Bundle();
            extras.putString(StackWidgetProvider.EXTRA_INTENT, bookmark.getIntent());
            if (bookmark.getParams() != null) {
                for (Param param : bookmark.getParams()) {
                    extras.putString(param.name, param.value);

                }

            }
            Intent fillInIntent = new Intent(bookmark.getIntent());
            fillInIntent.putExtras(extras);
            rv.setOnClickFillInIntent(R.id.layout, fillInIntent);
        }

    }
    // Return the remote views object.
    // AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
    // manager.updateAppWidget(thisWidget, rv);
    return rv;
}

From source file:com.chrulri.droidoflife.MainActivity.java

private void doRender() {
    if (bitmap == null) {
        // bitmap not ready yet, wtf?!
        Log.w(TAG, "bitmap is null");
        return;//from  w  w  w . j  a va 2  s  .c o m
    }

    Canvas canvas = surface.lockCanvas();
    if (canvas == null) {
        // surface not ready yet, nothing to do!
        return;
    }

    LifeRuntime.render(bitmap, settingsCache);

    Rect dst = surface.getSurfaceFrame();
    canvas.drawBitmap(bitmap, null, dst, null);

    surface.unlockCanvasAndPost(canvas);
}

From source file:com.bdcorps.videonews.MainActivity.java

public void grabnews(String topicCode) {
    int pos = article;
    try {/* ww w  .j  a  v  a  2  s . co m*/

        JSONArray a = Config.initNewsRequest(topicCode);

        //  for (int i = 0; i<json.getInt("num_results");i++)
        {
            final JSONObject b = (JSONObject) a.get(article);
            JSONArray c = b.getJSONArray("multimedia");
            if (c.length() > 4) {
                JSONObject d = (JSONObject) c.get(4);
                String url = d.getString("url");
                final String title = b.getString("title");
                try {
                    new DownloadImageTask(new DownloadImageTask.AsyncResponse() {

                        @Override
                        public void processFinish(Bitmap result) {
                            Paint myRectPaint = new Paint();
                            int x1 = 0;
                            int y1 = 0;
                            int x2 = 500;
                            int y2 = 500;

                            //Create a new image bitmap and attach a brand new canvas to it
                            Bitmap tempBitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(),
                                    Bitmap.Config.RGB_565);
                            Canvas tempCanvas = new Canvas(tempBitmap);

                            //Draw the image bitmap into the cavas
                            tempCanvas.drawBitmap(result, 0, 0, null);

                            //Draw everything else you want into the canvas, in this example a rectangle with rounded edges
                            tempCanvas.drawRoundRect(new RectF(x1, y1, x2, y2), 2, 2, myRectPaint);
                            titleTextView.setText(title);
                            img.setImageBitmap(tempBitmap);
                        }
                    }, img).execute(url).get();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            text.setText(b.getString("abstract"));
                            Log.i("SSS", "abstract is = " + text.getText().toString());
                            canSpeak = true;
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
            } else {

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getBaseContext(), "multimedia does not exist", Toast.LENGTH_LONG).show();
                    }
                });
                article++;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:com.emmaguy.todayilearned.PanView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mBlurAmount < 1f) {
        if (mScaledImage != null) {
            canvas.drawBitmap(mScaledImage, mOffsetX, mOffsetY, null);
        }//from w  w  w .j av a  2 s.c om
    }
    if (mBlurAmount > 0f) {
        if (mBlurredImage != null) {
            mDrawBlurredPaint.setAlpha((int) (mBlurAmount * 255));
            canvas.drawBitmap(mBlurredImage, mOffsetX, mOffsetY, mDrawBlurredPaint);
        }
    }
    drawEdgeEffects(canvas);
}

From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java

private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {

    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 = pixels;

    paint.setAntiAlias(true);/*from ww w.j a va2 s.  c o  m*/
    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;
}

From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java

/**
 * Draws the view/*from   w w  w. jav a2s . c  o m*/
 *
 * @param canvas canvas to paint to
 */
@Override
protected void onDraw(Canvas canvas) {
    if (bitMapIsInvalid) {
        updateRollingGraph();
    }
    if (rollingGraphBitmap != null) {
        canvas.drawBitmap(rollingGraphBitmap, 0, 0, null /* no paint? */);
    }
}

From source file:com.berniesanders.fieldthebern.views.MapScreenView.java

private Bitmap colorBitmap(final Bitmap bm, int color) {

    Paint paint = new Paint();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    paint.setColorFilter(filter);//from   w ww  .  j  a va  2  s . c  o m
    Bitmap copiedBitmap = bm.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(copiedBitmap);
    canvas.drawBitmap(bm, 0, 0, paint);
    return copiedBitmap;
}