Hello gurus,
I have a System.IntPtr pointing to the memory address of my image (not a
..NET image).
I wish to save this image data pointed by the IntPtr to a raw data file. The
way I now to that is:
System.IO.FileS tream file = new System.IO.FileS tream(fileName,
System.IO.FileM ode.Create);
file.Write(byte[], 0, ...);
file.Close();
But the FileStream.Writ e takes byte[] which I do not have.
How can I save this image data pointed by IntPtr to file?
---------
Thanks
Sharon 15 8346
Is your IntPtr a bitmap handle (hBitmap) or a direct pointer to raw data?
If it is, you could construct an Image.FromHBitm ap and then serialize the
image class.
Otherwise you need to convert it to a byte[], for example by means of
System.Runtime. InteropServices .Marshal.ReadIn tPtr or like.
Laura
"Sharon" <Sh*****@newsgr oups.nospam> ha scritto nel messaggio
news:4A******** *************** ***********@mic rosoft.com... Hello gurus,
I have a System.IntPtr pointing to the memory address of my image (not a .NET image). I wish to save this image data pointed by the IntPtr to a raw data file. The way I now to that is:
System.IO.FileS tream file = new System.IO.FileS tream(fileName, System.IO.FileM ode.Create); file.Write(byte[], 0, ...); file.Close();
But the FileStream.Writ e takes byte[] which I do not have. How can I save this image data pointed by IntPtr to file? --------- Thanks Sharon
"Sharon" <Sh*****@newsgr oups.nospam> wrote in message
news:4A******** *************** ***********@mic rosoft.com...
| Hello gurus,
|
| I have a System.IntPtr pointing to the memory address of my image (not a
| .NET image).
| I wish to save this image data pointed by the IntPtr to a raw data file.
The
| way I now to that is:
|
| System.IO.FileS tream file = new System.IO.FileS tream(fileName,
| System.IO.FileM ode.Create);
| file.Write(byte[], 0, ...);
| file.Close();
|
| But the FileStream.Writ e takes byte[] which I do not have.
| How can I save this image data pointed by IntPtr to file?
|
|
|
| ---------
| Thanks
| Sharon
You can use Marshal.Copy to copy the memory contents to a byte[].
Willy.
Sharon,
The fact that you are using IntPtr makes me believe that your data is in
unmanaged memory. To get the data in managed byte array you can use
System.Runtime. InteropServices .Marshal class.
You can use the Marshal.ReadByt e methods to loop through the data in
unmanaged memory and copy it one byte at a time in a managed byte[] or you
can create a structure with byte array in it and use Marshal.PtrToSt ructure
method to read it at once. The latter I haven't tried, but should work.
--
HTH
Stoitcho Goutsev (100)
"Sharon" <Sh*****@newsgr oups.nospam> wrote in message
news:4A******** *************** ***********@mic rosoft.com... Hello gurus,
I have a System.IntPtr pointing to the memory address of my image (not a .NET image). I wish to save this image data pointed by the IntPtr to a raw data file. The way I now to that is:
System.IO.FileS tream file = new System.IO.FileS tream(fileName, System.IO.FileM ode.Create); file.Write(byte[], 0, ...); file.Close();
But the FileStream.Writ e takes byte[] which I do not have. How can I save this image data pointed by IntPtr to file? --------- Thanks Sharon
Willy,
Isn't it Marshal.Copy copy from managed to unmanaged? In other words from
byte[] to memory pointed by IntPtr. I think Sharon needs the other way
around.
--
Stoitcho Goutsev (100)
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:uX******** ******@TK2MSFTN GP04.phx.gbl... "Sharon" <Sh*****@newsgr oups.nospam> wrote in message news:4A******** *************** ***********@mic rosoft.com... | Hello gurus, | | I have a System.IntPtr pointing to the memory address of my image (not a | .NET image). | I wish to save this image data pointed by the IntPtr to a raw data file. The | way I now to that is: | | System.IO.FileS tream file = new System.IO.FileS tream(fileName, | System.IO.FileM ode.Create); | file.Write(byte[], 0, ...); | file.Close(); | | But the FileStream.Writ e takes byte[] which I do not have. | How can I save this image data pointed by IntPtr to file? | | | | --------- | Thanks | Sharon
You can use Marshal.Copy to copy the memory contents to a byte[].
Willy.
There are overloads for both from managed to unmanaged and unmanaged to
managed.
Willy.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:Od******** ******@TK2MSFTN GP02.phx.gbl...
| Willy,
|
| Isn't it Marshal.Copy copy from managed to unmanaged? In other words from
| byte[] to memory pointed by IntPtr. I think Sharon needs the other way
| around.
|
|
| --
|
| Stoitcho Goutsev (100)
|
| "Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
| news:uX******** ******@TK2MSFTN GP04.phx.gbl...
| >
| > "Sharon" <Sh*****@newsgr oups.nospam> wrote in message
| > news:4A******** *************** ***********@mic rosoft.com...
| > | Hello gurus,
| > |
| > | I have a System.IntPtr pointing to the memory address of my image (not
a
| > | .NET image).
| > | I wish to save this image data pointed by the IntPtr to a raw data
file.
| > The
| > | way I now to that is:
| > |
| > | System.IO.FileS tream file = new System.IO.FileS tream(fileName,
| > | System.IO.FileM ode.Create);
| > | file.Write(byte[], 0, ...);
| > | file.Close();
| > |
| > | But the FileStream.Writ e takes byte[] which I do not have.
| > | How can I save this image data pointed by IntPtr to file?
| > |
| > |
| > |
| > | ---------
| > | Thanks
| > | Sharon
| >
| > You can use Marshal.Copy to copy the memory contents to a byte[].
| >
| > Willy.
| >
| >
|
|
Hi,
You are correct, Copy is to send data to unmanaged
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:Od******** ******@TK2MSFTN GP02.phx.gbl... Willy,
Isn't it Marshal.Copy copy from managed to unmanaged? In other words from byte[] to memory pointed by IntPtr. I think Sharon needs the other way around.
--
Stoitcho Goutsev (100)
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message news:uX******** ******@TK2MSFTN GP04.phx.gbl... "Sharon" <Sh*****@newsgr oups.nospam> wrote in message news:4A******** *************** ***********@mic rosoft.com... | Hello gurus, | | I have a System.IntPtr pointing to the memory address of my image (not a | .NET image). | I wish to save this image data pointed by the IntPtr to a raw data file. The | way I now to that is: | | System.IO.FileS tream file = new System.IO.FileS tream(fileName, | System.IO.FileM ode.Create); | file.Write(byte[], 0, ...); | file.Close(); | | But the FileStream.Writ e takes byte[] which I do not have. | How can I save this image data pointed by IntPtr to file? | | | | --------- | Thanks | Sharon
You can use Marshal.Copy to copy the memory contents to a byte[].
Willy.
Hi,
I find hard to believe there is no way to copy a chunk of data from
unmanaged memory, I was under the impression that Copy worked both way ,
It's not it can only be used from managed to unmanaged.
I haven't been able to find the other way around though.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message
news:Og******** ******@TK2MSFTN GP02.phx.gbl... Sharon,
The fact that you are using IntPtr makes me believe that your data is in unmanaged memory. To get the data in managed byte array you can use System.Runtime. InteropServices .Marshal class. You can use the Marshal.ReadByt e methods to loop through the data in unmanaged memory and copy it one byte at a time in a managed byte[] or you can create a structure with byte array in it and use Marshal.PtrToSt ructure method to read it at once. The latter I haven't tried, but should work.
-- HTH Stoitcho Goutsev (100) "Sharon" <Sh*****@newsgr oups.nospam> wrote in message news:4A******** *************** ***********@mic rosoft.com... Hello gurus,
I have a System.IntPtr pointing to the memory address of my image (not a .NET image). I wish to save this image data pointed by the IntPtr to a raw data file. The way I now to that is:
System.IO.FileS tream file = new System.IO.FileS tream(fileName, System.IO.FileM ode.Create); file.Write(byte[], 0, ...); file.Close();
But the FileStream.Writ e takes byte[] which I do not have. How can I save this image data pointed by IntPtr to file? --------- Thanks Sharon
Still using V1.0? Marshal.Copy has overloads to copy from unmanaged to
managed since v1.1. http://msdn.microsoft.com/library/de...scopytopic.asp
Willy.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:Ov******** ******@TK2MSFTN GP03.phx.gbl...
| Hi,
|
| You are correct, Copy is to send data to unmanaged
|
|
| --
| Ignacio Machin,
| ignacio.machin AT dot.state.fl.us
| Florida Department Of Transportation
|
| "Stoitcho Goutsev (100)" <10*@100.com> wrote in message
| news:Od******** ******@TK2MSFTN GP02.phx.gbl...
| > Willy,
| >
| > Isn't it Marshal.Copy copy from managed to unmanaged? In other words
from
| > byte[] to memory pointed by IntPtr. I think Sharon needs the other way
| > around.
| >
| >
| > --
| >
| > Stoitcho Goutsev (100)
| >
| > "Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
| > news:uX******** ******@TK2MSFTN GP04.phx.gbl...
| >>
| >> "Sharon" <Sh*****@newsgr oups.nospam> wrote in message
| >> news:4A******** *************** ***********@mic rosoft.com...
| >> | Hello gurus,
| >> |
| >> | I have a System.IntPtr pointing to the memory address of my image
(not
| >> a
| >> | .NET image).
| >> | I wish to save this image data pointed by the IntPtr to a raw data
| >> file.
| >> The
| >> | way I now to that is:
| >> |
| >> | System.IO.FileS tream file = new System.IO.FileS tream(fileName,
| >> | System.IO.FileM ode.Create);
| >> | file.Write(byte[], 0, ...);
| >> | file.Close();
| >> |
| >> | But the FileStream.Writ e takes byte[] which I do not have.
| >> | How can I save this image data pointed by IntPtr to file?
| >> |
| >> |
| >> |
| >> | ---------
| >> | Thanks
| >> | Sharon
| >>
| >> You can use Marshal.Copy to copy the memory contents to a byte[].
| >>
| >> Willy.
| >>
| >>
| >
| >
|
|
Yup, you are right. My apologies.
--
Stoitcho Goutsev (100)
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. .. There are overloads for both from managed to unmanaged and unmanaged to managed.
Willy.
"Stoitcho Goutsev (100)" <10*@100.com> wrote in message news:Od******** ******@TK2MSFTN GP02.phx.gbl... | Willy, | | Isn't it Marshal.Copy copy from managed to unmanaged? In other words from | byte[] to memory pointed by IntPtr. I think Sharon needs the other way | around. | | | -- | | Stoitcho Goutsev (100) | | "Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message | news:uX******** ******@TK2MSFTN GP04.phx.gbl... | > | > "Sharon" <Sh*****@newsgr oups.nospam> wrote in message | > news:4A******** *************** ***********@mic rosoft.com... | > | Hello gurus, | > | | > | I have a System.IntPtr pointing to the memory address of my image (not a | > | .NET image). | > | I wish to save this image data pointed by the IntPtr to a raw data file. | > The | > | way I now to that is: | > | | > | System.IO.FileS tream file = new System.IO.FileS tream(fileName, | > | System.IO.FileM ode.Create); | > | file.Write(byte[], 0, ...); | > | file.Close(); | > | | > | But the FileStream.Writ e takes byte[] which I do not have. | > | How can I save this image data pointed by IntPtr to file? | > | | > | | > | | > | --------- | > | Thanks | > | Sharon | > | > You can use Marshal.Copy to copy the memory contents to a byte[]. | > | > Willy. | > | > | |
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Maya |
last post by:
Hey, there!
I'm new to vb.net and it seems I wouldn't be able to solve this
without help.
I have a pipe delimited file that has to be saved in txt format
so it could be accepted by my DTS package.
If I open and save the file manualy in Wordpad - it works.
(not in Notepad otherwise formatting is changed and DTS package
won't accept it.)
|
by: JTMar |
last post by:
I need to save a file in UTF-8 format from an ASP file.
Using FileSystemObject I can only save them in Unicode (UTF-16, I think) but
not in UTF-8:
Set zzzz = fso.OpenTextFile(filepath, 2, true, -1)
How do I can save my file in UTF-8 format ?
I have tried to convert the file to UTF-8, with this code:
|
by: a |
last post by:
Save text file as html kloepper 17:42 23 Jul '04
I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html tags in this text file to well formed XHTML tags). The contents of the file contain html tags and the data in those tags.
eg.,
<table cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<tr>
<td width="48%"></td>
<td...
|
by: Alvo von Cossel I |
last post by:
hi,
i have a textbox in a form. when you press a Save button, a savefiledialog
appears. creating ther file works but everytime you click save, the dialog
appears. how do i make the dialog appear once and then only save the file?
thanx
--
Alvo von Cossel I of Germany
|
by: DanB |
last post by:
This is probably soooo simple but I can't seem to get it.
I have a text file that I want users to download via a web page.
I want the file to be saved to a default folder (or one that they choose)
on the users / client file system.
I have toyed with a Self-Extracting zip file but the contents of my zip file
changes each time it is downloaded so that invalidates the exe file. Also
the text file is so small it is a waste to zip it.
| |
by: Patrick |
last post by:
Following on from the excellent example at
http://www.c-sharpcorner.com/Code/2003/Sept/ExportASPNetDataGridToExcel.asp
on how to save a data-grid to excel file, how can I extend the example such
that when the user click on the button a popup appear in IE to say "Do you
want to save or open file?"
|
by: Jennyfer Barco |
last post by:
A Web Application
Hello I have a .NET project, a Web Application and I need to save a file
with some data the
user selects. If I use the command FileOpen it will save the file in the
server and not in the local machine where I'm running the application. Is
there a way to save a file in the local machine and not the web server. I
use the function GetFolders and brings me the directories in the path but
for the server machine, not the...
|
by: Matt |
last post by:
Hi,
I would like to save a file locally (on the client computer) in an ASP.net
application.
It is like the server would return some data that the user can save to a
file on his local PC.
The ASP page has a text field to type in the file path directly and a
"Browse..." button, that shall display a "Save as..." dialog.
I tried with the FileUpload control, but this does not work, since I do not
want to upload an existing file, but I want to...
|
by: jaikant |
last post by:
Hi,
I am loading a xml file using javascript in Pocket Internet Explorer for local HTML file. I am not able to save the xml file back to the PPC device.
foodXML = new ActiveXObject("Msxml2.DOMDocument");
newElement = foodXML.createElement(textstr);
foodXML.appendChild(newElement);
foodXML.save("test.xml");
Please help me to save xml file to local folder using javascript.
Thanks
|
by: Busbait |
last post by:
Hi,
The below code will allow the user to open the Save As dialog box,
Now my question is : after the user specify the file name and the path, how can I modify the below code in order to save the file in Excel format when the user click on the Save button
What I need is to use the file name which was specified by the user in the dialog box , and then create an Excel file using the same name & path and the new excel file should...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |