473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Picturedata to image

i have picturedata and i want to save that to image file how i can do that

i have this function but not working for all images
Expand|Select|Wrap|Line Numbers
  1. Function FPictureDataToClipBoard(ctl As Variant) As Boolean
  2. ' Memory Vars
  3. Dim hGlobalMemory As Long
  4. Dim lpGlobalMemory As Long
  5. Dim hClipMemory As Long
  6.  
  7. ' Cf_metafilepict structure
  8. Dim cfm As METAFILEPICT
  9.  
  10. ' Handle to a Memory Metafile
  11. Dim hMetafile As Long
  12.  
  13. ' Which ClipBoard format is contained in the PictureData prop
  14. Dim CBFormat As Long
  15.  
  16. ' Byte array to hold the PictureData prop
  17. Dim bArray() As Byte
  18.  
  19. ' Temp var
  20. Dim lngRet As Long
  21.  
  22. On Error GoTo Err_PtoC
  23.  
  24. ' Resize to hold entire PictureData prop
  25. ReDim bArray(LenB(ctl) - 1)
  26.  
  27. ' Copy to our array
  28. bArray = ctl
  29.  
  30. ' Determine which ClipBoard format we are using
  31. Select Case bArray(0)
  32.  
  33.  
  34. Case 40
  35. ' This is a straight DIB.
  36. CBFormat = CF_DIB
  37. ' MSDN states to Allocate moveable|Shared Global memory
  38. ' for ClipBoard operations.
  39. hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE Or GMEM_SHARE Or GMEM_ZEROINIT, UBound(bArray) + 1)
  40. If hGlobalMemory = 0 Then _
  41. Err.Raise vbObjectError + 515, "ImageToClipBoard.modImageToClipBoard", _
  42.    "GlobalAlloc Failed..not enough memory"
  43.  
  44. ' Lock this block to get a pointer we can use to this memory.
  45. lpGlobalMemory = GlobalLock(hGlobalMemory)
  46. If lpGlobalMemory = 0 Then _
  47. Err.Raise vbObjectError + 516, "ImageToClipBoard.modImageToClipBoard", _
  48.    "GlobalLock Failed"
  49.  
  50. ' Copy DIB as is in its entirety
  51. apiCopyMemory ByVal lpGlobalMemory, bArray(0), UBound(bArray) + 1
  52.  
  53. ' Unlock the memory in preparation to copy to the clipboard
  54. If GlobalUnlock(hGlobalMemory) <> 0 Then _
  55. Err.Raise vbObjectError + 517, "ImageToClipBoard.modImageToClipBoard", _
  56.    "GlobalUnLock Failed"
  57.  
  58.  
  59. Case CF_ENHMETAFILE
  60. ' New Enhanced Metafile(EMF)
  61. CBFormat = CF_ENHMETAFILE
  62. ' Create a Memory based Metafile we can pass to the ClipBoard
  63. hMetafile = SetEnhMetaFileBits(UBound(bArray) + 1 - 8, bArray(8))
  64.  
  65.  
  66. Case CF_METAFILEPICT
  67. ' Old Metafile format(WMF)
  68. CBFormat = CF_METAFILEPICT
  69. ' Create a Memory based Metafile we can pass to the ClipBoard
  70. ' We need to convert from the older WMF to the new EMF format
  71. ' Copy the Metafile Header over to our Local Structure
  72. apiCopyMemory cfm, bArray(8), Len(cfm)
  73. ' By converting the older WMF to EMF this
  74. ' allows us to have a single solution for Metafiles.
  75. ' 24 is the number of bytes in the sum of the
  76. ' METAFILEPICT structure and the 8 byte ClipBoard Format struct.
  77. hMetafile = SetWinMetaFileBits(UBound(bArray) + 24 + 1 - 8, bArray(24), 0&, cfm)
  78.  
  79.  
  80. Case Else
  81. 'Should not happen
  82. Err.Raise vbObjectError + 514, "ImageToClipBoard.modImageToClipBoard", _
  83.    "Unrecognized PictureData ClipBoard format"
  84.  
  85. End Select
  86.  
  87.  ' Can we open the ClipBoard.
  88. If OpenClipboard(0&) = 0 Then _
  89. Err.Raise vbObjectError + 518, "ImageToClipBoard.modImageToClipBoard", _
  90. "OpenClipBoard Failed"
  91.  
  92. ' Always empty the ClipBoard First. Not the friendliest thing
  93. ' to do if you have several programs interacting!
  94. Call EmptyClipboard
  95.  
  96. ' Now set the Image to the ClipBoard
  97. If CBFormat = CF_ENHMETAFILE Or CBFormat = CF_METAFILEPICT Then
  98.  
  99.     ' Remember we can use this logic for both types of Metafiles
  100.     ' because we converted the older WMF to the newer EMF.
  101.     hClipMemory = SetClipboardData(CF_ENHMETAFILE, hMetafile)
  102.  
  103. Else
  104. ' We are dealing with a standard DIB.
  105. hClipMemory = SetClipboardData(CBFormat, hGlobalMemory)
  106.  
  107. End If
  108.  
  109. If hClipMemory = 0 Then _
  110.     Err.Raise vbObjectError + 519, "ImageToClipBoard.modImageToClipBoard", _
  111.     "SetClipBoardData Failed"
  112.  
  113. ' Close the ClipBoard
  114. lngRet = CloseClipboard
  115. If lngRet = 0 Then _
  116.     Err.Raise vbObjectError + 520, "ImageToClipBoard.modImageToClipBoard", _
  117.     "CloseClipBoard Failed"
  118.  
  119.   ' Signal Success!
  120. FPictureDataToClipBoard = True
  121.  
  122.  
  123. Exit_PtoC:
  124. Exit Function
  125.  
  126.  
  127. Err_PtoC:
  128. FPictureDataToClipBoard = False
  129. MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
  130. Resume Exit_PtoC
  131.  
  132. End Function
i need a function that work for all type of images like embaded on button image ole log how i can do that
Oct 22 '09 #1
1 7387
maxamis4
295 Expert 100+
My friend here you go. This is an unbound object way of doing pictures.

http://www.databasedev.co.uk/image-form.html

As far as the buttons go, what you need to do is name the controls in a table based on the names. Reference the names in the table with the controls in the form, while looping through the form controls and find the image associated with the name. I hope i am making sense.
Oct 30 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: trojacek | last post by:
I'm trying to load image data stored in an OLE field into an image list, that will be used by a treeview to show icons. This is at run time. To do this, I'm trying to load the field which...
2
by: deko | last post by:
I have a table that contains a bunch of pictures. When the user selects a particular image in a form, I need a way to extract the selected bitmap image (stored in an OLE Object table field) to the...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: Frank Schlüter | last post by:
Hello, I want to fill an Access-image by an MS-ImageList. The Access-image has the properties "picture" and "picturedata". "Picture" is only for load from File or BMP, "picturedata" doesn't...
2
by: Dominic Vella | last post by:
Hi, I know I seem to have the really complicated questions, but I guess that's why I'm here. This is a little verbose, only because I've been trying to crack this for a week now. Your help...
5
by: Dominic Vella | last post by:
Does anyone have any details on what the PictureData structure looks like? Thanks in advance. Dominic
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.