图像问题,请帮忙解决。
一个从6.0升级过来的程序,调试不成功,可能是封送处理的问题,请指教。
Private Structure PALETTEENTRY
Dim peRed As Byte
Dim peGreen As Byte
Dim peBlue As Byte
Dim peFlags As Byte
End Structure
Private Structure LOGPALETTE
Dim palVersion As Short
Dim palNumEntries As Short
<VBFixedArray(255)> Dim palPalEntry() As PALETTEENTRY
Public Sub Initialize()
ReDim palPalEntry(255)
End Sub
End Structure
Private Structure GUID
Dim Data1 As Integer
Dim Data2 As Short
Dim Data3 As Short
<VBFixedArray(7)> Dim Data4() As Byte
Public Sub Initialize()
ReDim Data4(7)
End Sub
End Structure
Private Const RASTERCAPS As Integer = 38
Private Const RC_PALETTE As Integer = &H100s
Private Const SIZEPALETTE As Integer = 104
Private Structure RECT
Dim Left_Renamed As Integer
Dim Top_Renamed As Integer
Dim Right_Renamed As Integer
Dim Bottom_Renamed As Integer
End Structure
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Integer, ByVal iCapabilitiy As Integer) As Integer
Private Declare Function GetSystemPaletteEntries Lib "GDI32" (ByVal hDC As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, ByRef lpPaletteEntries As PALETTEENTRY) As Integer
Private Declare Function CreatePalette Lib "GDI32" (ByRef lpLogPalette As LOGPALETTE) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal hDCDest As Integer, ByVal XDest As Integer, ByVal YDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hDCSrc As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function GetForegroundWindow Lib "USER32" () As Integer
Private Declare Function SelectPalette Lib "GDI32" (ByVal hDC As Integer, ByVal hPalette As Integer, ByVal bForceBackground As Integer) As Integer
Private Declare Function RealizePalette Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function GetWindowDC Lib "USER32" (ByVal hWnd As Integer) As Integer
Private Declare Function GetDC Lib "USER32" (ByVal hWnd As Integer) As Integer
Private Declare Function GetWindowRect Lib "USER32" (ByVal hWnd As Integer, ByRef lpRect As RECT) As Integer
Private Declare Function ReleaseDC Lib "USER32" (ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
Private Declare Function GetDesktopWindow Lib "USER32" () As Integer
Private Structure PicBmp
Dim Size_Renamed As Integer
Dim Type As Integer
Dim hBmp As Integer
Dim hPal As Integer
Dim Reserved As Integer
End Structure
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (ByRef PicDesc As PicBmp, ByRef RefIID As GUID, ByVal fPictureOwnsHandle As Integer, ByRef IPic As System.Drawing.Image) As Integer
Public Function CaptureWindow(ByVal hWndSrc As Integer, ByVal Client As Boolean, ByVal LeftSrc As Integer, ByVal TopSrc As Integer, ByVal WidthSrc As Integer, ByVal HeightSrc As Integer) As System.Drawing.Image
Dim hDCMemory As Integer
Dim hBmp As Integer
Dim hBmpPrev As Integer
Dim r As Integer
Dim hDCSrc As Integer
Dim hPal As Integer
Dim hPalPrev As Integer
Dim RasterCapsScrn As Integer
Dim HasPaletteScrn As Integer
Dim PaletteSizeScrn As Integer
Dim LogPal As LOGPALETTE
LogPal.Initialize()
' Depending on the value of Client get the proper device context.
If Client Then
hDCSrc = GetDC(hWndSrc) ' Get device context for client area.
Else
hDCSrc = GetWindowDC(hWndSrc) ' Get device context for entire
' window.
End If
' Create a memory device context for the copy process.
hDCMemory = CreateCompatibleDC(hDCSrc)
' Create a bitmap and place it in the memory DC.
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
' Get screen properties.
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster
' capabilities.
HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette
' support.
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of
' palette.
' If the screen has a palette make a copy and realize it.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
' Create a copy of the system palette.
LogPal.palVersion = &H300s
LogPal.palNumEntries = 256
r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
' Select the new palette into the memory DC and realize it.
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
r = RealizePalette(hDCMemory)
End If
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, &HCC0020)
' Remove the new copy of the on-screen image.
hBmp = SelectObject(hDCMemory, hBmpPrev)
' If the screen has a palette get back the palette that was
' selected in previously.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
' Release the device context resources back to the system.
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
' Call CreateBitmapPicture to create a picture object from the
' bitmap and palette handles. Then return the resulting picture
' object.
CaptureWindow = CreateBitmapPicture(hBmp, hPal)
End Function
Public Function CreateBitmapPicture(ByVal hBmp As Integer, ByVal hPal As Integer) As System.Drawing.Image
Dim r As Integer
Dim Pic As PicBmp
' IPicture requires a reference to "Standard OLE Types."
Dim IPic As System.Drawing.Image
'UPGRADE_WARNING: 结构 IID_IDispatch 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1063"”
Dim IID_IDispatch As New Guid
IID_IDispatch.Initialize()
' Fill in with IDispatch Interface ID.
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0s
.Data4(7) = &H46s
End With
' Fill Pic with necessary parts.
With Pic
.Size_Renamed = Len(Pic) ' Length of structure.
.Type = 1 ' Type of Picture (bitmap).
.hBmp = hBmp ' Handle to bitmap.
.hPal = hPal ' Handle to palette (may be null).
End With
' Create Picture object.
××××××××××××××××××下面一句出现了问题
r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
' Return the new Picture object.
CreateBitmapPicture = IPic
End Function
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Dim G As System.Drawing.Graphics
G = Picture1.CreateGraphics
G.DrawImage(CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.Width, Picture1.Height), 0, 0)
'Picture1.PaintPicture(CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.ScaleX(VB6.PixelsToTwipsX(Picture1.Width), vbTwips, vbPixels), Picture1.ScaleY(VB6.PixelsToTwipsY(Picture1.Height), vbTwips, vbPixels)), 0, 0)
Picture1.BackgroundImage.Save("c:\test2.bmp")
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.Width, Picture1.Height).Save("C:\test1.bmp")
End Sub
Private Structure PALETTEENTRY
Dim peRed As Byte
Dim peGreen As Byte
Dim peBlue As Byte
Dim peFlags As Byte
End Structure
Private Structure LOGPALETTE
Dim palVersion As Short
Dim palNumEntries As Short
<VBFixedArray(255)> Dim palPalEntry() As PALETTEENTRY
Public Sub Initialize()
ReDim palPalEntry(255)
End Sub
End Structure
Private Structure GUID
Dim Data1 As Integer
Dim Data2 As Short
Dim Data3 As Short
<VBFixedArray(7)> Dim Data4() As Byte
Public Sub Initialize()
ReDim Data4(7)
End Sub
End Structure
Private Const RASTERCAPS As Integer = 38
Private Const RC_PALETTE As Integer = &H100s
Private Const SIZEPALETTE As Integer = 104
Private Structure RECT
Dim Left_Renamed As Integer
Dim Top_Renamed As Integer
Dim Right_Renamed As Integer
Dim Bottom_Renamed As Integer
End Structure
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Integer, ByVal iCapabilitiy As Integer) As Integer
Private Declare Function GetSystemPaletteEntries Lib "GDI32" (ByVal hDC As Integer, ByVal wStartIndex As Integer, ByVal wNumEntries As Integer, ByRef lpPaletteEntries As PALETTEENTRY) As Integer
Private Declare Function CreatePalette Lib "GDI32" (ByRef lpLogPalette As LOGPALETTE) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal hDCDest As Integer, ByVal XDest As Integer, ByVal YDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hDCSrc As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function GetForegroundWindow Lib "USER32" () As Integer
Private Declare Function SelectPalette Lib "GDI32" (ByVal hDC As Integer, ByVal hPalette As Integer, ByVal bForceBackground As Integer) As Integer
Private Declare Function RealizePalette Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function GetWindowDC Lib "USER32" (ByVal hWnd As Integer) As Integer
Private Declare Function GetDC Lib "USER32" (ByVal hWnd As Integer) As Integer
Private Declare Function GetWindowRect Lib "USER32" (ByVal hWnd As Integer, ByRef lpRect As RECT) As Integer
Private Declare Function ReleaseDC Lib "USER32" (ByVal hWnd As Integer, ByVal hDC As Integer) As Integer
Private Declare Function GetDesktopWindow Lib "USER32" () As Integer
Private Structure PicBmp
Dim Size_Renamed As Integer
Dim Type As Integer
Dim hBmp As Integer
Dim hPal As Integer
Dim Reserved As Integer
End Structure
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (ByRef PicDesc As PicBmp, ByRef RefIID As GUID, ByVal fPictureOwnsHandle As Integer, ByRef IPic As System.Drawing.Image) As Integer
Public Function CaptureWindow(ByVal hWndSrc As Integer, ByVal Client As Boolean, ByVal LeftSrc As Integer, ByVal TopSrc As Integer, ByVal WidthSrc As Integer, ByVal HeightSrc As Integer) As System.Drawing.Image
Dim hDCMemory As Integer
Dim hBmp As Integer
Dim hBmpPrev As Integer
Dim r As Integer
Dim hDCSrc As Integer
Dim hPal As Integer
Dim hPalPrev As Integer
Dim RasterCapsScrn As Integer
Dim HasPaletteScrn As Integer
Dim PaletteSizeScrn As Integer
Dim LogPal As LOGPALETTE
LogPal.Initialize()
' Depending on the value of Client get the proper device context.
If Client Then
hDCSrc = GetDC(hWndSrc) ' Get device context for client area.
Else
hDCSrc = GetWindowDC(hWndSrc) ' Get device context for entire
' window.
End If
' Create a memory device context for the copy process.
hDCMemory = CreateCompatibleDC(hDCSrc)
' Create a bitmap and place it in the memory DC.
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
' Get screen properties.
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster
' capabilities.
HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette
' support.
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of
' palette.
' If the screen has a palette make a copy and realize it.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
' Create a copy of the system palette.
LogPal.palVersion = &H300s
LogPal.palNumEntries = 256
r = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
' Select the new palette into the memory DC and realize it.
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
r = RealizePalette(hDCMemory)
End If
r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, &HCC0020)
' Remove the new copy of the on-screen image.
hBmp = SelectObject(hDCMemory, hBmpPrev)
' If the screen has a palette get back the palette that was
' selected in previously.
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
' Release the device context resources back to the system.
r = DeleteDC(hDCMemory)
r = ReleaseDC(hWndSrc, hDCSrc)
' Call CreateBitmapPicture to create a picture object from the
' bitmap and palette handles. Then return the resulting picture
' object.
CaptureWindow = CreateBitmapPicture(hBmp, hPal)
End Function
Public Function CreateBitmapPicture(ByVal hBmp As Integer, ByVal hPal As Integer) As System.Drawing.Image
Dim r As Integer
Dim Pic As PicBmp
' IPicture requires a reference to "Standard OLE Types."
Dim IPic As System.Drawing.Image
'UPGRADE_WARNING: 结构 IID_IDispatch 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1063"”
Dim IID_IDispatch As New Guid
IID_IDispatch.Initialize()
' Fill in with IDispatch Interface ID.
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0s
.Data4(7) = &H46s
End With
' Fill Pic with necessary parts.
With Pic
.Size_Renamed = Len(Pic) ' Length of structure.
.Type = 1 ' Type of Picture (bitmap).
.hBmp = hBmp ' Handle to bitmap.
.hPal = hPal ' Handle to palette (may be null).
End With
' Create Picture object.
××××××××××××××××××下面一句出现了问题
r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
' Return the new Picture object.
CreateBitmapPicture = IPic
End Function
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Dim G As System.Drawing.Graphics
G = Picture1.CreateGraphics
G.DrawImage(CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.Width, Picture1.Height), 0, 0)
'Picture1.PaintPicture(CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.ScaleX(VB6.PixelsToTwipsX(Picture1.Width), vbTwips, vbPixels), Picture1.ScaleY(VB6.PixelsToTwipsY(Picture1.Height), vbTwips, vbPixels)), 0, 0)
Picture1.BackgroundImage.Save("c:\test2.bmp")
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
CaptureWindow(Picture1.Handle.ToInt32, False, 0, 0, Picture1.Width, Picture1.Height).Save("C:\test1.bmp")
End Sub
...全文
相关推荐
解决医学磁共振图像(MRI)中高密度椒盐噪声和高斯噪声的问题提出的加权中值滤波算法(可复现的论文-有问题请联系博主)
内容概要:本文针对医学磁共振图像(MRI)在存储或传输过程中常受高密度椒盐噪声和高斯噪声影响的问题,提出了一种改进的加权中值滤波算法。该算法通过改良的有限阈值策略,对滤波窗口内的像素点灰度值与其相应权
【NX二次开发】解决NX\UG未能加载图像 - 详细信息请参见日志文件 的报错问题。...
做二次开发的朋友,偶尔会遇到下面这个错误弹框。为什么会出现这个报错?为什么工具在开发者电脑运行得很完美,在用户电脑上跑就完蛋?今天我就按我的理解把这问题给讲一下。 如果你是用户,请找开发者解决。或者尝试按照下面的方法解决。 原因分析: 其实我们开发的工具就像一个搬运工,需要找各种工具箱(库)里面的工具(函数),利用里面的工具...
解决使用MATLAB进行图像二值化后图像还是有灰度值问题
最近使用MATLAB对JPEG格式的灰度图像进行二值化,二值化后的图像非0即1(1代表的是白色,0代表的是黑色),我按照图像原本的名字保存,所以格式也没变,但是再次打开图像时还是存在非01的灰度值。 ...
Origin2017解决图像输出存在水印的问题
总的来说,解决Origin2017图像输出存在水印的问题主要通过修改软件设置和应用补丁。请确保遵循合法和安全的途径,避免侵犯版权或引入潜在风险。
用鼠标画矩形截取图像(请帮忙调试)
如果问题仍然无法解决,可能需要进一步提供代码片段以便分析。希望以上信息能帮助你解决问题,如果需要更具体的代码示例或调试指导,请提供更多的上下文信息。


