ASP画像コントロール特定のフォルダに保存したいのですが、ASP画像コントロールをフォルダにエクスポート
Image1.ImageUrl = "~/fa/barcode.aspx?d=" + Label1.Text.ToUpper();
これはbarcode.aspxが何をするか、基本的である:
Bitmap oBitmap = new Bitmap(w, 100);
// then create a Graphic object for the bitmap we just created.
Graphics oGraphics = Graphics.FromImage(oBitmap);
oGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
oGraphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
// Let's create the Point and Brushes for the barcode
PointF oPoint = new PointF(2f, 2f);
SolidBrush oBrushWrite = new SolidBrush(Color.Black);
SolidBrush oBrush = new SolidBrush(Color.White);
// Now lets create the actual barcode image
// with a rectangle filled with white color
oGraphics.FillRectangle(oBrush, 0, 0, w, 100);
// We have to put prefix and sufix of an asterisk (*),
// in order to be a valid barcode
oGraphics.DrawString("*" + Code + "*", oFont, oBrushWrite, oPoint);
Response.ContentType = "image/jpeg";
oBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
を私はフォルダ(〜/ FA/barcodeimages/)に保存する方法は?
WebClient webClient = new WebClient();
string remote = "http://" + Request.Url.Authority.ToString() + "/fa/barcode.aspx?d=" + Label1.Text.ToUpper();
string local = Server.MapPath("barcodeimages/" + Label1.Text.ToUpper() + ".jpeg");
webClient.DownloadFile(remote, local);
しかし、それは動作しません、私は常に壊れた.JPEGファイルを取得:これまでのところ、ここで私が試したものです。そしてそれは非効率的だと思われる。
あなたは 'oBitmap'がどこから来たのか、あるいはイメージコントロールを"保存 "することが本当に何を意味するのか説明していません。画像データ自体はどこにありますか、正確に何を保存しようとしていますか? –
@JonSkeet実際にはバーコード画像です。私はコードを編集するために投稿を編集しました。私がしたかったのは、自分のウェブサイトのフォルダにその画像をコピー/エクスポートすることでした。その結果、Webフォルダにファイル(〜/ fa/barcodeimages/barcode1.jpeg)があります。 –
@PodMays:ブラウザにURLを入力すると、jpegが正しくレンダリングされますか?もしそうでなければ、ビットマップの構築方法に問題があります。 – shahkalpesh