2016-10-14 7 views
1

C#のバナー画像にテキストを適用したいと考えています。これまでは、タイトル、href、イメージsrcを引き出すクラスコントロールがありましたが、保存せずにテキストを追加したいのです。保存せずに画像にテキストを追加する

だから私は引っ張って、それをontopに当てはめるというタイトルを使いたい。

以下は私がそれに適用しようとしているグラフィックスです。私はちょうどそれにテキストをオーバーレイし、新しいイメージを作成しないようにしたい。

private void GenerateBannerTitle() 
{ 
    Bitmap bannerSource = new Bitmap(PhysicalBannerPath); 
    //bannerSource.Save(PhysicalBannerPath); 
    RectangleF rectf = new RectangleF(430, 50, 650, 50); 

    using (Graphics g = Graphics.FromImage(bannerSource)) 
    { 
     g.SmoothingMode = SmoothingMode.AntiAlias; 
     g.InterpolationMode = InterpolationMode.HighQualityBicubic; 
     g.PixelOffsetMode = PixelOffsetMode.HighQuality; 
     g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; 
     g.DrawString("hfsdfdsfds", new Font("courier sans", 100, FontStyle.Bold), Brushes.White, rectf); 
    } 
} 

任意のヘルプやアイデア。 C#でインラインCSSを使ってこれを行うことはできますか?それとも、今のところontopを適用する方法を変更する方法がありますか?

私はちょうどイメージを引っ張っています。それは私が理解し、働くことが必要なテキストを適用するだけです。

+2

画像用および戻り値の型のためのMemoryStreamを見てみましょうファイルストリームの内容を見てください –

+0

なぜ単にラベルを適用しないのですか? –

+0

@CiroCorvinoどうすればいいですか?あなたは助けてください –

答えて

1

それはのようなHTMLで

private string GenerateBannerTitle() 
    { 
     var bitmap = new Bitmap(PhysicalBannerPath); 
     RectangleF rectf = new RectangleF(430, 50, 650, 50); 

     using (var g = Graphics.FromImage(bitmap)) 
     { 
      using (var arialFont = new Font("Arial", 10)) 
      { 
       g.SmoothingMode = SmoothingMode.AntiAlias; 
       g.InterpolationMode = InterpolationMode.HighQualityBicubic; 
       g.PixelOffsetMode = PixelOffsetMode.HighQuality; 
       g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; 
       g.DrawString("hfsdfdsfds", new Font("courier sans", 100, FontStyle.Bold), Brushes.White, rectf); 
      } 
     } 


     var ms = new MemoryStream(); 

     bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 

     var arr = new byte[ms.Length]; 

     ms.Position = 0; 
     ms.Read(arr, 0, (int)ms.Length); 
     ms.Close(); 

     var strBase64 = Convert.ToBase64String(arr); 

     return strBase64; 

    } 

およびshow base64文字列として画像を返すために、メモリストリームを使用します。

<img src="data:image/jpg;base64,the returned data"/> 
関連する問題