5

私は1つの画像を持っておりimage 1、1つはサーバーからimage 2のもので、最初の画像のちょうど中央に2番目の画像を描画しようとしています。結果として、私は写真のように単一の画像が欲しいです。 画像

4

2 に答える 2

16

これはあなたが探していることをするはずです:

backgroundBitmap変数はyourimage1になり、theはbitmapToDrawInTheCenteryourになりますimage2

public void centerImageInOtherImage()
{
    Bitmap backgroundBitmap        = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    Bitmap bitmapToDrawInTheCenter = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_search);
    
    Bitmap resultingBitmap = Bitmap.createBitmap(backgroundBitmap.getWidth(), backgroundBitmap.getHeight(), backgroundBitmap.getConfig());

    Canvas canvas = new Canvas(resultingBitmap);
    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(resultingBitmap);
}
于 2012-09-08T17:28:47.133 に答える
0

礼儀:Androidの別の画像にテキスト/画像を描画する

Canvasを使用すると、画像を相互に描画するのは非常に簡単です。Canvasは基本的に、テキスト/画像を描画するための描画ボードとして機能します。以下に示すように、最初の画像でキャンバスを作成してから、中央に2番目の画像を描画する必要があります。

/* This ImageOne will be used as the canvas to draw an another image over it. Hence we make it mutable using the copy API
as shown below
*/
      Bitmap imageOne = BitmapFactory.decodeResource(getResources(), R.drawable.imageOne).copy(Bitmap.Config.ARGB_8888,true);
      // Decoding the image two resource into a Bitmap
      Bitmap imageTwo= BitmapFactory.decodeResource(getResources(), R.drawable.imageTwo);
      // Here we construct the canvas with the specified bitmap to draw onto
      Canvas canvas=new Canvas(imageOne);

/*Here we draw the image two on the canvas using the drawBitmap API.
drawBitmap takes in four parameters
1 . The Bitmap to draw
2.  X co-ordinate to draw from
3.  Y co ordinate to draw from
4.  Paint object to define style
*/
      canvas.drawBitmap(imageTwo,(imageOne.getWidth())/2,(imageOne.getHeight())/2,new Paint());

      imageView.setImageBitmap(imageOne);
于 2018-06-13T11:00:57.920 に答える