-
-
Save mayuki/696fe81268b2daa7f9e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
namespace WebApplication3 | |
{ | |
public partial class Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Canvas canvas = new Canvas | |
{ | |
Width = 200, | |
Height = 200, | |
Background = Brushes.LightGray | |
}; | |
canvas.Children.Add(new Label { Content = "初春かわいい" }); | |
canvas.Arrange(new Rect(0, 0, canvas.Width, canvas.Height)); | |
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((Int32)canvas.Width, (Int32)canvas.Height, 96, 96, PixelFormats.Default); | |
renderTargetBitmap.Render(canvas); | |
MemoryStream memoryStream = new MemoryStream(); | |
BitmapEncoder encoder = new PngBitmapEncoder(); | |
encoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); | |
encoder.Save(memoryStream); | |
Response.ContentType = "image/png"; | |
Response.ClearContent(); | |
Response.BinaryWrite(memoryStream.ToArray()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment