Страница: 1 |
Страница: 1 |
Вопрос: Проблемы с буфером обмена
Добавлено: 18.12.05 21:10
Автор вопроса: Sergey | ICQ: 283551900
Проблемы с буфером обмена
Выполняю код:
Dim BM As Bitmap = New Bitmap(1000, 1000, Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim K As Integer
Clipboard.SetDataObject(New DataObject(BM))
K = 0
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
Do While Not (BM Is Nothing)
ListBox.Items.Add(CStr(K))
K += 1
BM = Nothing
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
Application.DoEvents()
Loop
Цикл бесконечный выполняется более 300раз, больше не ждал.
Если закомментарить строчку:
Clipboard.SetDataObject(New DataObject(BM))
Тоесть
Dim BM As Bitmap = New Bitmap(1000, 1000, Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim K As Integer
‘Clipboard.SetDataObject(New DataObject(BM))
K = 0
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
Do While Not (BM Is Nothing)
ListBox.Items.Add(CStr(K))
K += 1
BM = Nothing
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
Application.DoEvents()
Loop
И поместить в буфер обмена картинку с помощью PrtScr или Photoshop(размером 1000x1000x24 или более) то цикл выполняется 30-40раз.
Если картинка помещалась в буфер обмена из Photoshop то Photoshop выводит сообщение ‘Could not export the clipboard because there is not enough memory (RAM)’
Что-то где-то не освобождается.
Пробовал с Paint,Acrobat тоже самое.
Вечем проблема и как ее можно решить?
Ответы
Всего ответов: 3
Номер ответа: 1
Автор ответа:
GSerg
Вопросов: 0
Ответов: 1876
Профиль | | #1
Добавлено: 19.12.05 05:31
Ну типа да.
bitmap.dispose()
Номер ответа: 2
Автор ответа:
Sergey
ICQ: 283551900
Вопросов: 1
Ответов: 74
Профиль | | #2
Добавлено: 19.12.05 12:40
Попробовал:
 im BM As Bitmap = New Bitmap(1000, 1000, Drawing.Imaging.PixelFormat.Format24bppRgb)
 im K As Integer
'Clipboard.SetDataObject(New DataObject(BM))
K = 0
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
 o While Not (BM Is Nothing)
ListBox.Items.Add(CStr(K))
K += 1
BM.Dispose()
BM = Nothing
BM = Clipboard.GetDataObject.GetData("System.Drawing.Bitmap", True)
Application.DoEvents()
Loop
То же самое выполняется 33раза.
Если проблема в Bitmap.Dispose() тогда почему ее нет в первом случаи.
А разве BM = Nothing не освобождает память или тут как в Java когда захочет?
Номер ответа: 3
Автор ответа:
Sergey
ICQ: 283551900
Вопросов: 1
Ответов: 74
Профиль | | #3
Добавлено: 19.12.05 17:46
Реализовал через API
Namespace Clipboard
Public Module Clipboard
Private Declare Auto Function OpenClipboard Lib "User32.dll" (ByVal hWndNewOwner As Integer) As Boolean
Private Declare Auto Function CloseClipboard Lib "User32.dll" () As Boolean
Private Declare Auto Function ChangeClipboardChain Lib "User32.dll" (ByVal hWndRemove As Integer, ByVal hWndNewNext As Integer) As Boolean
Private Declare Auto Function CountClipboardFormats Lib "User32.dll" () As Int32
Private Declare Auto Function EmptyClipboard Lib "User32.dll" () As Boolean
Private Declare Auto Function EnumClipboardFormats Lib "User32.dll" (ByVal format As UInt32) As UInt32
Private Declare Auto Function GetClipboardData Lib "User32.dll" (ByVal uFormat As UInt32) As Integer
Private Declare Auto Function GetClipboardFormatName Lib "User32.dll" (ByVal format As Int32, ByVal lpszFormatName As Char(), ByVal cchMaxCount As Int32) As Int32
Private Declare Auto Function GetClipboardOwner Lib "User32.dll" () As Integer
Private Declare Auto Function GetClipboardSequenceNumber Lib "User32.dll" () As Int32
Private Declare Auto Function GetClipboardViewer Lib "User32.dll" () As Integer
Private Declare Auto Function GetOpenClipboardWindow Lib "User32.dll" () As Integer
Private Declare Auto Function GetPriorityClipboardFormat Lib "User32.dll" (ByVal paFormatPriorityList As Int32(), ByVal cFormats As Int32) As Int32
Private Declare Auto Function IsClipboardFormatAvailable Lib "User32.dll" (ByVal format As Int32) As Boolean
Private Declare Auto Function RegisterClipboardFormat Lib "User32.dll" (ByVal lpszFormat As String) As Int32
Private Declare Auto Function SetClipboardData Lib "User32.dll" (ByVal uFormat As Int32, ByVal hMem As Integer) As Integer
Private Declare Auto Function SetClipboardViewer Lib "User32.dll" (ByVal hWndNewViewer As Integer) As Integer
Const CF_TEXT As Integer = 1
Const CF_BITMAP As Integer = 2
Const CF_METAFILEPICT As Integer = 3
Const CF_SYLK As Integer = 4
Const CF_DIF As Integer = 5
Const CF_TIFF As Integer = 6
Const CF_OEMTEXT As Integer = 7
Const CF_DIB As Integer = 8
Const CF_PALETTE As Integer = 9
Const CF_PENDATA As Integer = 10
Const CF_RIFF As Integer = 11
Const CF_WAVE As Integer = 12
Const CF_UNICODETEXT As Integer = 13
Const CF_ENHMETAFILE As Integer = 14
Enum eError
Ok = 0
OpenError = 1
FormatError = 2
End Enum
Public Function GetBitmap(ByRef Bitmap As Bitmap) As eError
Dim hbm As Integer
Bitmap = Nothing
If OpenClipboard(0) Then
Try
hbm = GetClipboardData(UInt32.Parse(CF_BITMAP))
If hbm <> 0 Then
Try
Bitmap = Bitmap.FromHbitmap(New IntPtr(hbm))
Catch
Return eError.FormatError
End Try
End If
Finally
CloseClipboard()
End Try
Else
Return eError.OpenError
End If
Return eError.Ok
End Function
Public Function GetBitmapWait() As Bitmap
Dim BM As Bitmap
While GetBitmap(BM) = eError.OpenError
Application.DoEvents()
End While
Return BM
End Function
End Module
End Namespace
...
Dim BM As Bitmap = New Bitmap(1000, 1000, Drawing.Imaging.PixelFormat.Format24bppRgb)
Dim K As Integer
'Clipboard.SetDataObject(New DataObject(BM))
K = 0
BM = Clipboard.GetBitmapWait()
Do While Not (BM Is Nothing)
ListBox.Items.Add(CStr(K))
K += 1
BM.Dispose()
BM = Nothing
BM = Clipboard.GetBitmapWait()
Application.DoEvents()
Loop
Проблема была в System.Windows.Forms.Clipboard.