如何将JavaScript Image变量内容访问到C#Image [英] How to Access the JavaScript Image variable content to C# Image

查看:55
本文介绍了如何将JavaScript Image变量内容访问到C#Image的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们,





Hi folks,


<script type="text/javascript">
            function printIt() {
                var win = window.open('', 'popup', 'location=1,status=1,scrollbars=1,width=800,height=600');
                if (win) {
                    var imageControl = document.getElementById('<%=chkImage2.ClientID%>').src;
                    win.document.write('<img src="' + imageControl + '">');
                    win.document.close();
                    win.focus();
                    win.print();
                }
                return false;
            }
        </script>



 <telerik:RadWindow ID="rdwndwPreviewCheck" VisibleOnPageLoad="false" Title="Check Preview"
        Height="630" Width="790"  runat="server" Behaviors="Close" AutoSize="false" Skin="Office2010Blue"
        OpenerElementID="cmdGraficoIstogramma" Modal="true" Overlay="false" Style="width: 790px;
        height: 630px; visibility: visible; left: 236px; top: 361px; z-index: 3001; position: absolute;">
        <Shortcuts>
            <telerik:WindowShortcut CommandName="CloseAll" Shortcut="Esc" />
        </Shortcuts>
        <ContentTemplate>
            <table>
            </table>
            <asp:Image ID="chkImage2" runat="server" ImageUrl="~/CheckPreview.aspx" />
            <br />
            <br />
            <table style="width: 100%;">
                <tr align="center">
                    <td style="width: 580px;">
                        <telerik:RadButton ID="rdPrint"  runat="server" Text="  Print"   Style="position: relative;
                            left: 90px;"   önClick="print"    >
                            <Icon SecondaryIconCssClass="rbPrint" SecondaryIconRight="4" SecondaryIconTop="4" />
                        </telerik:RadButton>
                    </td>
                    <td>
                        <telerik:RadButton ID="CloseRadPrintWindow"  runat="server" Text="Close"  önClientClicked="closeMyRadWindow"
                            Style="position: relative; left: -185px;">
                        </telerik:RadButton>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </telerik:RadWindow>









如何访问上面的imageControl到..C#代码背后的技术..任何人都可以重播我如何访问图像并将该图像转换为Byte []格式..





How to access the above "imageControl" to ..C# code behind technique ..Any one can replay me how to access image and convert that image into Byte[] format ..

推荐答案

由于您已经可以访问服务器端的位图文件,因此可以使用以下代码将位图文件转换为字节数组。希望这个帮助



As you already have access to bitmap file in server side you can use following code to convert bitmap file to byte array. Hope this help

 MemoryStream ms = new MemoryStream();
 b.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] bytes =  ms.ToArray();


在上面类型的问题中,如从其他页面响应获取图像,在那种情况下,我们将图像分配给某个会话变量然后将图像数据访问到我们的页面,请参阅下面的代码。

In the above type of Question like image getting from the Other Page Response,In that of situation , We assign image to some session variable then access that image data into Our Page ,See the Below code.
/*checkperview.aspx" not current page  */
  b.Save(p.Response.OutputStream, ImageFormat.Jpeg);
  Image Img = b;
  MemoryStream ms = new MemoryStream(imageToByteArray(Img));
  byte[] bytes = ms.ToArray();
  Image previewImage = byteArrayToImage(bytes);
  Session["previewImage"] = previewImage;


/* Here "b" is bitmap image */
/* P is Page */
/*Image is System.Drawing.Image */





这里我将Bitmap Image转换为Jpeg格式图像,但我可能不需要转换,我需要为什么我要完成对话。





Here I am converting Bitmap Image to Jpeg format image ,But I your may not need That conversion ,I need that Why I am Done conversation.

/*Manualcheck.aspx Current Page   */

  Image Img = (Image)Session["previewImage"];

/*Here I am got Image of Other Page,Now I can Do what ever Operation I need it. */





在上面的问题中,我使用了调用不同页面的预览按钮。



In the Above Question ,I used preview button in that calling the different page .


这篇关于如何将JavaScript Image变量内容访问到C#Image的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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