0

.aspxコントロール付きのページがありますFileUpload。ウェブサイトへの画像のアップロードを実現したい。ただし、その前に、次の条件で画像の高さと幅を確認する必要があります。

  • 画像の高さが768を超えるか、幅が1024を超える場合は、続行するためのポップアップメッセージを表示します...(はい/いいえ)

  • 画像の高さが768未満または幅が1024未満の場合は、続行するためのポップアップメッセージを表示します...(はい/いいえ)

    これまで、画像のアップロードコードを実行しましたが、これを実現するにはどうすればよいですか?どんな種類の助け/提案もありがたいです。

           <asp:RegularExpressionValidator ID="revUploaderMainPopup" runat="server" ControlToValidate="UploaderMainPopup"
                            ErrorMessage="*" ValidationGroup="MainPopUploadvlg" ToolTip="Only .jpg, .bmp, .png are valid."
                            ForeColor="Red" Display="Dynamic"  ValidationExpression="(.*\.([Jj][Pp][Gg])|.*\.([Bb][Mm][Pp])|.*\.([pP][nN][gG])$)">
           </asp:RegularExpressionValidator> 
    
4

3 に答える 3

0

カスタムバリデーターを使用せずにこれを行うことはできません。そして、それは間違いなくサーバー側でなければなりません。クライアント側のコードでは、「はいまたはいいえ」ダイアログボックスを表示するためにJavascriptが必要になります(これはjavascript: confirm('yes?');ダイアログボックスで実行できます。

また、アップロードが行われなかったようにUIを維持し、クライアント側で完全に検証している場合(部分的なポストバックのため)、いくつかのajaxが必要になります。

そのajaxリクエストを数ミリ秒短縮できるように、ファイル全体を読み取らずに、画像のサイズを取得するようにしてください。

幸運を!

于 2013-01-23T11:46:30.173 に答える
0

フォローしてみてください

        using (System.Drawing.Image image = System.Drawing.Bitmap.FromStream(fs))
        {
            int iWidth = (int)Math.Round((decimal)image.Width);
            int iHeight = (int)Math.Round((decimal)image.Height);
           if(iWidth > 1024 || iHeight > 768)
           {
                // here you can throw your message
           }
        }

よろしく、

于 2013-01-23T11:54:40.293 に答える
0

私は次の方法でそれを行いました:私は2つの変数(画像と文字列)をポップアップ付きのdivに取り、牽引ボタンを持っています。画像を検証した後display:block、サーバーからdivに設定しています。
あなたがたボタンをクリックするだけで私はそれを保存しています。

 <div id="dvPopup" class="popup" runat="server" style="display: none">
    <asp:Panel ID="pnlpopup" runat="server" Style="display: block; position: absolute; width:400px;
        margin: auto" CssClass="modalConfirmation">
        <div style="width: 400px; height: 30px;" class="MessageHeaderError">
            <div class="modalHeader">
                Confirmation
            </div>
        </div>
        <br />
        <div style="color: Black">
            <span runat="server" id="spnMessge" style="font-weight:bold">Picture is smaller than 1024 x 768 and will be stretched.</span>
        </div>
        <div class="small">
        </div>
        <div>
            <div style="display: table-cell; height: 40px; padding-left: 80px; vertical-align: middle;
                width: 80px;">
                <asp:ImageButton ID="btnYes" ImageUrl="~/images/correct.png" runat="server" AlternateText="YES"
                    ToolTip="Yes" OnClick="btnYes_Click" />
            </div>
            <div style="display: table-cell; height: 40px; vertical-align: middle;">
                <asp:ImageButton ID="btnNo" ImageUrl="~/images/delete.png" runat="server" AlternateText="NO"
                    ToolTip="No" Style="margin-left: 100px;" OnClick="btnNo_Click" />
            </div>

.csFIE で:

 private bool ValidateImageSize(System.Drawing.Image imgPopup, string strSource)
    {
        //Messure height & width and show popup;
        if ((strSource == "MainPopup") && (imgPopup.Height > 768 || imgPopup.Width > 1024))
        {
            return true;
        }
        else if (strSource == "SmallPopup" && imgPopup.Height > 300 || imgPopup.Width > 400)
        {
            return true;
        }
        return false;
    }
于 2013-01-31T05:45:43.467 に答える