Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6572407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:00:07+00:00 2026-05-25T15:00:07+00:00

I’m dynamically generating image from text, and existing image on my asp.net website. Here

  • 0

I’m dynamically generating image from text, and existing image on my asp.net website.

Here is the code:

protected void Button1_Click(object sender, EventArgs e)
{
    var tytul = Request.QueryString["Tytul"];
    var tresc = Request.QueryString["Tresc"];

    var font = new Font("Verdana", 23);

    var brushForeColor = new SolidBrush(Color.Black);
    var brushBackColor = new SolidBrush(Color.FromArgb(248, 247, 182));

    var test = new Bitmap(450, 60);
    var graphicstest = Graphics.FromImage(test);
    var width = (int)graphicstest.MeasureString(tresc, font).Width;
    var height = (int)graphicstest.MeasureString(tresc, font).Height;

    while (width > 450)
    {
        height = height + 25;
        width = width - 450;
    }

    var heightall = height + 40 + 30 + 100;

    var bitmap = new Bitmap(450, heightall);
    var graphics = Graphics.FromImage(bitmap);

    var displayRectangle = new Rectangle(new Point(0, 0), new Size(450, 40));
    graphics.FillRectangle(brushBackColor, displayRectangle);

    //Define string format 
    var format1 = new StringFormat(StringFormatFlags.NoClip);
    format1.Alignment = StringAlignment.Center;

    var format2 = new StringFormat(format1);

    //Draw text string using the text format
    graphics.DrawString(tytul, font, brushForeColor, displayRectangle, format2);

    // Rysowanie drugiego boxa

    brushBackColor = new SolidBrush(Color.FromArgb(253, 253, 202));
    font = new Font("Verdana", 18);

    displayRectangle = new Rectangle(new Point(0, 40), new Size(450, height + 30));
    graphics.FillRectangle(brushBackColor, displayRectangle);

    displayRectangle = new Rectangle(new Point(0, 55), new Size(450, height + 15));


    graphics.DrawString(tresc, font, brushForeColor, displayRectangle, format2);

    graphics.DrawImage(System.Drawing.Image.FromFile(Server.MapPath(".") + "/gfx/layout/podpis.png"), new Point(0, height + 70));

    Response.ContentType = "image/png";
    bitmap.Save(Response.OutputStream, ImageFormat.Png);      
}

As you can see the bitmap is saved and showed on aspx page after postback. What I wanna do is when user click Button1, then image is generated and browser download window pops up, without saving on server or showing on page. How to do this? Please help me.

Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:00:08+00:00Added an answer on May 25, 2026 at 3:00 pm

    You need to add a Content-Disposition header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.