ビットマップの水平および垂直解像度 (dpi) を見つけようとしています。ビットマップを適切にクリップするには、この情報が必要です。私はすでにビットマップの幅と高さを持っていますが、これが唯一の不足している情報です。私が得ている(間違った)出力は、クリッピングがオフになっていることです。これが私の例です。ビットマップの垂直解像度と水平解像度が必要なコードでは、「(Missing)」とマークされています。
final Bitmap clippedBmp;
final Rect<Double> clipRectInInches = imageScaleInPixelAndInches.getClipRect();
final Rect<Integer> clipRectInPixel = new Rect<Integer>();
clipRectInPixel.setX ((int)(clipRectInInches.getX() * (Missing)));
clipRectInPixel.setY ((int)(clipRectInInches.getY() * (Missing)));
clipRectInPixel.setWidth ((int)(clipRectInInches.getWidth() * (Missing)));
clipRectInPixel.setHeight((int)(clipRectInInches.getHeight() * (Missing)));
ClipRectUtil.normalizeClipRect(clipRectInPixel, orgBmp.getWidth(), orgBmp.getHeight());
clippedBmp = Bitmap.createBitmap(orgBmp,
clipRectInPixel.getX(),
clipRectInPixel.getY(),
clipRectInPixel.getWidth(),
clipRectInPixel.getHeight());
これがnormalizeClipRect関数です
public static void normalizeClipRect(Rect<Integer> clipRectInPixel, int imgWidth, int imgHeight)
{
int clipX = clipRectInPixel.getX();
int clipY = clipRectInPixel.getY();
int clipWidth = clipRectInPixel.getWidth();
int clipHeight = clipRectInPixel.getHeight();
if ( clipX < 0 )
clipX = 0;
if ( clipY < 0 )
clipY = 0;
if ( clipX > imgWidth )
clipX = imgWidth;
if ( clipY > imgHeight )
clipY = imgHeight;
if ( clipX + clipWidth > imgWidth )
clipWidth = imgWidth - clipX;
if ( clipY + clipHeight > imgHeight )
clipHeight = imgHeight - clipY;
// update in-place
clipRectInPixel.setX (clipX);
clipRectInPixel.setY (clipY);
clipRectInPixel.setWidth (clipWidth);
clipRectInPixel.setHeight(clipHeight);
}
よろしくお願いします。さらに情報が必要な場合はお知らせください。
再度、感謝します、
マルク