How to Convert BMP Image in PictureBox to Array of Bytes in VB6Convert a Picture Box image pixels to a Byte Array in VB6How do I check if an array includes an object in JavaScript?How do you convert a byte array to a hexadecimal string, and vice versa?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do you check if a variable is an array in JavaScript?How do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How do I empty an array in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
What is the tangent at a sharp point on a curve?
Do I have to take mana from my deck or hand when tapping this card?
Exposing a company lying about themselves in a tightly knit industry (videogames) : Is my career at risk on the long run?
Reason why a kingside attack is not justified
Strange behavior in TikZ draw command
New Order #2: Turn My Way
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Amorphous proper classes in MK
Is this saw blade faulty?
Friend wants my recommendation but I don't want to give it to him
Calculate Pi using Monte Carlo
Would a primitive species be able to learn English from reading books alone?
Mac Mini (2018) 10Gb Port Compatibility
Is there any common country to visit for persons holding UK and Schengen visas?
Why didn’t Eve recognize the little cockroach as a living organism?
"Oh no!" in Latin
I keep switching characters, how do I stop?
Why is "la Gestapo" feminine?
Mortal danger in mid-grade literature
Should a narrator ever describe things based on a character's view instead of facts?
How can I, as DM, avoid the Conga Line of Death occurring when implementing some form of flanking rule?
What is it called when someone votes for an option that's not their first choice?
What is the meaning of "You've never met a graph you didn't like?"
Weird lines in Microsoft Word
How to Convert BMP Image in PictureBox to Array of Bytes in VB6
Convert a Picture Box image pixels to a Byte Array in VB6How do I check if an array includes an object in JavaScript?How do you convert a byte array to a hexadecimal string, and vice versa?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do you check if a variable is an array in JavaScript?How do I determine whether an array contains a particular value in Java?How do I declare and initialize an array in Java?How do I empty an array in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?
In a legacy VB6 application I have a BMP image stored in a PictureBox. I am able to save it to a BMP file using:
SavePicture picBox.Picture, "BmpImage.bmp"
However what I want is to save the BMP image in the PictureBox to an array of bytes. I need the entire BMP to be stored including the BMP headers. Effectively I want the same data that would be written to the BMP file but in a Byte array and without having to write and read a disk file.
I've searched but have not found anything online that addresses this particular question.
I did find one link that suggested writing to a MemoryStream. So I tried this:
10 Dim bmpArray() As Byte
20 Dim memStream As New System.IO.MemoryStream
50 SavePicture picBox.Picture, memStream
60 bmpArray = memStream.GetBuffer
However this doesn't compile. I get "User-defined type not defined" for "System.IO.MemoryStream" I've included System in my list of references. I've also tried declaring as New MemoryStream but still get the "User-defeind type not defined" compiler error.
Also I have looked at a similar question however the solution provided only stores the pixel data in the array.
arrays vb6 picturebox memorystream bmp
|
show 3 more comments
In a legacy VB6 application I have a BMP image stored in a PictureBox. I am able to save it to a BMP file using:
SavePicture picBox.Picture, "BmpImage.bmp"
However what I want is to save the BMP image in the PictureBox to an array of bytes. I need the entire BMP to be stored including the BMP headers. Effectively I want the same data that would be written to the BMP file but in a Byte array and without having to write and read a disk file.
I've searched but have not found anything online that addresses this particular question.
I did find one link that suggested writing to a MemoryStream. So I tried this:
10 Dim bmpArray() As Byte
20 Dim memStream As New System.IO.MemoryStream
50 SavePicture picBox.Picture, memStream
60 bmpArray = memStream.GetBuffer
However this doesn't compile. I get "User-defined type not defined" for "System.IO.MemoryStream" I've included System in my list of references. I've also tried declaring as New MemoryStream but still get the "User-defeind type not defined" compiler error.
Also I have looked at a similar question however the solution provided only stores the pixel data in the array.
arrays vb6 picturebox memorystream bmp
2
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14
|
show 3 more comments
In a legacy VB6 application I have a BMP image stored in a PictureBox. I am able to save it to a BMP file using:
SavePicture picBox.Picture, "BmpImage.bmp"
However what I want is to save the BMP image in the PictureBox to an array of bytes. I need the entire BMP to be stored including the BMP headers. Effectively I want the same data that would be written to the BMP file but in a Byte array and without having to write and read a disk file.
I've searched but have not found anything online that addresses this particular question.
I did find one link that suggested writing to a MemoryStream. So I tried this:
10 Dim bmpArray() As Byte
20 Dim memStream As New System.IO.MemoryStream
50 SavePicture picBox.Picture, memStream
60 bmpArray = memStream.GetBuffer
However this doesn't compile. I get "User-defined type not defined" for "System.IO.MemoryStream" I've included System in my list of references. I've also tried declaring as New MemoryStream but still get the "User-defeind type not defined" compiler error.
Also I have looked at a similar question however the solution provided only stores the pixel data in the array.
arrays vb6 picturebox memorystream bmp
In a legacy VB6 application I have a BMP image stored in a PictureBox. I am able to save it to a BMP file using:
SavePicture picBox.Picture, "BmpImage.bmp"
However what I want is to save the BMP image in the PictureBox to an array of bytes. I need the entire BMP to be stored including the BMP headers. Effectively I want the same data that would be written to the BMP file but in a Byte array and without having to write and read a disk file.
I've searched but have not found anything online that addresses this particular question.
I did find one link that suggested writing to a MemoryStream. So I tried this:
10 Dim bmpArray() As Byte
20 Dim memStream As New System.IO.MemoryStream
50 SavePicture picBox.Picture, memStream
60 bmpArray = memStream.GetBuffer
However this doesn't compile. I get "User-defined type not defined" for "System.IO.MemoryStream" I've included System in my list of references. I've also tried declaring as New MemoryStream but still get the "User-defeind type not defined" compiler error.
Also I have looked at a similar question however the solution provided only stores the pixel data in the array.
arrays vb6 picturebox memorystream bmp
arrays vb6 picturebox memorystream bmp
edited Mar 7 at 12:28
DaveInCaz
3,32632041
3,32632041
asked Mar 7 at 0:56
JonNJonN
1,24122140
1,24122140
2
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14
|
show 3 more comments
2
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14
2
2
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14
|
show 3 more comments
2 Answers
2
active
oldest
votes
If you literally want the exact contents of the BMP file as an array of bytes, why not do it in steps?
Step 1: Use SavePicture to write to a temporary file.
Step 2: Use normal file I/O operations to read the temporary file back into an array.
Step 3: Delete the temp file
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
add a comment |
There are functions in GDI32
that make it simple to get an array from an image. I can't post working code here because I've written much of it in assembly using custom Types etc, but I can tell you to start your search at GetDIBits()
, where the 'DI' stands for Device Independent.
Here's a declaration for it:
Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFO, _
ByVal wUsage As Long)
Use the .hDC
of the picture box.
You'll need definitions for BITMAPINFO
, BITMAPINFOHEADER
etc but it sounds as if you may already have those.
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034467%2fhow-to-convert-bmp-image-in-picturebox-to-array-of-bytes-in-vb6%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you literally want the exact contents of the BMP file as an array of bytes, why not do it in steps?
Step 1: Use SavePicture to write to a temporary file.
Step 2: Use normal file I/O operations to read the temporary file back into an array.
Step 3: Delete the temp file
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
add a comment |
If you literally want the exact contents of the BMP file as an array of bytes, why not do it in steps?
Step 1: Use SavePicture to write to a temporary file.
Step 2: Use normal file I/O operations to read the temporary file back into an array.
Step 3: Delete the temp file
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
add a comment |
If you literally want the exact contents of the BMP file as an array of bytes, why not do it in steps?
Step 1: Use SavePicture to write to a temporary file.
Step 2: Use normal file I/O operations to read the temporary file back into an array.
Step 3: Delete the temp file
If you literally want the exact contents of the BMP file as an array of bytes, why not do it in steps?
Step 1: Use SavePicture to write to a temporary file.
Step 2: Use normal file I/O operations to read the temporary file back into an array.
Step 3: Delete the temp file
edited Mar 7 at 15:39
answered Mar 7 at 12:28
DaveInCazDaveInCaz
3,32632041
3,32632041
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
add a comment |
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
That's what I'm currently doing as a "work around". However as I stated in my question, I want to do this without having to write to a temp file. I have to believe there is a way to do this in VB6 without resorting to writing to disk.
– JonN
Mar 7 at 21:23
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
Why do you consider this to be a workaround? The in-memory format of an image in the PictuteBox is probably not the same as the binary representation do the same image in Bitmap format. And in fact there are multiple variations of what can be in a "BMP" format.
– DaveInCaz
Mar 11 at 12:25
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
It's a workaround because one of the requirements for this scenario in my application is avoiding writing to disk. The whole point of the new feature being added is to eliminating disk writes.
– JonN
Mar 11 at 21:13
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
Fair enough... curious though what the restriction on writing to disk?
– DaveInCaz
Mar 11 at 21:16
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
In an earlier version of the project two components exchanged images via disk files. One of those components is my application (ActiveX EXE in VB6) The other component which my application delivers images to is from 3rd party. A more recent version of the 3rd party component now accepts images directly through memory. This was done to speedup the image exchange. So to have to write the image to disk in order to get it into memory defeats the intended design improvement. The 3rd party is expecting my app to deliver the image directly in memory without wasting time writing to disk.
– JonN
Mar 11 at 21:26
add a comment |
There are functions in GDI32
that make it simple to get an array from an image. I can't post working code here because I've written much of it in assembly using custom Types etc, but I can tell you to start your search at GetDIBits()
, where the 'DI' stands for Device Independent.
Here's a declaration for it:
Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFO, _
ByVal wUsage As Long)
Use the .hDC
of the picture box.
You'll need definitions for BITMAPINFO
, BITMAPINFOHEADER
etc but it sounds as if you may already have those.
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
add a comment |
There are functions in GDI32
that make it simple to get an array from an image. I can't post working code here because I've written much of it in assembly using custom Types etc, but I can tell you to start your search at GetDIBits()
, where the 'DI' stands for Device Independent.
Here's a declaration for it:
Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFO, _
ByVal wUsage As Long)
Use the .hDC
of the picture box.
You'll need definitions for BITMAPINFO
, BITMAPINFOHEADER
etc but it sounds as if you may already have those.
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
add a comment |
There are functions in GDI32
that make it simple to get an array from an image. I can't post working code here because I've written much of it in assembly using custom Types etc, but I can tell you to start your search at GetDIBits()
, where the 'DI' stands for Device Independent.
Here's a declaration for it:
Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFO, _
ByVal wUsage As Long)
Use the .hDC
of the picture box.
You'll need definitions for BITMAPINFO
, BITMAPINFOHEADER
etc but it sounds as if you may already have those.
There are functions in GDI32
that make it simple to get an array from an image. I can't post working code here because I've written much of it in assembly using custom Types etc, but I can tell you to start your search at GetDIBits()
, where the 'DI' stands for Device Independent.
Here's a declaration for it:
Public Declare Sub GetDIBits Lib "gdi32" _
(ByVal hDC As Long, _
ByVal hBitmap As Long, _
ByVal nStartScan As Long, _
ByVal nNumScans As Long, _
ByRef lpBits As Any, _
ByRef lpBI As BITMAPINFO, _
ByVal wUsage As Long)
Use the .hDC
of the picture box.
You'll need definitions for BITMAPINFO
, BITMAPINFOHEADER
etc but it sounds as if you may already have those.
answered Mar 8 at 0:37
Jim MackJim Mack
6561413
6561413
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
add a comment |
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
I looked up GetDIBits and it appears to have a variety of behaviors based on the input parameters provided. I don't see a straightforward call scenario that would return the entire BMP array including headers and pixel data as an array of bytes. At best it looks like you would need to retrieve the BMP header, palette and pixel data separately and assemble them somehow into an array of bytes yourself. Is that what you had in mind?
– JonN
Mar 8 at 22:31
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
@JonN - You can create your array with the headers in place, then point GetDIBits at the place in the array where the data belongs. Done. Aside from writing/reading as a file or pipe I don't know any way to get the BMP header built for you.
– Jim Mack
Mar 8 at 22:47
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
Don't the headers vary in size depending on the particular BMP format being used? Aren't there two different versions of the header and the palette section can vary in size too, Right? So would the technique be to read in some portion of the header and then from that determine the sizes of the various headers and select the position in the array for each section accordingly?
– JonN
Mar 8 at 22:53
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55034467%2fhow-to-convert-bmp-image-in-picturebox-to-array-of-bytes-in-vb6%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The code you're attempting to use is for VB.Net, thus the error...
– Idle_Mind
Mar 7 at 3:00
JonN, @Idle_Mind was referring to the memorystream code. That doesn't exist in VB6.
– DaveInCaz
Mar 7 at 12:24
If you have the option to write .NET code, you could possibly create a VB.NET class which does whatever you want, and call that from VB6. There's some initial setup overhead in getting that to work of course, plus whatever deployment changes you'd have to make.
– DaveInCaz
Mar 7 at 12:25
@Idle_Mind yes I suspected that it was because the 1st link was a solution for .NET but thought I'd try it and see if MemoryStream was available in VB6. I'm hoping someone here knows how to create equivalent of a memory stream in VB6 or some other way to convert PictureBox to array of bytes.
– JonN
Mar 7 at 21:27
Do some searches. There is a lot of code around for doing this in VB6, but it isn't the kind of thing easily posted here because there are a lot of little steps and each should have error checking as you go. This site is better suited to simple Q & A rather than requesting code samples aside from tiny ones.
– Bob77
Mar 8 at 21:14