0
私は以前これに関連する質問をしましたが、私の目標が間違っていたと思います。アンドロイドで縮尺変更された画像のタッチ可能な領域を定義する
私が持っているもの:グラフィックを表示し、複数のタッチ可能な領域を画像内の長方形として定義するカスタムImageView。私の問題はスケーリングです。私はビットマップファイルの実際の解像度に基づいてイメージのタッチ可能な領域を定義したいが、その座標を変換して、矩形がスケーリングされたイメージの同じ領域をカバーするようにする。
これは私がこれまで持っているものです: ビューが作成されると、スケールの大き
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
Drawable pic=this.getDrawable();
int realHeight= pic.getIntrinsicHeight();
int realWidth=pic.getIntrinsicWidth();
int scaledHeight=this.getHeight();
int scaleWidth=this.getWidth();
heightRatio=(float)realHeight/scaledHeight;
widthRatio=(float)realWidth/scaleWidth;
}
に、実際の比率を計算する今、私は長方形(複数可)を定義する座標を取りたいですオリジナル(非スケール)画像 上の画像の同じ領域にその四角形(複数可)を描く - しかし、規模の会計処理:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p=new Paint();
p.setStrokeWidth(1);
p.setColor(Color.BLUE);
for (HotSpot h: spots)
{
//Each hotspot has a rectangle defined in reference to the actual size of the image
Rect old=h.getRect();
float offsetLeft=old.left+(old.left*widthRatio);
float offsetTop=old.top+(old.top*heightRatio);
float offsetRight=old.right+(old.right*heightRatio);
float offsetBottom=old.bottom+(old.bottom*widthRatio);
RectF nRect=new RectF(offsetLeft,offsetTop,offsetRight,offsetBottom);
canvas.drawRect(nRect,p);
}
結果は「ボールパークで」ですがなく、かなり正確。どんな助けもありがとうございます。
あなたはこのソリューション試すことができ