Well……It would be better if you can paste your solution in the form of zip,for Microsoft support at present only use zip files……
I think that in fact you can do a class to serialize it in the form of xml,and then read the whole xml contents in and then read out the image bytes and use HttpHandler to deal with the image problem……
Well……You should create an entity model class and the serialize or deserialize it step by step, and then with the help of httphandler, you can fetch the bytes of image out。
Please follow the example——If you need the sample,please leave your email here……
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CSharp
{
/// <summary>
/// Summary description for Imagehandler
/// </summary>
public class Imagehandler : IHttpHandler
{
private static List<EntityModel> models = null;
static Imagehandler()
{
models = Dbgenerator.ReadFromXml();
}
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ContentType = "image/jpeg";
int id = Convert.ToInt32(context.Request.QueryString["Id"]);
id--;
context.Response.BinaryWrite(models[id].Image);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
[EntityModel]
namespace CSharp
{
/// <summary>
/// A model entity that used to hold data contents
/// </summary>
[Serializable]
public class EntityModel
{
public int Id { get; set; }
public string Name { get; set; }
public byte[] Image { get; set; }
}
/// <summary>
///A class that is used to create random records to be like fetching contents from a db
/// </summary>
public static class Dbgenerator
{
private static List<EntityModel> entities = new List<EntityModel>();
static Dbgenerator()
{
entities.Add(new EntityModel { Id = 1, Name = "member1", Image = System.IO.File.ReadAllBytes("c:\\Koala.jpg") });
entities.Add(new EntityModel { Id = 2, Name = "member2", Image = System.IO.File.ReadAllBytes("c:\\Chrysanthemum.jpg") });
}
/// <summary>
/// Write xml into hard disc C
/// </summary>
public static void WriteGenerateInXml()
{
XmlSerializer xs = new XmlSerializer(typeof(List<EntityModel>));
FileStream fs = new FileStream("c:\\dataxml.xml", FileMode.OpenOrCreate);
xs.Serialize(fs, entities);
fs.Close();
}
/// <summary>
/// Read out from xml file
/// </summary>
public static List<EntityModel> ReadFromXml()
{
XmlSerializer xs = new XmlSerializer(typeof(List<EntityModel>));
FileStream fs = new FileStream("c:\\dataxml.xml", FileMode.OpenOrCreate);
List<EntityModel> models = xs.Deserialize(fs) as List<EntityModel>;
fs.Close();
return models;
}
}
}
eladc
Member
32 Points
89 Posts
Reading binary in to a image
Jun 30, 2012 05:28 PM|LINK
Hey, in my xml file there is a binary data,
i want to turn that data to an image using a generic handler.
nothing i do works so i have uploaded the entire project, maybe you guys can
see if you can come up with some solutions ;)
http://www.tinyuploads.com/download/file/dXNBz0 (check out line 34 in Default.aspx.cs file)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading binary in to a image
Jul 02, 2012 02:00 AM|LINK
Well……It would be better if you can paste your solution in the form of zip,for Microsoft support at present only use zip files……
I think that in fact you can do a class to serialize it in the form of xml,and then read the whole xml contents in and then read out the image bytes and use HttpHandler to deal with the image problem……
For more you can see this:
http://forums.asp.net/t/1733946.aspx/1
eladc
Member
32 Points
89 Posts
Re: Reading binary in to a image
Jul 02, 2012 11:27 AM|LINK
zip: http://www.tinyuploads.com/download/file/rmn6vQ
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading binary in to a image
Jul 03, 2012 01:50 AM|LINK
Well……You should create an entity model class and the serialize or deserialize it step by step, and then with the help of httphandler, you can fetch the bytes of image out。
Please follow the example——If you need the sample,please leave your email here……
[aspx]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CSharp.WebForm1" %> <!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 runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table> <tr> <th>Id</th> <th>Name</th> <th>Image</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%#Eval("Id") %></td> <td><%#Eval("Name") %></td> <td> <img src='Imagehandler.ashx?Id=<%#Eval("Id") %>' width="120" height="120" /> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </div> </form> </body> </html>[Httphandler]
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CSharp { /// <summary> /// Summary description for Imagehandler /// </summary> public class Imagehandler : IHttpHandler { private static List<EntityModel> models = null; static Imagehandler() { models = Dbgenerator.ReadFromXml(); } public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.ContentType = "image/jpeg"; int id = Convert.ToInt32(context.Request.QueryString["Id"]); id--; context.Response.BinaryWrite(models[id].Image); context.Response.End(); } public bool IsReusable { get { return false; } } } }[EntityModel]
namespace CSharp { /// <summary> /// A model entity that used to hold data contents /// </summary> [Serializable] public class EntityModel { public int Id { get; set; } public string Name { get; set; } public byte[] Image { get; set; } } /// <summary> ///A class that is used to create random records to be like fetching contents from a db /// </summary> public static class Dbgenerator { private static List<EntityModel> entities = new List<EntityModel>(); static Dbgenerator() { entities.Add(new EntityModel { Id = 1, Name = "member1", Image = System.IO.File.ReadAllBytes("c:\\Koala.jpg") }); entities.Add(new EntityModel { Id = 2, Name = "member2", Image = System.IO.File.ReadAllBytes("c:\\Chrysanthemum.jpg") }); } /// <summary> /// Write xml into hard disc C /// </summary> public static void WriteGenerateInXml() { XmlSerializer xs = new XmlSerializer(typeof(List<EntityModel>)); FileStream fs = new FileStream("c:\\dataxml.xml", FileMode.OpenOrCreate); xs.Serialize(fs, entities); fs.Close(); } /// <summary> /// Read out from xml file /// </summary> public static List<EntityModel> ReadFromXml() { XmlSerializer xs = new XmlSerializer(typeof(List<EntityModel>)); FileStream fs = new FileStream("c:\\dataxml.xml", FileMode.OpenOrCreate); List<EntityModel> models = xs.Deserialize(fs) as List<EntityModel>; fs.Close(); return models; } } }eladc
Member
32 Points
89 Posts
Re: Reading binary in to a image
Jul 03, 2012 05:24 AM|LINK
did u see my zip file?
it seems like a very long way to simply read the binary string (from the report.xml file i uploaded)
and display it using a web handler
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading binary in to a image
Jul 03, 2012 05:28 AM|LINK
Yes,of course;the bigger the image is,the longer time it wil take……
If you need a full sample,plz leave your email……
eladc
Member
32 Points
89 Posts
Re: Reading binary in to a image
Jul 04, 2012 04:10 AM|LINK
eladchen@gmail.com
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading binary in to a image
Jul 04, 2012 04:30 AM|LINK
sorry please use Hotmail instead,for I cannot send you and your Google mail has reguarded mine as a junk one……:(
eladc
Member
32 Points
89 Posts
Re: Reading binary in to a image
Jul 04, 2012 02:52 PM|LINK
faken_en@hotmail.com
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Reading binary in to a image
Jul 05, 2012 01:25 AM|LINK
Hi,
I've sent that to you, plz see it……