高悬赏求vb图像处理程序代码

高悬赏求vb图像处理程序代码,第1张

额……给你点提示吧。

(1)可以用CommonDialog控件(CommonDialog1.ShowOpen)

(2)

取RGB值的话,可以用Point取(

Picture1.Point(i,j)

),得到一个颜色值,然后通过下面的运算算出来。(r红

g绿

b蓝)

color=Picture1.Point(i,j)

r

=

(color

Mod

65536)

Mod

256

g

=

(color

Mod

65536)

Mod

256

b

=

color

\

65536

然后rr

gg

bb就很好搞了

rr=255-r

gg=255-g

bb=255-b

这问题有点笼统,软糖来说说把:

图像处理由System.Drawing命名空间负责。

主要是Bitmap类和Graphics类。

Bitmap表示一个位图,可以是BMP,JPG,PNG等文件。

装载位图

Dim 位图 As Bitmap = Bitmap.FromFile("C:\Image1.PNG")

Graphics表示一张画纸,能够进行绘制 *** 作。

它可以被窗体、控件、位图调用CreateGraphics()方法来创建。

然后调用Graphics.Draw开头的一系列函数来绘制图像和图形,Fill开头的填充图形。

创建画纸并绘制位图

Dim 画纸 As Graphics = Me.CreateGraphics()

画纸.DrawImage(位图, 100, 100, 256, 256)

可以将上面三行放到Form1_Load中测试,把路径改一下,

还可以把Me改为能在上面绘图的控件的名称。

更多内容请看MSDN的System.Drawing命名空间。

如满意,请采纳,谢谢。

这种绘图问题来找我嘛……(分好寒酸。。)

传说中的GDI+隆重出场!……

GDI+是最快的。可以超过VB任何绘图语句

1.建立一个模块,复制下面代码:

Option Explicit

Public Type GdiplusStartupInput

GdiplusVersion As Long

DebugEventCallback As Long

SuppressBackgroundThread As Long

SuppressExternalCodecs As Long

End Type

Public Enum GpStatus

Ok = 0

GenericError = 1

InvalidParameter = 2

OutOfMemory = 3

ObjectBusy = 4

InsufficientBuffer = 5

NotImplemented = 6

Win32Error = 7

WrongState = 8

Aborted = 9

FileNotFound = 10

ValueOverflow = 11

AccessDenied = 12

UnknownImageFormat = 13

FontFamilyNotFound = 14

FontStyleNotFound = 15

NotTrueTypeFont = 16

UnsupportedGdiplusVersion = 17

GdiplusNotInitialized = 18

PropertyNotFound = 19

PropertyNotSupported = 20

End Enum

Public Enum LinearGradientMode

LinearGradientModeHorizontal ' 0

LinearGradientModeVertical' 1

LinearGradientModeForwardDiagonal ' 2

LinearGradientModeBackwardDiagonal' 3

End Enum

Public Enum WrapMode

WrapModeTile ' 0

WrapModeTileFlipX' 1

WrapModeTileFlipY' 2

WrapModeTileFlipXY ' 3

WrapModeClamp' 4

End Enum

Public Type POINTL

x As Long

y As Long

End Type

Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus

Public Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus

Public Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, graphics As Long) As GpStatus

Public Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus

Public Declare Function GdipGraphicsClear Lib "gdiplus" (ByVal graphics As Long, ByVal lColor As Long) As GpStatus

Public Declare Function GdipCreateLineBrushI Lib "gdiplus" (Point1 As POINTL, Point2 As POINTL, ByVal color1 As Long, ByVal color2 As Long, ByVal WrapMd As WrapMode, lineGradient As Long) As GpStatus

Public Declare Function GdipFillRectangleI Lib "gdiplus" (ByVal graphics As Long, ByVal Brush As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As GpStatus

Public Declare Function GdipDeleteBrush Lib "gdiplus" (ByVal Brush As Long) As GpStatus

Dim mToken As Long

Public Sub InitGDIPlus()

Dim uInput As GdiplusStartupInput

uInput.GdiplusVersion = 1

If GdiplusStartup(mToken, uInput) <>Ok Then

MsgBox "GDI+ 初始化错误。程序即将关闭。", vbCritical, "InitError"

End

End If

End Sub

Public Sub TerminateGDIPlus()

GdiplusShutdown mToken

End Sub

2.窗体上复制下面代码:

Option Explicit

Dim g As Long, Brush As Long

Dim p1 As POINTL, p2 As POINTL

Private Sub Form_Load()

Picture1.ScaleMode = 2

Picture1.AutoRedraw = True

Me.ScaleMode = 2

p1.x = Picture1.Left

p1.y = Picture1.Top

p2.x = p1.x + Picture1.Width

p2.y = p1.y + Picture1.Height

Call InitGDIPlus

GdipCreateFromHDC Picture1.hDC, g

GdipCreateLineBrushI p1, p2, &HFFFF00FF, &HFF00FF00, WrapModeTileFlipY, Brush

GdipFillRectangleI g, Brush, p1.x, p1.y, p2.x - p1.x, p2.y - p1.y

End Sub

Private Sub Form_Unload(Cancel As Integer)

GdipDeleteBrush Brush

GdipDeleteGraphics g

TerminateGDIPlus

End Sub

注意这一行 GdipCreateLineBrushI p1, p2, &HFFFF00FF, &HFF00FF00, WrapModeTileFlipY, Brush

&HFFFF00FF, &HFF00FF00分别是两个颜色,对应AlphaRedGreenBlue

即&HFFFF00FF代表Alpha=255,Red=255,Green=0,Blue=255


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7817896.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存