Quantcast
Channel: System.Drawing/GDI+
Viewing all 176 articles
Browse latest View live

Adding watermark into image won't work on the server but works perfectly on the local machine?

$
0
0

I need some help on figuring out what are the reasons why? or what I've been missing on this because I could hardly figure out why this works in my local machine and is not working on the server. I have a code in C# to print a watermark on the image and it works perfectly on my local machine but when I applied it into my web host server where I'm updating my site. It won't print any markings. Any thoughts about this? Here's my code below to help you more track what might be the reason why it won't work from the server.

string watermarkText = "© mywebsite.com";

//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(file.InputStream, false))
{
    using (Graphics grp = Graphics.FromImage(bmp))
    {
        //Set the Color of the Watermark text.
        Brush brush = new SolidBrush(Color.White);

        //Set the Font and its size.
        Font font = new System.Drawing.Font("san-serif", 20, FontStyle.Italic, GraphicsUnit.Pixel);

        //Determine the size of the Watermark text.
        SizeF textSize = new SizeF();
        textSize = grp.MeasureString(watermarkText, font);

        //Position the text and draw it on the image.
        Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
        grp.DrawString(watermarkText, font, brush, position);

        firstfname = Path.GetFileName(file.FileName).ToString();
        newfname = ProdId + firstfname;

        bmp.Save(Path.Combine(Server.MapPath("~/ProductImages/"), newfname));
        con.Open();
        string sqlProductImagesTab = "INSERT INTO [ProdImagesTab]([ProductIdforImages],[ProductImages],[SellerEmail]) Values('" + ProdId + "','" + newfname.Replace("'", "''") + "','" + SellerEmail + "')";
        SqlCommand cmd3 = new SqlCommand(sqlProductImagesTab, con);
        cmd3.CommandType = CommandType.Text;

        cmd3.ExecuteNonQuery();
        cmd3.Dispose();
        con.Close();

    }
}

 


How to get image.Width and Height from an image NOT on the server ?

$
0
0

I found several threads to get Width & Height from an image which resides on a server / or localhost ...

but nowhere for an image not on my server ..

Any clue to get around ?

As for example  i need to get the Width and Heigt from this image ..

 http://i.colnect.net/images/o/372/970/372970.jpg

this BELOW works for images on a server as it uses Server.Mappath  and the Object written by Persists , which resides on my server ..

set Jpeg = Server.createObject("Persits.Jpeg")

Path = Server.Mappath("image.jpg")

' need something like :    Path = "http://i.colnect.net/images/o/372/970/372970.jpg"    but this does not work ...

set Jpeg = Server.createObject("Persits.Jpeg")

Path = Server.Mappath("image.jpg")

Jpeg.Open Path

Jpeg.Width = Jpeg.OriginalWidth

Jpeg.Height = Jpeg.OriginalHeight

response.write("W=" + Cstr( Jpeg.Width ) + "<br>")

response.write("H=" + Cstr( Jpeg.Height ) + "<br>")

KIS !!  Keep it simple ...

How do I create an algoritm

$
0
0

Hello!

Assume I have on the x-axes the display area from x=40 pixels to x=750
pixels because I have some text to the far left so the x -axis start at position x = 40
If I now want to set a lot of point in this coordinate system.
For example if I have x-value 0 this would be positioned  at x = 40 and
x-value 800 would be positioned at x=750.
So I have to transform my x value into the coordinate system where origo for
x is 40 and x max is 800.

I can't find a suitable algoritm that can transform my x values into this
coordinate system.

//Tony

How to create image tiles from one big image

$
0
0

code taken from here http://www.estaun.net/blog/map-tiles-generator/

http://www.stefangordon.com/simple-image-tiling-in-c/

now tell me how to use the below code to generate tile for big images ?

what should be right value for MAXZOOM argument ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace GenerateTiles
{
    class Program
    {
        public struct OPTIONS
        {
            public const string FILEPATH = "f";
            public const string TARGETFOLDER = "t";
            public const string REMOVEXISTINGFILES = "d";
            public const string MAXZOOM = "max";
            public const string HELP = "help";
        }

        static void Main(string[] args)
        {
            Options options = new Options();
            options.AddOption(new Option(OPTIONS.FILEPATH, true, "File to parse"));
            options.AddOption(new Option(OPTIONS.TARGETFOLDER, true, "Folder to create tiles"));
            options.AddOption(new Option(OPTIONS.REMOVEXISTINGFILES, false, "Remove existing files"));
            options.AddOption(new Option(OPTIONS.MAXZOOM, true, "Max zoom dimension"));
            options.AddOption(new Option(OPTIONS.HELP, true, "Print this message"));

            BasicParser parser = new BasicParser();
            CommandLine cmd = parser.Parse(options, args);

            if (cmd.HasOption(OPTIONS.HELP))
            {
                HelpFormatter formatter = new HelpFormatter();
                formatter.PrintHelp("GenerateTiles", options);
                return;
            }

            if ((!cmd.HasOption(OPTIONS.FILEPATH)) ||
                (!cmd.HasOption(OPTIONS.TARGETFOLDER)) ||
                (!cmd.HasOption(OPTIONS.MAXZOOM)))
            {
                HelpFormatter formatter = new HelpFormatter();
                formatter.PrintHelp("GenerateTiles", options);
                return;
            }

            if (!System.IO.File.Exists(cmd.GetOptionValue(OPTIONS.FILEPATH)))
            {
                Console.WriteLine("file not exist");
                return;
            }

            double maxZoom;
            bool res = double.TryParse(cmd.GetOptionValue(OPTIONS.MAXZOOM), out maxZoom);
            if ((res == false) || (maxZoom >= 10))
            {
                Console.WriteLine("Scale multiplier should be  an integer <=10");
                return;
            }

            //Read image                    
            Bitmap bmSource;
            try
            {
                bmSource = (Bitmap)Bitmap.FromFile(cmd.GetOptionValue(OPTIONS.FILEPATH));
            }
            catch
            {
                Console.WriteLine("image file not valid");
                return;
            }

            //check directory exist
            if (!System.IO.Directory.Exists(cmd.GetOptionValue(OPTIONS.TARGETFOLDER)))
            {
                System.IO.Directory.CreateDirectory(cmd.GetOptionValue(OPTIONS.TARGETFOLDER));
            }
            else if (cmd.HasOption(OPTIONS.REMOVEXISTINGFILES))
            {
                string[] files = System.IO.Directory.GetFiles(cmd.GetOptionValue(OPTIONS.TARGETFOLDER));
                foreach (string file in files)
                    System.IO.File.Delete(file);

                string[] dirs = System.IO.Directory.GetDirectories(cmd.GetOptionValue(OPTIONS.TARGETFOLDER));
                foreach (string dir in dirs)
                    System.IO.Directory.Delete(dir, true);
            }

            int actualHeight = bmSource.Height;
            int actualWidth = bmSource.Width;

            if (((actualHeight % 256) != 0)
                ||
                ((actualWidth % 256) != 0))
            {
                Console.WriteLine("image width and height pixels should be multiples of 256");
                return;
            }

            int actualResizeSizeWidth = 1;

            int level = 0;
            while (level <= maxZoom)
            {
                string leveldirectory = System.IO.Path.Combine(cmd.GetOptionValue(OPTIONS.TARGETFOLDER), String.Format("{0}", level));
                if (!System.IO.Directory.Exists(leveldirectory))
                    System.IO.Directory.CreateDirectory(leveldirectory);

                int rowsInLevel = Convert.ToInt32(Math.Pow(2, level));
                actualResizeSizeWidth = 256 * rowsInLevel;

                //create image to parse
                int actualResizeSizeHeight = (actualHeight * actualResizeSizeWidth) / actualWidth;
                Bitmap resized = new Bitmap(bmSource, new Size(actualResizeSizeWidth, actualResizeSizeHeight));
                string levelSourceImage = System.IO.Path.Combine(leveldirectory, "level.png");
                resized.Save(levelSourceImage);

                for (int x = 0; x < rowsInLevel; x++)
                {
                    string levelrowdirectory = System.IO.Path.Combine(leveldirectory, String.Format("{0}", x));
                    if (!System.IO.Directory.Exists(levelrowdirectory))
                        System.IO.Directory.CreateDirectory(levelrowdirectory);

                    Bitmap bmLevelSource = (Bitmap)Bitmap.FromFile(levelSourceImage);

                    //generate tiles
                    int numberTilesHeight = Convert.ToInt32(Math.Ceiling(actualResizeSizeHeight / 256.0));
                    for (int y = 0; y < numberTilesHeight; y++)                     {                         Console.WriteLine("Generating Tiles  " + level.ToString() + " " + x.ToString() + " " + y.ToString());                         int heightToCrop = actualResizeSizeHeight >= 256 ? 256 : actualResizeSizeHeight;
                        Rectangle destRect = new Rectangle(x * 256, y * 256, 256, heightToCrop);
                        //croped
                        Bitmap bmTile = bmLevelSource.Clone(destRect, System.Drawing.Imaging.PixelFormat.DontCare);
                        //full tile
                        Bitmap bmFullTile = new Bitmap(256, 256);
                        Graphics gfx = Graphics.FromImage(bmFullTile);
                        gfx.DrawImageUnscaled(bmTile, 0, 0);
                        bmFullTile.Save(System.IO.Path.Combine(levelrowdirectory, String.Format("{0}.png", y)));
                        bmFullTile.Dispose();
                        bmTile.Dispose();
                    }
                }
                level++;
            }
        }
    }
}

Remove background color from Graphics.Clear()

$
0
0

HI all,

I have a code to resize image. it works good just one thing that I dont want. 

 Bitmap bmPhoto = new Bitmap(Width, Height,
                              PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(fullSizeImg.HorizontalResolution,
                             fullSizeImg.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.Clear(Color.Red);
            grPhoto.InterpolationMode = InterpolationMode.Default;
            grPhoto.CompositingQuality = CompositingQuality.HighQuality;
            grPhoto.SmoothingMode = SmoothingMode.HighQuality;

            grPhoto.DrawImage(fullSizeImg,
                new Rectangle(destX, destY, destWidth, destHeight),
                new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                GraphicsUnit.Pixel);

            grPhoto.Dispose();

In my bold section, it fills a Red color on outside of image. I dont want that red color. If I remove that line, it fills with black color. I dont want that color at all. I want it fits whatever empty spaces it is getting that filled with color.

how to create thumbnails while storing the image in images folder in webmatrix webpages razor site.

$
0
0

how to create thumbnails while storing the image in images folder in webmatrix webpages razor site.

Resize Image Returned by API

$
0
0

I have an API that returns an image from a byte array via a memory stream at the moment. I want to update it to return an image at a specific width and height given some inputs. What I'm not sure though, is how I manipulate the memory stream to say, the image is x wide and y tall. Here's the code now.

//dt is a data table with 1 row and 1 column. That column is the image stored as bytes in the database.
byte[] imgData = GetImgBytes();
WebOperationContext.Current.OutgoingResponse.ContentType = "image/png";
//DO NOT try to dispose of the memory stream or put it in a using. Putting it in there will make it dispose of it before it returns it. 
MemoryStream ms = new MemoryStream(imgData);

//##############################################################
//not sure how I'd change the width and height here. originally I was just returning ms
Image img = Image.FromStream(ms);
//##############################################################

ms.Position = 0; 
return ms;

System.Drawing DrawLines

$
0
0

The "FillRectangle" works. 

The lines do not. 

The "..." in the code is where I put the calculations for the 9 ellipses and their data. 

They do exist and they are in the 2000,2000 range.

          protected void Page_Load(object sender, EventArgs e)
          {
                ...
                using (Bitmap xPanel = new Bitmap(2000, 2000))
                {
                    using (Graphics objGraphicPanel = Graphics.FromImage(xPanel))
                    {
                        //Background Yellow
                        SolidBrush yellowBrush = new SolidBrush(Color.Yellow);
                        objGraphicPanel.FillRectangle(yellowBrush, 0, 0, 2000, 2000);
                        Pen colorPen = new Pen(Color.Black, 2);
                        MemoryStream ms = new MemoryStream();

                        for (k = 1; k <= 9; k++)
                        {
                            for (int nn = 2; nn <= n; nn++)
                            {
                                float x1 = Convert.ToSingle(XYecl[k, nn - 1]);
                                float y1 = Convert.ToSingle(ZYecl[k, nn - 1]);
                                float x2 = Convert.ToSingle(XYecl[k, nn]);
                                float y2 = Convert.ToSingle(ZYecl[k, nn]);
                                PointF[] ptf =
                                {
                                    new PointF(x1, y1),
                                    new PointF(x2, y2)
                                };
                                objGraphicPanel.DrawLines(colorPen, ptf);
                                xPanel.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }
                        string Imgbase64 = Convert.ToBase64String(ms.ToArray());
                        MyImage.Src = "data:image/png;base64," + Imgbase64;
                        objGraphicPanel.Dispose();
                    }
                    xPanel.Dispose();
                }
             }           


how to remove a section of image and move below part up in C#

$
0
0

I have a image in which i have the rectangle dimension of its which is needed to be removed from the image and the below section should be moved upper, how i can do that using the image processing library available in C#, or you have any kind of reference for this requirement please let me know and help me i am attaching the image for the problem statement.

MemoryStream into an iTextSharp jpg image

$
0
0

I now am trying to use System.Drawing in iTextSharp PDF creator.

I have successfully downloaded iTextSharp.dll from SourceForge, placed it in a folder in my ASP.net project and "Add Reference" browse to my solution.

It works fine.

I am having some trouble turning my MemoryStream, ms, into an iTextSharp jpg image as seen below:

Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
Dim output = New MemoryStream()
Dim writer = PdfWriter.GetInstance(doc, output)
doc.Open()
   Using xPanel As New Bitmap(500, 500)
        Using gphs As Graphics = Graphics.FromImage(xPanel)
            Dim ms As New MemoryStream()
            ...System.Drawing Code...
            xPanel.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
            Dim PdfImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg)
            doc.Add(PdfImage)
        End Using
    End Using
doc.Close
 ...


                       

how to render html to a image in memory?

$
0
0

hi guys,

i have a list to show data, and i need to  get these screenshot to my document.

many types data, so , i want to write a tool to auto save these screenshot in memory ,

it will be better if i can bind data to a control in memory then render it to image,

no simulate mouse click,all in memory, 

is it possible?

can you give me some ideas ?

thx your reply.

Why my upload code turn the image of 90° when resize the image, what is wrong?

$
0
0

Hi, i do not understa why, sometimes, not all the time... some images uploaded, when i reduce the size in my code, the image resized is saved as turned of 90°...

This is my code in my controller :

        [HttpPost]
        [Authorize]
        [ValidateAntiForgeryToken]
        public ActionResult CreationUpload(CreationHairTagsModel creationbind, IEnumerable<HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                foreach (var file in files)
                {
                    if (file != null)
                    {
                        if (file.ContentLength > 0)
                        {

                            var myuploadextension = Path.GetExtension(file.FileName);

                            if (myuploadextension.ToUpper() == ".JPEG" || myuploadextension.ToUpper() == ".JPG" || myuploadextension.ToUpper() == ".BMP" || myuploadextension.ToUpper() == ".PNG" || myuploadextension.ToUpper() == ".GIF")
                            {
                                var sizeMb = (file.ContentLength / 1024f) / 1024f; //file.contentlength is in bytes

                                var todaydate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                var todaydatefriendly = todaydate.ImageFriendly();

                                var myuploadiwthoutextension = Path.GetFileNameWithoutExtension(file.FileName);
                                int myuploadiwthoutextensionlen = (myuploadiwthoutextension.Length);
                                if (myuploadiwthoutextensionlen > 50)
                                {
                                    myuploadiwthoutextension = (myuploadiwthoutextension.Substring(0, 50));
                                }
                                var myuploadiwthoutextensionfriendly = myuploadiwthoutextension.ImageFriendly();

                                var UserId = User.Identity.GetUserId();
                                int UserIdlen = (UserId.Length);
                                if (UserIdlen > 8)
                                {
                                    UserId = (UserId.Substring(0, 8));
                                }

                                var fileName = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + myuploadextension;
                                var path = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName);

                                var fileName200 = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + "-200" + myuploadextension;
                                var path200 = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName200);

                                var fileName750 = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + "-650" + myuploadextension;
                                var path750 = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName750);

                                file.SaveAs(path);

                                WebImage img = new WebImage(path);

                                int CurrentWidth = img.Width;
                                int CurrentHeight = img.Height;

                                // With this i resize image highter than longer
                                var CurrentWidthHeightChoosen = "Width";
                                int CurrentWidthHeight = img.Width;
                                if (CurrentHeight > CurrentWidth)
                                {
                                    CurrentWidthHeight = img.Height;
                                    CurrentWidthHeightChoosen = "Height";
                                }

                                //***********
                                //RESIZE 200
                                //***********
                                if (CurrentWidthHeight > 200)
                                {

                                    int maxWidth = 200;
                                    int CreationWidthPercentual = 20000 / CurrentWidth;
                                    int maxHeight = (CurrentHeight * CreationWidthPercentual) / 100;

                                    // With this i resize image highter than longer
                                    if (CurrentWidthHeightChoosen == "Height")
                                    {
                                        maxHeight = 200;
                                        int CreationHeightPercentual = 20000 / CurrentHeight;
                                        maxWidth = (CurrentWidth * CreationHeightPercentual) / 100;
                                    }

                                    // Resize image
                                    var image = System.Drawing.Image.FromFile(path);
                                    var ratioX = (double)maxWidth / image.Width;
                                    var ratioY = (double)maxHeight / image.Height;
                                    var ratio = Math.Min(ratioX, ratioY);
                                    var newWidth = (int)(image.Width * ratio);
                                    var newHeight = (int)(image.Height * ratio);
                                    var newImage = new Bitmap(newWidth, newHeight);
                                    Graphics thumbGraph = Graphics.FromImage(newImage);

                                    thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                                    thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                                    thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

                                    thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight);
                                    image.Dispose();

                                    string fileRelativePath = "~/Content/UserCreations/" + Path.GetFileName(path200);
                                    newImage.Save(Server.MapPath(fileRelativePath), newImage.RawFormat);

                                    //Save database
                                    creationbind.Creation.CreationPhotoBis = fileName200;
                                }
                                else
                                {
                                    //Save database
                                    creationbind.Creation.CreationPhotoBis = fileName;
                                }


                                //***********
                                //RESIZE 650 (It was 750)
                                //***********
                                if (CurrentWidthHeight > 650)
                                {
                                    int maxWidth = 650;
                                    int CreationWidthPercentual = 65000 / CurrentWidth;
                                    int maxHeight = (CurrentHeight * CreationWidthPercentual) / 100;

                                    // With this i resize image highter than longer
                                    if (CurrentWidthHeightChoosen == "Height")
                                    {
                                        maxHeight = 650;
                                        int CreationHeightPercentual = 65000 / CurrentHeight;
                                        maxWidth = (CurrentWidth * CreationHeightPercentual) / 100;
                                    }

                                    // Resize image
                                    var image = System.Drawing.Image.FromFile(path);
                                    var ratioX = (double)maxWidth / image.Width;
                                    var ratioY = (double)maxHeight / image.Height;
                                    var ratio = Math.Min(ratioX, ratioY);
                                    var newWidth = (int)(image.Width * ratio);
                                    var newHeight = (int)(image.Height * ratio);
                                    var newImage = new Bitmap(newWidth, newHeight);
                                    Graphics thumbGraph = Graphics.FromImage(newImage);

                                    thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                                    thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                                    thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;

                                    thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight);
                                    image.Dispose();

                                    string fileRelativePath = "~/Content/UserCreations/" + Path.GetFileName(path750);
                                    newImage.Save(Server.MapPath(fileRelativePath), newImage.RawFormat);

                                    //Save database
                                    creationbind.Creation.CreationPhoto750 = fileName750;
                                }
                                else
                                {
                                    //Save database
                                    creationbind.Creation.CreationPhoto750 = fileName;
                                }

                                creationbind.Creation.CreationPhotoReal = fileName; //after add

                                db.Creations.Add(creationbind.Creation);
                                db.SaveChanges();
                            }


                        }
                    }
                }

                //UserId
                return RedirectToAction("CreationList", "Creation", new { UserId = User.Identity.GetUserId() });
            }

            return View(creationbind);
        }

For example this piscture, which is fine as original :

http://www.collectionhair.it/Content/UserCreations/2016-10-18-040416-6470fdbe-img-6238.JPG

when resized to 650 became like this, is turned of 90° (the same happen when i resize of 200)... as i show :

http://www.collectionhair.it/Content/UserCreations/2016-10-18-040416-6470fdbe-img-6238-650.JPG

What is wrong in my code?

How to convert SSRS multipage TIFF image into SINGLE jpeg or png image?

$
0
0

Hi, I need to be able to exportan SSRS report as an image. Now, as far as I am aware, TIFF is the only image version that SSRS supports generating a multipage image in one call. I need to intercept the return TIFF byte[] array from my SOAP request and convert the multipage TIFF images into a single jpeg or png file containing all of the TIFF file images. Can anybody suggest a best approach? Googlong generally brings up conversions to pdf which I have tried to emulate but I think I have clouded my thinking now by over exposure and really need a pointer in right direction. Many thanks.

How to Measure the Height of a Table that is a String using The Art of Dev

$
0
0

Hello,

I'm using the Library that is nothing less that awesome is will render a string HTML perfectly.

What I am doing is I have a group of algorithms that you pass it a List<Part> parts and it will return a perfect Table with a header and all the columns perfectly and for each table that is created I add it to a list List<String>, so I've got a list of tables so when all the table are created it is time to loop the list and each table is added to "The Art Of Dev" and each table is written to an image perfectly but I've got a problem, for those sheets of data that will extend beyond a traditional document, as in, the Word document it with return an extra long document / image or it will return a fixed size document / image, which a Max / Mix size can be set and the rest of the data is clipped and does not show.

In my loop I need a way to measure the height of each table before I write it to the image.

Now, I do realize that one can measure Text with the graphic object but a none rendered table is different.

CAN SOMEONE PLEASE TELL ME HOW TO MEASURE A TABLE HEIGHT so i can at that point before sending it to be written to render that document, give it a header / fotoer and page number, then restart a whole new document. All my documents needs to be the size of a word document.

Thank you!!!

Get number of layers on tiff (photoshop) file

$
0
0

Hello people! I need to get the number of layers on a tiff file.

The files are created with Photoshop, and I have to get the number of layers on the file. Do you know some way to get it.

I've tried this:

int numb = image.GetFrameCount(FrameDimension.Page); 

But shows me 1 when the file has 3 layers....

I also know that a file has an alpha channel is image.GetPropertyItem(277).Value[0] > 4 - So may be some other property item give me that, but I don't know which code or which method get this value. Thanks in advance.


saving image with specific name before javascript function

$
0
0

hello 

I have below code which convert text to imag on page load

I want this to happen before any other javascript function..I have a javascript function function init()(in aspx page)..I want the below code to happen before function init() how do i do that?

 <asp:Label ID="Label1" runat="server" Text="1234" />
Dim text As String = Label1.Text.Trim() Dim bitmap As New Bitmap(1, 1) Dim font As New Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel) Dim graphics As Graphics = Graphics.FromImage(bitmap) Dim width As Integer = CInt(graphics.MeasureString(text, font).Width) Dim height As Integer = CInt(graphics.MeasureString(text, font).Height) bitmap = New Bitmap(bitmap, New Size(width, height)) graphics = Graphics.FromImage(bitmap) graphics.Clear(Color.White) graphics.SmoothingMode = SmoothingMode.AntiAlias graphics.TextRenderingHint = TextRenderingHint.AntiAlias graphics.DrawString(text, font, New SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0) graphics.Flush() graphics.Dispose() Dim fileName As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) & ".jpg" bitmap.Save(Server.MapPath("/imgs/12.jpg") & fileName, ImageFormat.Jpeg)

change the size of the image

$
0
0

Hello

I have below code, Can some one please tell me how do I create an image with 250 height and 250 width

below code creates a very small image file...

 Dim text As String = Label1.Text.Trim()
        Dim bitmap As New Bitmap(1, 1)
        Dim font As New Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel)
        Dim graphics As Graphics = Graphics.FromImage(bitmap)
        Dim width As Integer = CInt(graphics.MeasureString(text, font).Width)
        Dim height As Integer = CInt(graphics.MeasureString(text, font).Height)
        bitmap = New Bitmap(bitmap, New Size(width, height))
        graphics = Graphics.FromImage(bitmap)
        graphics.Clear(Color.White)
        graphics.SmoothingMode = SmoothingMode.AntiAlias
        graphics.TextRenderingHint = TextRenderingHint.AntiAlias
        graphics.DrawString(text, font, New SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0)
        graphics.Flush()
        graphics.Dispose()
        'Dim fileName As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) & ".jpg"
        Dim fileName As String = "12.jpg"
        bitmap.Save(Server.MapPath("/imgs/") & fileName, ImageFormat.Jpeg)

Text in the center of the image and in 3d

$
0
0

Hello I have below code which converts text to an image on page...I want this text to appear in the center of the image and should be written in 3D...how do I do that?

 Dim text As String = "ABC"
        Dim bitmap As New Bitmap(1, 1)
        Dim font As New Font("Arial", 40, FontStyle.Regular, GraphicsUnit.Pixel)
        Dim graphics As Graphics = Graphics.FromImage(bitmap)
        'Dim width As Integer = CInt(graphics.MeasureString(text, font).Width)
        'Dim height As Integer = CInt(graphics.MeasureString(text, font).Height)
        Dim width As Integer = 250
        Dim height As Integer = 250
        bitmap = New Bitmap(bitmap, New Size(width, height))
        graphics = Graphics.FromImage(bitmap)
        graphics.Clear(Color.White)
        graphics.SmoothingMode = SmoothingMode.AntiAlias
        graphics.TextRenderingHint = TextRenderingHint.AntiAlias
        graphics.DrawString(text, font, New SolidBrush(Color.FromArgb(255, 0, 0)), 0, 0)
        graphics.Flush()
        graphics.Dispose()
        'Dim fileName As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) & ".jpg"
        Dim fileName As String = "12.jpg"
        bitmap.Save(Server.MapPath("/imgs/") & fileName, ImageFormat.Jpeg)

DrawString make gaps between characters

$
0
0

Hi

I'm looking for character spacing functionin GDI as in MS Word

because DrawString make large gaps between characters.

Thank you.

ImageMagick Command Line

$
0
0

Hi
I am new to ImageMagick and I want to use Fred's ImageMagick Scripts in asp.net

I use this code to run simpler script

        Dim proc As New Diagnostics.Process()
        Dim arg As String = String.Format("convert  {0} -aspet 1:1 {1} ", Server.MapPath("~/images/") & "old.png", Server.MapPath("~/images/") & "new.png") 'work
        proc.StartInfo.Arguments = String.Format(arg)
        proc.StartInfo.FileName = Server.MapPath("Magick.exe")
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.CreateNoWindow = True
        proc.StartInfo.RedirectStandardOutput = False
        proc.Start()
        Response.Write(arg)

But all script not work

Viewing all 176 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>