2017-07-28 9 views
0

私は、画像エディタを使ってギャラリーから画像を選択し、画像にオブジェクトを描くことができます。Draw on Custom Imageビュー

私はカスタムImageViewを作成し、選択したイメージでsetImageBitmapを呼び出しました。

画像は画面の中央に配置され、矩形のフォーム(0、0)から(100,100)に描画しようとすると、左上隅から描画されます。スクリーンは画像ではありません。

また、選択したビットマップの幅と高さは、カスタムImageViewのonDraw()メソッドのキャンバスの幅と高さとは異なります。

+0

属性を設定するandroid:scaleType = "fitXY"、android:layout_width = "match_parent" android:layout_height = "match_parent" – huk

+0

私は画像を拡大縮小したくないので、どこにでも直接描画する方法が必要ですそれは(中央または上部)です。 –

答えて

0

画像を選択した後、選択した画像のビットマップを作成し、コードの下に試してみてください。

int currentBitmapWidth = bitMap.getWidth(); 
int currentBitmapHeight = bitMap.getHeight(); 

int ivWidth = imageView.getWidth(); 
int ivHeight = imageView.getHeight(); 
int newWidth = ivWidth; 

newHeight = (int) Math.floor((double) currentBitmapHeight *((double) 
new_width/(double) currentBitmapWidth)); 

Bitmap newbitMap = Bitmap.createScaledBitmap(bitMap, newWidth, 
newHeight, true); 

imageView.setImageBitmap(newbitMap) 

これはあなたのImageViewのサイズにイメージを設定します。