Android在另一个图像中绘制图像

Android在另一个图像中绘制图像,android,canvas,google-maps-android-api-2,marker,Android,Canvas,Google Maps Android Api 2,Marker,如何使用画布在另一个图像中绘制图像; 如图所示: 像这样把它放到地图应用程序v2中 marker = gmap.addMarker(new MarkerOptions().title("test") .position(new LatLng(0, 0)) .snippet("snipet test") .icon(BitmapDescriptorFac

如何使用画布在另一个图像中绘制图像; 如图所示:

像这样把它放到地图应用程序v2中

 marker = gmap.addMarker(new MarkerOptions().title("test")
                        .position(new LatLng(0, 0))
                        .snippet("snipet test")
                        .icon(BitmapDescriptorFactory.fromBitmap(bitmap))
我已经画了一幅这样的长方形图

            InputStream inputStream = connection.getInputStream();
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
            Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                    bitmap.getHeight(), Bitmap.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);


            paint.setAntiAlias(true);
            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);
如何做到这一点
请帮助我

根据您想要的框架形状为画布设置剪辑路径:

Path frame = new Path();
frame.addCircle(centerX, centerY, radius, Direction.CW);
canvas.getClipBounds(oldClipBounds); //see below
canvas.clipPath(frame);
如果你画的东西在圆圈之外,你在画布上画的东西就看不见了

如果需要仅在此框架外部进行的其他图形,可以稍后通过以下方式对其进行保护:

canvas.clipRect(oldClipBounds, Region.Op.REVERSE_DIFFERENCE);

我找到了解决此问题的方法: 您将图像放在一个带有画布的圆圈中,然后使用精确的大小调整结果的大小,并将其放在标记图像中

public class IconMarker {
    public IconMarker(){}

    public Bitmap DrawMarker(String userid,int typeid,Resources rcs){

        //  image from database: ...InputStream inputStream = connection.getInputStream();
        //Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        Bitmap img1=new UserInfoBd().getPhotoProfil(userid);
        if(img1==null) img1=BitmapFactory.decodeResource(rcs,R.drawable.espace_photo);
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bmp = BitmapFactory.decodeResource(rcs,
                typeid);
        Bitmap output = Bitmap.createBitmap(bmp.getWidth(),
                bmp.getHeight(), Bitmap.Config.ARGB_8888);

        Canvas canvas1 = new Canvas(output);
        canvas1.drawBitmap(bmp, 0,0, null);
        Bitmap output1 = Bitmap.createBitmap(img1.getWidth(),
                img1.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(output1);

        final int color = 0xff424242;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, img1.getWidth(), img1.getHeight());
        final RectF rectF = new RectF(rect);


        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        canvas.drawOval(rectF, paint);

        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(img1, rect, rect, paint);
        Bitmap img=getResizedBitmap(output1,bmp.getHeight()*3/4-4,bmp.getWidth()*3/4);

        canvas1.drawBitmap(img,(float)4.7,(float)3.5,null);

        return output;

    }
    public  Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {

        int width = bm.getWidth();

        int height = bm.getHeight();

        float scaleWidth = ((float) newWidth) / width;

        float scaleHeight = ((float) newHeight) / height;

        // CREATE A MATRIX FOR THE MANIPULATION
        Matrix matrix = new Matrix();

        // RESIZE THE BIT MAP
        matrix.postScale(scaleWidth, scaleHeight);

        // RECREATE THE NEW BITMAP
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

        return resizedBitmap;
    }
}