locked
print basket to image RRS feed

  • Question

  • User-1763060630 posted
    <DIR>

    hi, I have a question. How can I code the name, id, price and total amount of basket content as image?

     

    pls help

    </DIR>
    Thursday, November 27, 2008 4:57 AM

Answers

  • User589874384 posted

    Hi ozel1!

    You could try the System.Drawing.Bitmap. Try this code in your test application:

    Dim objBitMap As New Bitmap(310, 139)

    Dim descVote As PointF = New Point(270, 12)

    objGraphics.DrawString("your text here in string", New Font("Tahoma", 10), Brushes.Black, descVote)

     

    You have to set your canvass first as New Bitmap with the width and height of 310 and 139 respectively. New Point refers to your x and y locations of your canvass. Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 27, 2008 10:38 PM

All replies

  • User494352855 posted

    Well, you (or I) could make a handler that generates the image based on the data in the querystring...

    image.ashx?name=ProductX&id=12424&price=45.89&total=90

    You *must* have disk caching though.... I can't stress this enough. Otherwise this apprach will fail under load. I'd recommend using the disk caching system from this module.

    I wrote it, and it's been thoroughly tested for years on production systems.

    I write lots of image composition and rendering for people... If you're interested, send me an e-mail at nathanael.jones@gmail.com. Rates are $95/hr<//p>

    Thursday, November 27, 2008 9:18 AM
  • User-1763060630 posted
    no thnx
    Thursday, November 27, 2008 9:40 AM
  • User589874384 posted

    Hi ozel1!

    You could try the System.Drawing.Bitmap. Try this code in your test application:

    Dim objBitMap As New Bitmap(310, 139)

    Dim descVote As PointF = New Point(270, 12)

    objGraphics.DrawString("your text here in string", New Font("Tahoma", 10), Brushes.Black, descVote)

     

    You have to set your canvass first as New Bitmap with the width and height of 310 and 139 respectively. New Point refers to your x and y locations of your canvass. Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 27, 2008 10:38 PM
  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    You can use Font object and Drawing2D object to achieve that. Here’s the sample for you to refer.

    <o:p> </o:p>

    System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);

    Graphics g = Graphics.FromImage(image);

    <o:p></o:p>

          

                Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));

                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);

                g.DrawString("You content here", font, brush, 2, 2);

    <o:p> </o:p>

                System.IO.MemoryStream ms = new System.IO.MemoryStream();

                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

                Response.ClearContent();

                Response.ContentType = "image/Gif";

                Response.BinaryWrite(ms.ToArray());

    <o:p> </o:p>

    Thanks.

     

    Tuesday, December 2, 2008 1:06 AM
  • User-1763060630 posted

    First of all, thanks a lot. I received an error when I used to code you gave me. The error is displayed in the picture below. Do you have a complete sample of this that you've used before.

     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
    
            Graphics g = Graphics.FromImage(image);
    
    
    
            Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
    
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
    
            g.DrawString("You content here", font, brush, 2, 2);
    
    
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
    
            image.Save("name.gif", System.Drawing.Imaging.ImageFormat.Gif);
    
            Response.ClearContent();
    
            Response.ContentType = "image/Gif";
    
            Response.BinaryWrite(ms.ToArray());
    
    
        }
    }
    
     

    Tuesday, December 2, 2008 3:43 AM
  • User589874384 posted

     you forgot to add in your namespace:

    using System.Drawing

    using System.Drawing.Imaging

    Tuesday, December 2, 2008 3:53 AM
  • User-1136466523 posted

    Hi,

    "checkCode" is the content you want to write in the image. You can define the variable in your code context.

    Thanks.

    Tuesday, December 2, 2008 4:45 AM
  • User-1763060630 posted
    I've tried but still the same error.
    Tuesday, December 2, 2008 4:46 AM
  • User-1763060630 posted

    Yes, you're great. If you can just write a sample code there I'll get it better. I have very little knowledge about System.Drawing

    Tuesday, December 2, 2008 4:52 AM
  • User-1763060630 posted
    ?[:@]
    Monday, December 15, 2008 2:08 AM