vb.net-如何将图片框中的任意图片变成圆形

问题描述 投票:0回答:3

我正在 vb.net 中制作一个应用程序,它具有良好的用户界面,包括包含图片框的帐户图标。我的问题是如何使图片框中的图像变成圆形?

像这样: https://drive.google.com/open?id=1rUBq68ULDkTiFFv2uEiV_oQIh3wQIfhd

vb.net rounding picturebox
3个回答
4
投票

我通常不会为没有显示尝试的问题提供代码,但答案中有几个步骤,而且自己编写代码比解释它们更容易。例如

'Get the original image.
Dim originalImage = PictureBox1.Image

'Create a new, blank image with the same dimensions.
Dim croppedImage As New Bitmap(originalImage.Width, originalImage.Height)

'Prepare to draw on the new image.
Using g = Graphics.FromImage(croppedImage)
    Dim path As New GraphicsPath

    'Create an ellipse that fills the image in both directions.
    path.AddEllipse(0, 0, croppedImage.Width, croppedImage.Height)

    Dim reg As New Region(path)

    'Draw only within the specified ellipse.
    g.Clip = reg
    g.DrawImage(originalImage, Point.Empty)
End Using

'Display the new image.
PictureBox2.Image = croppedImage

这将创建一个与原始图像具有相同宽度和高度的椭圆形图像。如果原件是方形的,那么最终的将是圆形的。如果您想要一个圆形,而不管原始的纵横比如何,那么您必须以适当的方式对其进行操作。


0
投票

虽然我看到您已经找到了问题的解决方案,但是这里有一个非常简单的解决方法。

假设您的项目位于

WinForms
中,并且您正在使用
Picture Box
控件。实现圆形图像外观的最简单方法是将
Image
PictureBox
属性设置为圆形且中间空白/透明、外部白色的图像。然后,无论您设置为
BackgroundImage
的任何图像,它都会显示为圆形。

这是一个示例圆形透明图像,您可以将其设置为

Image
(确保将
SizeMode
设置为拉伸),然后将任何图片设置为
BackgroundImage


-1
投票

මා දෑ දකී ඒ රූපේ මා හර්දේ ශෝබන ගංගා වෑහේවී ආලය හංගා දෑසින් පානා හී සැර යැව්වා මකරන්දේ සාරය ගි ල්වා ආශාවේ මා සිත දල්වා සේයාවන් ඔබගේ මං සෙව්ව් වා පායාවී සද ඔමරී ඒ යාමේ තරු ඇඹරී රූ ධාරී වන බබර ේමනකැලඹිලාරගනා හර සාරේ දෙපසේ පේනා මනසාරයි නාදය ඇසෙනා මං ආසයි හීනේ ලං වෙලා මනලෝලී කෝමල සේනා රන්දෝලී නර්තන ගේ නා නුඹ මාගේ නේදෝ යාවෙනා සරාගී සලුපටලාලා බලාවී ග ත සොලවාලා නුරාගී ප්u200dරේමා මුලු රෑ මත්වීලාදෝ මෝර ා

© www.soinside.com 2019 - 2024. All rights reserved.