本文介绍了安卓:在另一图像的中心绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形象图像1 键,一个是从服务器的图像2 我试图绘制未来第二个刚刚在第一的中心。作为结果,我想就像在PIC单片机的形象。

I have one image image 1 and one is coming from server that is image 2 i am trying to draw second one just at the center of the first. as result i want single image like in pic .

推荐答案

这应该是你找什么:该BackgroundBitmap指令将是你的此搜索和bitmapToDrawInTheCenter将是你的图像2。

This should be what you looking for:The backgroundBitmap would be your "image1" and the bitmapToDrawInTheCenter would be your "image2".

public void createImageInImageCenter(){
    Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    Bitmap bitmapToDrawInTheCenter = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_search);

    Bitmap resultBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(),backgroundBitmap.getHeight(), backgroundBitmap.getConfig());
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(backgroundBitmap, new Matrix(), null);
    canvas.drawBitmap(bitmapToDrawInTheCenter, (backgroundBitmap.getWidth() - bitmapToDrawInTheCenter.getWidth()) / 2, (backgroundBitmap.getHeight() - bitmapToDrawInTheCenter.getHeight()) / 2, new Paint());

    ImageView image = (ImageView)findViewById(R.id.myImage);
    image.setImageBitmap(resultBitmap);
}

这篇关于安卓:在另一图像的中心绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:21
查看更多