- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 imageView,我正在尝试创建圆角,尝试了这篇文章中的所有解决方案:How to make an ImageView with rounded corners?但没有任何效果..这是我的 XML
<RelativeLayout
android:id="@+id/RL_ImageHolder"
android:layout_width="150dp"
android:layout_height="180dp"
android:layout_alignBottom="@+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/relativeLayout2"
android:layout_marginLeft="10dp" >
<ImageView
android:id="@+id/imgPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="Preview"
/>
</RelativeLayout>
这就是我使用上面链接的帖子中提到的方法设置 ImageView 的方式:
byteArray = extras.getByteArray("picture");
if (byteArray != null) {
bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
preview.setScaleType(ScaleType.CENTER_CROP);
preview.setImageBitmap(getRoundedCornerBitmap(bmp));
图像设置正确,但它仍然是一个矩形.. 知道为什么它不起作用吗?
编辑: 刚刚发现仅当包含图像的布局具有固定的宽度/高度时才行不通。必须考虑如何管理它。谢谢大家
最佳答案
尝试使用下面的代码 fragment :
public static Bitmap GetCurveImage(Bitmap bitmap) {
// Bitmap myCoolBitmap = ... ; // <-- Your bitmap you
// want rounded
int w = bitmap.getWidth(), h = bitmap.getHeight();
// We have to make sure our rounded corners have an
// alpha channel in most cases
Bitmap rounder = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(rounder);
// We're going to apply this paint eventually using a
// porter-duff xfer mode.
// This will allow us to only overwrite certain pixels.
// RED is arbitrary. This
// could be any color that was fully opaque (alpha =
// 255)
Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
xferPaint.setColor(Color.RED);
// We're just reusing xferPaint to paint a normal
// looking rounded box, the 20.f
// is the amount we're rounding by.
canvas.drawRoundRect(new RectF(0, 0, w, h), 5.0f, 5.0f, xferPaint);
// Now we apply the 'magic sauce' to the paint
xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
Bitmap result = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas resultCanvas = new Canvas(result);
resultCanvas.drawBitmap(bitmap, 0, 0, null);
resultCanvas.drawBitmap(rounder, 0, 0, xferPaint);
return result;
}
希望对您有所帮助。
关于android试图圆位图角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13949036/
我是 C++ 的新手,我在使用这段代码时遇到了问题: string output_date(int day, int month, int year){ string date; if
所以我这样做了 tar cvzf test.zip FP 为了创建目录 FP 的 zip 但是,它会列出 zip 中的目录 FP/ FP/php/ FP/php/pdf/ FP/php/docs/ F
我正在尝试在 Swift、Xcode 7.3(所以是 Swift 2.2)中创建一个通用类,但我似乎无法让它通过编译器: protocol Struct1Protocol { } struct Str
我的测试用例是这样的: class FooTest extends PHPUnit_Framework_TestCase { /** @covers MyClass::bar */ f
我正在尝试将brew install wine作为使electron-builder工作的一步。但是我所能得到的只是以下响应: ==> Installing dependencies for wine
我这样做: string[,] string1 = {{"one", "0"},{"Two", "5"},{"Three","1"}}; int b = 0; for(int i = 0; i <=
我正在尝试使用 SetWindowsHookEx 键盘 Hook Notepad.exe。 如您所见,工作线程正在将其 ASCII 代码(即 wParam)发送到指定的服务器。 UINT WINAPI
我正在尝试将 ListView 实现到我的 Fragment 中,但无论我尝试什么,我都会得到一个 NullPointerException。我检查对象是否为 null 并记录是否为 null,看起来
我尝试在一行中对齐两个 div。使用 float left 属性,一切顺利。但是当我在 div 中使用图像时,它开始产生问题。 所以这是我的示例代码:- Some headi
我目前正在使用此代码来获取图像的灰度图像表示并以 (512, 370, 1) 的格式表示它大批。 img_instance = cv2.imread(df.iloc[i][x_col]) / 255.
总结 我正在创建一个简单的应用程序,它允许用户选择一个包含顶级窗口的进程。用户首先键入 native DLL(而非托管 DLL)的路径。然后用户键入将在 Hook 过程中调用的方法的名称。该方法不得返
我是一名优秀的程序员,十分优秀!