 |
|
 |
It's a good start to convert, but you should always dispose your stream. Why always use Gif instead of native format?
|
|
|
|
 |
|
 |
i have andorid client which uploads image to server via WCF. as this client call my method having signature
public string InsertImage(string byteStream). now i am converting this string in array of byte and using yr imageconvertor class to render image by following code
public System.Drawing.Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms.ToArray());
Response.Write(returnImage);
return returnImage;
}
but m getting exception. can you solve this issue or help me out right approach .
|
|
|
|
 |
|
 |
awsome.
|
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
The Save() Method will make the quality lower or not?
Should I set the "EncoderParameter" to keep the quality?
y or n?
|
|
|
|
 |
|
 |
Hi, first of all, I want to say thank you for share this code.
It is really help me in my final project.
But, I want to know about the byte that are produced by this code are represent the RGB or YUV or any other else?
thanks
|
|
|
|
 |
|
 |
Hi Guys,
I've been working on this for about a week and this seems to be not working please can you assist.
Please can you view the code below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script src="https://pcmchatproxy3.valueactive.eu/js/MgsLiveChatControl.js" type ="text/javascript"></script>
<script type ="text/javascript">
function nav()
{
var w = document.jump.menu.selectedIndex;
var url_add = document.jump.menu.options[w].value;
// nav1(url_add);
//
// }
//
// function nav1(url_add)
// {
if (url_add == 0)
{
LoadPromotions();
}
else if (url_add == 1)
{
LoadBanking();
}
else if (url_add == 2)
{
LoadFAQS();
}
else if (url_add == 3)
{
LoadSupport();
}
}
function LoadSupport()
{
try
{
var CasinoId = "322";
var BrowserLanguage = "En";
var SessionLanguage = "En";
var TopPosition = "350";
var LeftPosition = "300";
var Resource = "Website: Contact US";
var AutoLogin = true;
var DisableProxyPopUp = false;
var ProxyPageURL = " ";
var TrackingGuid = "";
var PlayerLoginName = "";
var SystemType = "2";
var SessionId = "";
var SessionType = "";
var NotificationURL = ""
var PSLLoginName = "";
var stepId = "1420";
MgsLiveChatControl.InitializeMgsLiveChatControl(CasinoId, BrowserLanguage, SessionLanguage, TrackingGuid, PlayerLoginName, SystemType, SessionId, SessionType, AutoLogin, TopPosition, LeftPosition, Resource, DisableProxyPopUp, ProxyPageURL, PSLLoginName,NotificationURL,CasinoId, stepId);
}
catch(Error)
{
}
}
function LoadPromotions()
{
try
{
var CasinoId = "322";
var BrowserLanguage = "En";
var SessionLanguage = "En";
var TopPosition = "350";
var LeftPosition = "300";
var Resource = "Website:Promotions";
var AutoLogin = true;
var DisableProxyPopUp = false;
var ProxyPageURL = " ";
var TrackingGuid = "";
var PlayerLoginName = "";
var SystemType = "2";
var SessionId = "";
var SessionType = "";
var NotificationURL = ""
var PSLLoginName = "";
var stepId = "1438";
MgsLiveChatControl.InitializeMgsLiveChatControl(CasinoId, BrowserLanguage, SessionLanguage, TrackingGuid, PlayerLoginName, SystemType, SessionId, SessionType, AutoLogin, TopPosition, LeftPosition, Resource, DisableProxyPopUp, ProxyPageURL, PSLLoginName,NotificationURL,CasinoId, stepId);
}
catch(Error)
{
}
}
</script>
</head>
<body>
<form name="jump">
<select name="menu" onchange = "javascript:nav()">
<OPTION VALUE="javascript:LoadPromotions()">Promotions</OPTION>
<OPTION VALUE="javascript:LoadBanking()">Banking</OPTION>
Please can you assist?
Thanks,
Monde
|
|
|
|
 |
|
 |
Hello, i am looking for one function. which extend the function FromStream(), so i can create one image from 32 bpp image stream. Do you have any idear?
|
|
|
|
 |
|
 |
its simple and its useful .
|
|
|
|
 |
|
|
 |
|
 |
Thanks a lot! So obvious, but still couldn't get the idea
|
|
|
|
 |
|
 |
Even if you call all your friends to vote for you 5 points, the code quality remains 0 (zero).
The function how it should've look:
public byte[] ImageToByteArray( System.Drawing.Image p_ImageIn )
{
byte[] aRet = null;
using ( System.IO.MemoryStream oMS = new System.IO.MemoryStream() )
{
p_ImageIn.Save( oMS, System.Drawing.Imaging.ImageFormat.Gif );
aRet = oMS.ToArray();
}
return aRet;
}
|
|
|
|
 |
|
 |
This worked great bro ...
Add the below lines also to get image from a server folder...
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/Images/no_image_icon2_100.gif"));
byte[] b = ImageToByteArray(image);
love to be a jerk....COMPUTER JERK ....
|
|
|
|
 |
|
|
 |
|
 |
streams are left open, plus the imageIn and byteArray in will be totally useless after these operations. the code above will lead to very misleading GDI errors. author should clone / copy the imageIn and clone / copy the arrayIn to make sure that the inputs are not corrupted. i just spent the last 3 weeks dealing with uploading images from the web, resampling into various other size image formats, saving to disk, and into the SQL DB. the code above will get you into hot water quick.
|
|
|
|
 |
|
 |
Good observation.
The more anger towards the past you carry in your heart, the less capable you are of loving in the present.
My Blog![ ^]
|
|
|
|
 |
|
 |
i am using vs2005 web application.
one image information in hex format is like as follows.
000125262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A73740D0A
my requirement is this hex data need to store in sql db and need to display in a website.
can anybdy help me to solve my problem??
In sql i inserted this data in an image coloumn like as follows(added ox).
INSERT INTO [Test_mm].[dbo].[PictureTable]
([Title]
,[DateAdded]
,[MIMEType]
,[Image])
VALUES
('jjj'
,'6/22/2010 3:12:04 PM'
,'hjhg'
,0x000125262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A73740D0A)
after inserting the data i tried to display this using the code below.But the picture box is coming with a red colour cross button?
Dim ImageID As Integer = Convert.ToInt32(Request.QueryString("ImageID"))
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnection").ConnectionString)
Const SQL As String = "SELECT [MIMEType], [Image] FROM [PictureTable] WHERE [ImageID] = @ImageID"
Dim myCommand As New SqlCommand(SQL, myConnection)
myCommand.Parameters.AddWithValue("@ImageID", ImageID)
myConnection.Open()
Dim myReader As SqlDataReader = myCommand.ExecuteReader
If myReader.Read Then
Response.ContentType = myReader("MIMEType").ToString()
Response.BinaryWrite(myReader("Image"))
End If
myReader.Close()
myConnection.Close()
End Using
can anybdy help me to solve this ?i am troubling lot..pls pls help me
MEENU
|
|
|
|
 |
|
 |
hi meenu,
follow this route:
part 1: sending image to databse:
convert image to byte array
convert byte array to base64 string
save base64 string to database
part 2: displaying the image
in your web app ( asp page) get the base64 string from the table
output the base64 string to your outputstream
|
|
|
|
 |
|
 |
Dear friend thank u very much for ur response.
i am troubling with my problem from the last few weeks.Pls check the step what i did.
STEP1
--------
actualy image data is sending by a vehicle tracking unit.using a socket application i am tracing that data.the data from the vehicle tracking unit is not in a decimal format.image data coming from socket containing lot of special type of characters. so i am converting this image information to hex format using the code below.
Private Function Data_Asc_Hex(ByRef Data As String) As String
On Error Resume Next
'first take each charcter using substring.
'then convert character into ascii.
'then convert ascii value into Hex Format
Dim sValue As String
Dim sHex As String = ""
While (Data.Length > 0)
sValue = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString))
Data = Data.Substring(1, (Data.Length - 1))
sHex = (sHex + sValue)
End While
Return sHex
End Function
i am calling the function like as follows
Dim Image As String = ""
''convert image details to hex
If TestArray(3) <> "" Then 'convert to hex
Image = Data_Asc_Hex(TestArray(3))
End If
STEP2
-----------------------------------
after converting image data to hex format,i did the steps what u specified.
for eg:after step 1 i got image data in socket application in hex format like as follows
D0043D23FA4682EFAB507FFD6E74BD34BD234185EA367A03FFFD7E33F3FF125223F1253BCCA67FFFD0E53CCA3CCA453F3F473F401FFFD1E57CCA43F3F1DE65064A0FFFD2E4CCBEF4D32D22C619698D28A047FFD3E03FC4533FF43F385C52FDA05033FFD4E23CFA3ED029141F68A3ED23F3FFFD5E23ED028FB40A450A2E47AD0D7231D683FFD6E03FE73F69B9343F30DC1A693FD33FFD7F38F30D2F93F3FDE63F71A067FFD0F3BF30D1BDA8183F8FAD193EB41FFD1F3AC3F32681864D13F401FFFD2F33F314093F4C507FFD9D
STEP3
-------------------------------------------
'--hex to byte
Dim hex As String = "D0043D23FA4682EFAB507FFD6E74BD34BD234185EA367A03FFFD7E33F3FF125223F1253BCCA67FFFD0E53CCA3CCA453F3F473F401FFFD1E57CCA43F3F1DE65064A0FFFD2E4CCBEF4D32D22C619698D28A047FFD3E03FC4533FF43F385C52FDA05033FFD4E23CFA3ED029141F68A3ED23F3FFFD5E23ED028FB40A450A2E47AD0D7231D683FFD6E03FE73F69B9343F30DC1A693FD33FFD7F38F30D2F93F3FDE63F71A067FFD0F3BF30D1BDA8183F8FAD193EB41FFD1F3AC3F32681864D13F401FFFD2F33F314093F4C507FFD9D"
Dim NumberChars As Integer = Hex.Length
Dim bytes As Byte() = New Byte(NumberChars / 2 - 1) {}
For i As Integer = 0 To NumberChars - 1 Step 2
bytes(i / 2) = Convert.ToByte(Hex.Substring(i, 2), 16)
Next
'*****************
STEP4
-------------------------------------------
'bytearray to base 64
If bytes Is Nothing Then Throw New ArgumentNullException("bytes")
Dim str64 As String = Convert.ToBase64String(bytes)
''''
STEP 5
------------------------------------------------
Dim img As System.Drawing.Image
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream
Dim b64 As String = str64
Dim b() As Byte
'Converts the base64 encoded msg to image data
b = Convert.FromBase64String(b64)
MS = New System.IO.MemoryStream(b)
'creates image
img = System.Drawing.Image.FromStream(MS)
'writes image for displaying
img.Save("c:\pict1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
'cleaning up house
img.Dispose()
MS.Close()
STEP 6
-----------------------------------------------
getting an error
"Parameter is not valid." in the line
img = System.Drawing.Image.FromStream(MS)
can u help me to findout where the problem is?
thanks
MEENU
|
|
|
|
 |
|
 |
br.Close();
fs.Close();
Important!
|
|
|
|
 |
|
 |
what if i dont know the type of the image
|
|
|
|
 |
|
 |
this can be used to convert the image in same format.
using (MemoryStream ms = new MemoryStream())
{
imageIn.Save(ms, imageIn.RawFormat);
return ms.ToArray();
}
|
|
|
|
 |
|
 |
I am having trouble in using this library RTP.NET. i cannot find any helpful samples on how to send and receive RTPPackets. Can anybody give me any link related to it please?
|
|
|
|
 |