473,834 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Array of Int to image

Hi,

i have a array of uint[] and want to display this array as a
System.Web.UI.W ebControls.Imag e.
//=============== =============== ===========
uint [] ar = new uint[3072];
string fName;

System.Web.UI.W ebControls.Imag e i = new System.Web.UI.W ebControls.Imag e();
vm.Display._Gen erateThumbnail( ar);
fName = "c:\\temp\\ f_" + vm.Name + ".bmp";

SaveArrayToFile (ar,fName);
i.ImageUrl = fName;
i.ID = "I_1";
Panel1.Controls .Add(i);

private void SaveArrayToFile (uint [] ar, string FileName)
{
FileStream fs = new FileStream(File Name, FileMode.Create );
BinaryWriter w = new BinaryWriter(fs );
for (int i = 0; i < ar.Length; i++)
{
w.Write(ar[i]);
}
w.Close();
fs.Close();
}

//=============== =============== ===========

The problem is, that the pictures aren't shown, as the picures are garbage.
What is wrong ?

Best regards

Clas

--
The light at the end of the tunnel,
was switch off due to high costs.
Nov 16 '05 #1
2 7932
Hi Clas,

Let's first step through your code. You create an Image class instance. Then
you call a method which you haven't told us anything about. It seems to be
generating a thumbnail from the (empty) image you just created, although I
can't tell for sure, again, because you've told us nothing about it. But it
gets worse. Now you call a method called "SaveArrayToFil e" which writes the
array to a file specified in the previous line. Note that you have abandoned
the Image class which you created empty. You never do anything with it, nor
do you associate it in any way with a file. I have no idea why you would
think that this creates an image of any kind. An image file is not created
by writing an array of unsigned integers to a file. What you DO get is a
binary file containing an array of unsigned integers.

Okay, let's talk about how to do it right. Yes, you DO need to create an
Image, but more specifically, a Bitmap. You need to make sure that no value
in your array is greater than 255, or less than 0. That is the maximum and
minimum values of a pixel byte. And your array elements must match the size
of a byte, or you will have to convert them on the fly, which is expensive.
And your array must have "width * height" values in it (width and height of
the Bitmap).

Now you have 2 choices. You can use Managed code to loop through the pixels,
using the Bitmap.GetPixel () method, and set the values of each R,G, and B
byte, or you can use an unsafe code block (more complicated, but much
faster) to loop through the pixels of the Bitmap with a pointer, and set
them that way.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Clas Hortien" <ho*****@hotmai l.com> wrote in message
news:ci******** **@news1.wdf.sa p-ag.de...
Hi,

i have a array of uint[] and want to display this array as a
System.Web.UI.W ebControls.Imag e.
//=============== =============== ===========
uint [] ar = new uint[3072];
string fName;

System.Web.UI.W ebControls.Imag e i = new System.Web.UI.W ebControls.Imag e();
vm.Display._Gen erateThumbnail( ar);
fName = "c:\\temp\\ f_" + vm.Name + ".bmp";

SaveArrayToFile (ar,fName);
i.ImageUrl = fName;
i.ID = "I_1";
Panel1.Controls .Add(i);

private void SaveArrayToFile (uint [] ar, string FileName)
{
FileStream fs = new FileStream(File Name, FileMode.Create );
BinaryWriter w = new BinaryWriter(fs );
for (int i = 0; i < ar.Length; i++)
{
w.Write(ar[i]);
}
w.Close();
fs.Close();
}

//=============== =============== ===========

The problem is, that the pictures aren't shown, as the picures are garbage. What is wrong ?

Best regards

Clas

--
The light at the end of the tunnel,
was switch off due to high costs.

Nov 16 '05 #2
Clas Hortien <ho*****@hotmai l.com> wrote:
i have a array of uint[] and want to display this array as a
System.Web.UI.W ebControls.Imag e.


Well, how does the array of uints relate to the actual image? Where did
you get them from?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
50642
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I convert the following code so that the Pic2 can accept the Image from the stream where it wants Picture property not and Image property. Here is a snippet, I'm trying to avoid writing to disk.: Image i = Pic1.Image;
3
9239
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As Long) As Byte() 'find the encoder with the image/jpeg mime-type dim codecs as ImageCodecInfo = ImageCodecInfo.GetImageEncoders() Dim ici As ImageCodecInfo For Each codec As ImageCodecInfo In codecs If (codec.MimeType = "image/jpeg") Then
5
14625
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without saving to a file on HDD, then loading it as binary) Does anyone know how to convert an image into a string & have any pointers to information on how the image would look when in the string (Like bit patterns, etc)?
8
11662
by: piggy | last post by:
I am trying to convert an image to an byte array (tobytes() method) and from byte array back to an image (frombytes() method). The problem i have here is say the image size is 285 bytes but the total bytes is 635. I know it would include the header but the header should be the same size regardless of the image size. I tested the other image size of 407 bytes and the total bytes array is 727. I am not sure what is wrong? your help would...
5
9101
by: stef | last post by:
hello I can find all kind of procedures to convert an array to a bitmap (wxPython, PIL), but I can't find the reverse, either - convert a bitmap to an array or - read a bitmap file to an array
1
2889
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm using OpenGL in Visual Basic .net 2005 and i need to use the following function glBitmap(width as integer,height as integer, xorig as single, yorig as single, xmove as single, ymove as single, bitmap as System.InPtr) or glBitmap(width as integer,height as integer, xorig as single, yorig as single, xmove as single, ymove as single, bitmap() as byte)
2
4490
by: minouparhizkar | last post by:
hi could anyone helping me to finish this i have no idea how to implement the program in java im trying to grabbing the pixel from image and then convert it to the txt file .i did that but it didnt give me back any result could you tell me whats wrong with that. here is the pixel grabber file: package digitalpen; import java.awt.image.*;
3
11657
by: dpsairam | last post by:
Hi, How to convert a byte array to image....i mean i have to convert a Byte array into image format.....please hellp.........i need the java code... Thanking You.
0
10794
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9796
marktang
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...
0
9643
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,...
0
10786
Oralloy
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...
0
10214
tracyyun
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...
0
9326
agi2029
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...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.