- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想将加载的图像更改为圆角。
您知道的任何提示、教程、最佳实践吗?
最佳答案
对于一个更可控的方法,绘制一个圆角矩形,并使用绘画的 porter-duff Xfer 模式将其蒙版到您的图像上。
首先设置 Xfer 绘制和圆角位图:
Bitmap myCoolBitmap = ... ; // <-- Your bitmap you want rounded
int w = myCoolBitmap.getWidth(), h = myCoolBitmap.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), 20.0f, 20.0f, xferPaint);
// Now we apply the 'magic sauce' to the paint
xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
现在将此位图应用到您的图像上:
Bitmap result = Bitmap.createBitmap(myCoolBitmap.getWidth(), myCoolBitmap.getHeight() ,Bitmap.Config.ARGB_8888);
Canvas resultCanvas = new Canvas(result)
resultCanvas.drawBitmap(myCoolBitmap, 0, 0, null);
resultCanvas.drawBitmap(rounder, 0, 0, xferPaint);
圆角位图现在驻留在结果中。
关于java - 我应该如何在 Android 中给图像圆角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1705239/
我有一个包含各种子元素的网格,例如网格、Stackpanel、图像...是否可以以裁剪所有内容的方式将网格的角变圆?此外,根网格的大小可能会有所不同,因此无法进行硬编码。 编辑:经过大量搜索,我发现这
我的应用程序采用非常圆润的字体设计,我希望使用勾选框作为 UI 的一部分。带有完全圆形勾选“框”的设计看起来不太好。我正在寻找圆角的标准勾选框,就像您使用容器一样。关于如何实现这一目标的任何想法。我试
我的应用程序采用非常圆润的字体设计,我希望使用勾选框作为 UI 的一部分。带有完全圆形勾选“框”的设计看起来不太好。我正在寻找圆角的标准勾选框,就像您使用容器一样。关于如何实现这一目标的任何想法。我试
所以我应该显示一个时间表,其中每个项目都有一个带有圆角的背景图像...... 我不知道如何为我的 View (当前是 TextView,但我可以更改它)提供背景(这是必须重复的图案)并为其提供圆角..
我想让 JTextArea 有一个圆角,我做了这段代码: public BPosTxtArea() { super(); setOpaque(false); } @Override p
我有两个项目,我在其中创建了一组扩展 card 类的自定义 cards,然后将它们插入到 StaggeredView 中。 我的问题是,在其中一个项目中,卡片角会自动变圆,而在另一个项目中则不会! 此
我正在寻找一些 c++ 绘图图形库来为动态键盘键创建器创建带有抗锯齿选项的圆角。我已经测试过 OpenCV 和 Magick++ 函数,但结果不是很好。谁能帮我解决这个问题? 这是一个使用 Magic
有没有办法使 QLineEdit 小部件的角变圆?如果没有,是否有类似的小部件我可以这样做? 视觉意义: 已解决:(请参阅下面的更多信息) QLineEdit *lineEdit = ne
我正在尝试创建具有圆角和背景的矩形作为重复位图。我是这样写的,但是在角落里得到了位图。 有人能帮忙吗? 背景.xml 最
我有 UIVIew 的代码: override func drawRect(rect: CGRect) { let toolbarSize = CGFloat(UIDevice.current
我正在开发一个 Windows 窗体应用程序(C#、.NET 4.0、VS 2010),其中我有一个非常标准的 MainForm 和一个 ToolStrip(GripStyle:Hidden,Dock
我设法绘制了一个矩形 :-) 但我不知道如何绘制圆角矩形。 谁能帮我解决以下如何四舍五入矩形的代码? let canvas = UIGraphicsGetCurrentContext() rec =
我有以下 SVG: 我想获得类似 CSS 的 border-top-right-radius 和 border-top-bottom-radius 效果。 如何实现
这个问题在这里已经有了答案: How to make an ImageView with rounded corners? (58 个回答) 关闭去年。 我希望图像具有圆角。我实现了这个 xml 代码
我使用此类别并为我的 UITableView 创建大小相同的图像。有没有办法让图像也有圆角?谢谢! + (UIImage *)scale:(UIImage *)image toSize:(CGSize
我对 iPhone 屏幕设计没有太多经验,但我需要制作一个像这样的表格:(图片),我进行了调查,但没有找到任何东西。该表需要有一个圆角,用户将能够插入数据,在本例中是名字、姓氏等......现在我使用
创建具有自定义背景图像的 NSButton 的最佳方法是什么,它能够具有可变的宽度,而不会使角边框看起来被拉伸(stretch)?我知道有一些方便的方法可以使用 UIButton 执行此操作:http
我知道你可以使用 .cornerRadius()将 swiftUI View 的所有角都圆角,但有没有办法只圆角特定的角,例如顶部? 最佳答案 有两个选项,您可以使用 View与 Path ,或者您可
我想在我的游戏屏幕上添加一些黑色轮廓,使其看起来像圆角。 这是我想要达到的效果: 我认为使用着色器可能很容易创建这种效果,而不是在所有内容之上绘制一个巨大的位图。 有人可以帮助我使用此效果的 GLSL
我的 NSTextField 有圆角和白色背景颜色,但 View 本身似乎是矩形的。这意味着圆角和边界矩形之间的空间显示为透明。我该如何填写该区域才能使其不突出? 图片: 代码: let textFi
我是一名优秀的程序员,十分优秀!