2011-07-27 3 views
1

aspx 페이지에서 displayImage.aspx라는 이름의 태그를 사용하고 다른 src 속성 값을 할당하고 있습니다. ** SRC = "getImageFromText.aspx" 투명 비트 맵 이미지 생성 방법 Graphics.clear (color.Transparent) 속성을 설정할 때 검은 색 배경이 나타납니다.

getImageFromText.aspx

라는 이름의 하나의 aspx 페이지. **

내가 getImageFromText.aspx.cs에서 비트 맵을 생성하고 메모리 증기를 저장하는 코드를 작성하지만 난 수 없습니다입니다 그 이미지를 투명하게합니다.. Graphics.clear (color.Transparent)를 설정하면 검정색 배경으로 표시됩니다. yi는 Graphics.clear (color.ANYCOLO R)를 눌러 검정색 배경을 제거합니다. 비트 맵 이미지를 투명하게 배경으로 만들 수 있다는 조언이나 코드를 알려주십시오. 매개 변수처럼 투명하게하고자하는 색상을 사용하여,

Bitmap.MakeTransparent :
코드는

보호 무효를 Page_Load (개체를 보낸 사람, EventArgs입니다 전자) {

if (Request.QueryString["phone"] != null) 
    { 
     CreateBitmapImage(Request.QueryString["phone"]); 
    } 

    // CreateBitmapImage("Call Now 123-457-1222"); 

} 
private void CreateBitmapImage(string phonenumber) 
{ 

    string message = "Call Now " + phonenumber.ToString(); 
    Bitmap objBmpImage = new Bitmap(1, 1); 



    int intWidth = 0; 

    int intHeight = 0; 


    // Create the Font object for the image text drawing. 
    FontFamily[] fontFamilies; 
    PrivateFontCollection fontCollection = new PrivateFontCollection(); 
    fontCollection.AddFontFile(Server.MapPath("Futura-Condensed-Bold.ttf")); 
    fontFamilies = fontCollection.Families; 
    string familyName = ""; 
    familyName = fontFamilies[0].Name; 
    Font objFont = new Font(familyName, 19, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel); 




    // Create a graphics object to measure the text's width and height. 

    Graphics objGraphics = Graphics.FromImage(objBmpImage); 



    // This is where the bitmap size is determined. 

    intWidth = (int)objGraphics.MeasureString(message, objFont).Width; 

    intHeight = (int)objGraphics.MeasureString(message, objFont).Height; 



    // Create the bmpImage again with the correct size for the text and font. 

    objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight)); 



    // Add the colors to the new bitmap. 

    objGraphics = Graphics.FromImage(objBmpImage); 



    // Set Background color "#5496CA" 
    string xCol = "#5496CA"; 
    Color clearClr = System.Drawing.ColorTranslator.FromHtml(xCol); 
    objGraphics.Clear(clearClr); 

    objGraphics.SmoothingMode = SmoothingMode.AntiAlias; 
    objGraphics.PixelOffsetMode = PixelOffsetMode.HighQuality; 
    objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; 

    objGraphics.DrawString(message, objFont, new SolidBrush(Color.White), 0, 0); 



    MemoryStream memoryStream = new MemoryStream(); 
    objBmpImage.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); 

    // Write the MemoryStream to the Response stream, and set content type to image/gif. 
    memoryStream.WriteTo(Response.OutputStream); 
    Response.ContentType = "image/gif"; 
    Response.End(); 

    // Clean up. 
    memoryStream.Close(); 
    objGraphics.Flush(); 




} 

답변

3

사용 이하입니다.

감사합니다.

+0

나는 objBmpImage.MakeTransparent()를 사용했습니다. 그러나 그것은 나에게 같은 결과를 주었다. –

+0

실제로 저축하기 전에 마지막 통화처럼 통화 했습니까? – Tigran

+0

나는 그것을 b4라고 불렀다. ... MemoryStream memoryStream = new MemoryStream(); objBmpImage.Save (memoryStream, System.Drawing.Imaging.ImageFormat.Bmp); –

관련 문제