0
私はここでFacebook API
を使用して取得するURLを持っており、これを円形のBitmap
に変更しようとしています。これは正常に動作しますが、私のイメージは実際には中央にないようです。URLから円形ビットマップに矩形画像を変更すると写真が上に移動しますか?
しかし、私は、私は私のコードで間違ってやっているかを把握することはできません。ここでは、それがどのように見えるかの例です。ここでは、円形のBitmap
にURLを変換するために私のコードは次のとおりです。
public Bitmap getBitmapFromURL(String userId) {
try {
URL imgUrl = new URL("https://graph.facebook.com/" + userId + "/picture?type=large");
InputStream in = (InputStream) imgUrl.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(in);
Bitmap output;
if (bitmap.getWidth() > bitmap.getHeight()) {
output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
} else {
output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
float r = 0;
if (bitmap.getWidth() > bitmap.getHeight()) {
r = bitmap.getHeight()/2;
} else {
r = bitmap.getWidth()/2;
}
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawCircle(r, r, r, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
} catch (IOException e) {
// Log exception
return null;
}
}