PhotoViewライブラリを使用して写真のトリミング ツールを作成しようとしていますが、 によって返される値を理解するのに苦労していますgetDisplayRect()
。写真を次のImageView
ように設定しました:
photo.setImageDrawable(new BitmapDrawable(getResources(), image));
はimage
Bitmap オブジェクトです。次に、いくつかのスケーリング値を設定します。
float minScale = ((float)image.getWidth() > (float)image.getHeight())
? (float)image.getWidth() / (float)image.getHeight()
: (float)image.getHeight() / (float)image.getWidth();
attacher.setMaxScale(minScale * 5f);
attacher.setMidScale(minScale * 2.5f);
attacher.setMinScale(minScale);
attacher.setScale(minScale, (float)image.getWidth() / 2f,(float)image.getHeight() / 2f, false);
attacher.update();
オブジェクトattacher
はどこですか。PhotoViewAttacher
ユーザーが完了したら、次を使用して、に表示されるビットマップの部分を決定しますImageView
。
RectF rect = attacher.getDisplayRect();
float scale = attacher.getScale();
PhotoData ret = new PhotoData(data);
ret.x = (int)(Math.abs(rect.left) / scale);
ret.y = (int)(Math.abs(rect.top) / scale);
ret.width = (int)(rect.width() / scale);
ret.height = (int)(rect.height() / scale);
しかし、予想外の結果が得られます。たぶん、ここにいる誰かが洞察を提供してくれるでしょうか?