如何在asp.net中使用二进制图像实现图库 [英] how to implement image gallery using binary image in asp.net

查看:79
本文介绍了如何在asp.net中使用二进制图像实现图库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,



i希望开发一个已完成50%的画廊页面,但我有二进制格式的图像,我显示了所有图像,但我想要当我点击图像按钮时,它将显示全长...所以我怎么能写出一个代码,请告诉我.....已经使用了一些jquery但是它显示了二进制数...就是这样......所以请帮帮我

 <   asp:DataList     ID   =  dl_testimonials   高度  =  550px    CellSpacing   =  2    CellPadding   =  1          宽度  =  100%    RepeatLayout   =     RepeatDirection   = 水平    RepeatColumns   =  4        runat   =  server >  
< ItemTemplate >
< div id = dl_galitmback >
< asp:ImageButton ID = img_testiuser CssClass = img_gallery ImageUrl =' < ;% getgalleryimg.aspx?id = + Eval( gid)%>' rel = prettyPhoto [pp_gal] runat = server / >

<% - < a href ='<%#getgalleryimg.aspx?id =+ Eval(gid )%>' rel =prettyPhoto [pp_gal]title ='<%#Eval(caption)%>>
< img src ='<%#getgalleryimg.aspx?id =+ Eval(gid)%>' width =60height =60alt ='<%#Eval(displayname)%>' />
< / a>
- %>

< / div >
< / ItemTemplate >
< / asp:DataList >

解决方案





每个文件都是二进制内容@ Dave-Kreskowiak说,现在您需要按照应用程序类型指定您的Web浏览器,浏览器将呈现它。



所以如果您已经拥有该图像的二进制文件,那么请编写一个Web方法将该二进制数据作为图像返回,该函数将获取id并返回图像,现在您将该数据设置为该特定图像Tab,例如:< img src =data:image / bmp; base64,xxxxxxxxxxxxx ...>



如何编写网络方法?

示例: http://stackoverflow.com/questions/10127937/calling-a-pages- webmethod-from-javascript-on-a-different-page [ ^ ]



如何使用Web方法返回图像?



 [WebMethod] 
[ return :XmlElement( imageData,DataType = base64Binary)]
public byte [] CreateImage()
{
使用(位图图片= new 位图( 100 100 ))
使用(Graphics imageGraphics = Graphics.FromImage(image))
{
imageGraphics.FillRectangle(Brushes.Red, 0 0 ,image.Width,image.Height);
imageGraphics.DrawRectangle(Pens.Blue, 0 0 ,image.Width,image。高度);

使用(MemoryStream stream = new MemoryStream())
{
image.Save(stream,ImageFormat.Png);

stream.Flush();

return stream.ToArray();
}
}
}





另一篇文章可以帮到你:将图像提交给Web服务并让他们回来 [ ^


friends,

i would like to develop a gallery page that already 50 % completed but i have images in binary format , i displayed all the images , but i want when i click on image button it will shows the full length ...so how can i write a code for that please tel me..... already using some jquery but it's shows binary number..leave it that...so please help me

<asp:DataList ID="dl_testimonials" Height="550px" CellSpacing="2" CellPadding="1"    Width="100%" RepeatLayout="Table" RepeatDirection="Horizontal" RepeatColumns="4"   runat="server">
   <ItemTemplate  >
       <div id="dl_galitmback">
        <asp:ImageButton ID="img_testiuser" CssClass="img_gallery" ImageUrl='<%# "getgalleryimg.aspx?id="  + Eval("gid") %>' rel="prettyPhoto[pp_gal]"   runat="server" />

<%--<a href='<%# "getgalleryimg.aspx?id="  + Eval("gid") %>'  rel="prettyPhoto[pp_gal]" title="'<%#Eval("caption") %>">
       <img src='<%# "getgalleryimg.aspx?id="  + Eval("gid") %>' width="60" height="60" alt='<%# Eval("displayname") %>' />
</a>--%>

       </div>
   </ItemTemplate>
</asp:DataList>

解决方案

Hi,

Every file is binary content as @Dave-Kreskowiak said, Now you need to specify your web browser by their application type and browser will render it.

So If you already have binary of that image then write a web Method which will return that binary data as an image, that function will take a id and return the image, now you will set that data to that particular image Tab e.g : <img src="data:image/bmp;base64,xxxxxxxxxxxxx...">

How to write an web method?
Example : http://stackoverflow.com/questions/10127937/calling-a-pages-webmethod-from-javascript-on-a-different-page[^]

How to return image using web Method?

[WebMethod]
[return:XmlElement("imageData", DataType="base64Binary")]
public byte[] CreateImage()
{
using(Bitmap image = new Bitmap(100, 100))
using(Graphics imageGraphics = Graphics.FromImage(image))
{
imageGraphics.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height);
imageGraphics.DrawRectangle(Pens.Blue, 0, 0, image.Width, image.Height);

using(MemoryStream stream = new MemoryStream())
{
image.Save(stream, ImageFormat.Png);

stream.Flush();

return stream.ToArray();
}
}
}



Another Article which will help you : Submit Images to Web Service and Get Them Back[^]


这篇关于如何在asp.net中使用二进制图像实现图库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆