Last post Apr 03, 2009 09:23 PM by email@example.com
May 23, 2007 11:42 AM|Esqueleto|LINK
I've read many posts in this forum about resizing images and writing text in images as a WaterMark. What I want is to merge to images and show in a <img> tag.
One of the images will be transparent and can be put any where in the first image (top left, top right or lower) then the tow images could not have the exact size.
how can do this?
tkx in advace
Paulo Aboim Pinto
Oivelas - Portugal
May 23, 2007 01:01 PM|Benners_J|LINK
There are a couple of parts to what you are trying to do. First of all, you need to combine the two images. Second, you need to display the image on the web page. The img tag always needs a web link, so you'll need to create another web page that writes
out the image.
First you will need to create a new aspx page to use as the image link. In this page, you will combine the two pictures.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Open the images
Dim img1 As New Bitmap("c:\test\1.jpg")
Dim img2 As New Bitmap("c:\test\2.jpg")
' Create a new image that supports transparency if the original image doesn't.
' You may need to do this for both images, or for neither
' depending on the original pictures
Dim img3 As New Bitmap(img2.Width, img2.Height, Imaging.PixelFormat.Format32bppArgb)
Graphics.FromImage(img3).DrawImage(img2, 0, 0)
' Create a graphics object for the first image
' that we can use to draw the second image with
Dim g As Graphics = Graphics.FromImage(img1)
' Make the second image partially transparent.
' You can skip this step if the image is already transparent.
Dim currentColor As Color
For x As Integer = 0 To img3.Width - 1
For y As Integer = 0 To img3.Height - 1
currentColor = img3.GetPixel(x, y)
' The first number (100) is the amount of transparency
' 0 is totally transparent. 255 is opaque
img3.SetPixel(x, y, Color.FromArgb(100, currentColor.R, currentColor.G, currentColor.B))
' Draw the second image overtop of the first.
' The second and third arguments tell where to draw
' the top-left corner of the image in relation to the
' first image
g.DrawImage(img3, 0, 0)
' Save the image to a memory stream so we can
' write it back out.
Dim imgStream As New MemoryStream()
' Write the image to the web browser
Response.ContentType = "image/jpeg"
' Make sure the web page doesn't write out anything
' other than the image
If the above code is in an .aspx page called "image.aspx", then you would link to it in your other page using
<img src="image.aspx" />
You could probably do a lot to clean up the code, but that should get you looking in the right direction.
Also, there is a good demonstration on CodeProject
Jul 04, 2008 04:11 AM|karnan|LINK
I have problem in combining one or more images into one. I have a XML which will have images path and their dimensions. I need combine the images according to given x and y values of the images.
The images are transparent, but when i try to overlap image on to other image the background is also displaying, since it is transparent image it should not show the background.
Please help me in this issue. Below is the code i used to generate.
OutPutGraphics.DrawImageUnscaled(Title, 200, 50, 10, 60);
OutPutGraphics.DrawImageUnscaled(SubTitleBox, 500, 50, 100, 100);
OutPutGraphics.DrawImage(SubTitleBox1, 800, 500, 100, 100);
OutPutGraphics.SmoothingMode = System.Drawing.Drawing2D.
Apr 03, 2009 09:23 PMfirstname.lastname@example.org|LINK
The MakeTransparent() method uses the system, which is the Web Server, default transparent color. It might be different from the system default transpatent color of your development PC. Why don't you try to use a specific color?
"image processing" image processing graphics