473,948 Members | 9,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image concatenation in c#

Hi,
I haven't had much luck searching for guidance on the following
challenge.
I have a .NET app in which I would like to take multiple thumnail
images and combine them into one flat image.
Could someone give me an example of how to take two images, imgA and
imgB and create imgC which would be one image of imgA and imgB side by
side or imgA on top of imgB. If both imgA and imgB are 10pixels x 10
pixels, the side by side version of imgC would be 10pixels x 20 pixels.
Thanks in advance.

Jon

May 18 '06 #1
10 5778
First, you create an image that is 10X20 pixels in size, and get the
Graphics from it to draw on it. Then you draw the first image on one half,
and the second on the other. For details, see the System.Drawing namespace:

http://msdn.microsoft.com/library/en...asp?frame=true

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

"byrd48" <by*****@rocket mail.com> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
Hi,
I haven't had much luck searching for guidance on the following
challenge.
I have a .NET app in which I would like to take multiple thumnail
images and combine them into one flat image.
Could someone give me an example of how to take two images, imgA and
imgB and create imgC which would be one image of imgA and imgB side by
side or imgA on top of imgB. If both imgA and imgB are 10pixels x 10
pixels, the side by side version of imgC would be 10pixels x 20 pixels.
Thanks in advance.

Jon

May 18 '06 #2
Thanks,
Could you point me to a code example? I've looked around for a day now
and haven't found the solution. I've seen examples of overlaying
watermarks on images, but not taking two images and "gluing them
together" to make one.

thanks again.

Jon

May 18 '06 #3
I don't know where to find a code sample. It's pretty straightforward . Let's
say you have 2 images, each is 10X10 pixels in size. You want to put
"imageA" on the left, and "imageB" on the right. You create a 20X10 image,
get the Graphics from it, and draw each image at its original size. The only
difference is that you draw "imageA" at location (0,0) and "imageB" at
location (10,0).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

"byrd48" <by*****@rocket mail.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.com.. .
Thanks,
Could you point me to a code example? I've looked around for a day now
and haven't found the solution. I've seen examples of overlaying
watermarks on images, but not taking two images and "gluing them
together" to make one.

thanks again.

Jon

May 18 '06 #4
Here's the code I'm trying:

System.Drawing. Graphics g;
System.Drawing. Bitmap newImg = new Bitmap(600, 200);
System.Drawing. Image img1 =
System.Drawing. Image.FromFile( Server.MapPath( "./images/") +
"airport_r1_c2. gif");
System.Drawing. Image img2 =
System.Drawing. Image.FromFile( Server.MapPath( "./images/") +
"airport_r2_c2_ f2.gif");
g = System.Drawing. Graphics.FromIm age(newImg);
g.DrawImage(img 1,0,0);
g.DrawImage(img 2, 281, 0);
g.Save();
newImg.Save(Ser ver.MapPath("./images/") + "NewBitmap.jpg" );
System.Runtime. InteropServices .ExternalExcept ion was unhandled by user
code
Message="A generic error occurred in GDI+."
Source="System. Drawing"
ErrorCode=-2147467259
StackTrace:
at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo
encoder, EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stri ng filename, ImageFormat
format)
at System.Drawing. Image.Save(Stri ng filename)
at Default2.Page_L oad(Object sender, EventArgs e) in
c:\Inetpub\wwwr oot\Test\Defaul t2.aspx.cs:line 28
at System.Web.Util .CalliHelper.Ev entArgFunctionC aller(IntPtr fp,
Object o, Object t, EventArgs e)
at
System.Web.Util .CalliEventHand lerDelegateProx y.Callback(Obje ct sender,
EventArgs e)
at System.Web.UI.C ontrol.OnLoad(E ventArgs e)
at System.Web.UI.C ontrol.LoadRecu rsive()
at System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)

May 18 '06 #5
What are the actual dimensions of both images? Considering the fact that
these images are different image types than the Bitmap you're drawing to, I
would suggest using the overload that takes a Rectangle instead of an X and
a Y.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

"byrd48" <by*****@rocket mail.com> wrote in message
news:11******** **************@ 38g2000cwa.goog legroups.com...
Here's the code I'm trying:

System.Drawing. Graphics g;
System.Drawing. Bitmap newImg = new Bitmap(600, 200);
System.Drawing. Image img1 =
System.Drawing. Image.FromFile( Server.MapPath( "./images/") +
"airport_r1_c2. gif");
System.Drawing. Image img2 =
System.Drawing. Image.FromFile( Server.MapPath( "./images/") +
"airport_r2_c2_ f2.gif");
g = System.Drawing. Graphics.FromIm age(newImg);
g.DrawImage(img 1,0,0);
g.DrawImage(img 2, 281, 0);
g.Save();
newImg.Save(Ser ver.MapPath("./images/") + "NewBitmap.jpg" );
System.Runtime. InteropServices .ExternalExcept ion was unhandled by user
code
Message="A generic error occurred in GDI+."
Source="System. Drawing"
ErrorCode=-2147467259
StackTrace:
at System.Drawing. Image.Save(Stri ng filename, ImageCodecInfo
encoder, EncoderParamete rs encoderParams)
at System.Drawing. Image.Save(Stri ng filename, ImageFormat
format)
at System.Drawing. Image.Save(Stri ng filename)
at Default2.Page_L oad(Object sender, EventArgs e) in
c:\Inetpub\wwwr oot\Test\Defaul t2.aspx.cs:line 28
at System.Web.Util .CalliHelper.Ev entArgFunctionC aller(IntPtr fp,
Object o, Object t, EventArgs e)
at
System.Web.Util .CalliEventHand lerDelegateProx y.Callback(Obje ct sender,
EventArgs e)
at System.Web.UI.C ontrol.OnLoad(E ventArgs e)
at System.Web.UI.C ontrol.LoadRecu rsive()
at System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint)

May 18 '06 #6
The dimensions of each are 280 x 17. I was making the new bitmap large
enough to accomodate them plus several others.
Thanks,
Jon

May 18 '06 #7
Make the Bitmap large enough to accomodate exactly what you need to draw.
Let me know if the Rectangle solution works for you. It will resize the
image to fit in the Rectangle.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

"byrd48" <by*****@rocket mail.com> wrote in message
news:11******** *************@j 33g2000cwa.goog legroups.com...
The dimensions of each are 280 x 17. I was making the new bitmap large
enough to accomodate them plus several others.
Thanks,
Jon

May 18 '06 #8
Hi,
I've had some success, however the placement of images is still not
working as I think it should. In this example, I'm taking one image,
SlotLarge.jpg and am placing it twice into a new image. The file is 48
x 67. I'm placing the first instance at (0, 0) and the second at (0,
68), so they should be one over the other. What's happening though is
the second one is overlapping the first one. You can see the files at:
http://www.byrd48.net/imagetest.htm

The code is below. Thanks again.

m_fileDir =
@"c:\inetpub\ww wroot\pfs\image s\machines\45co untlarge\";

m_Bitmap = new Bitmap(320, 600);
Graphics g = Graphics.FromIm age(m_Bitmap);

System.Drawing. Image _img =
System.Drawing. Image.FromFile( m_fileDir + "SlotLarge.jpg" );
g.DrawImage(_im g, 0, 0);

g.DrawImage(_im g, 0, 68);

m_Bitmap.Save(m _fileDir + "testimage.jpg" ,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

May 24 '06 #9
It is important to follow instructions carefully. Do you remember when I
recommended that you use the overload of the DrawImage method that takes a
destination rectangle? Your image is being drawn larger than it is
originally. I mentioned that, due to the different image formats, the image
scaling might be necessary. Also, if you had only made the area exactly the
size you need to draw to (also recommended earlier), you would have seen
immediately that the image was not the same size in the bitmap.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

The man who questions opinions is wise.
The man who quarrels with facts is a fool.

"byrd48" <by*****@rocket mail.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.com.. .
Hi,
I've had some success, however the placement of images is still not
working as I think it should. In this example, I'm taking one image,
SlotLarge.jpg and am placing it twice into a new image. The file is 48
x 67. I'm placing the first instance at (0, 0) and the second at (0,
68), so they should be one over the other. What's happening though is
the second one is overlapping the first one. You can see the files at:
http://www.byrd48.net/imagetest.htm

The code is below. Thanks again.

m_fileDir =
@"c:\inetpub\ww wroot\pfs\image s\machines\45co untlarge\";

m_Bitmap = new Bitmap(320, 600);
Graphics g = Graphics.FromIm age(m_Bitmap);

System.Drawing. Image _img =
System.Drawing. Image.FromFile( m_fileDir + "SlotLarge.jpg" );
g.DrawImage(_im g, 0, 0);

g.DrawImage(_im g, 0, 68);

m_Bitmap.Save(m _fileDir + "testimage.jpg" ,
System.Drawing. Imaging.ImageFo rmat.Jpeg);

May 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3665
by: Jonas Galvez | last post by:
Is it true that joining the string elements of a list is faster than concatenating them via the '+' operator? "".join() vs 'a'+'b'+'c' If so, can anyone explain why?
7
8048
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so something like this: 1) e = (a, b, c, d); // concatenate a,b,c,d into e 2) (a, b, c, d) = e; // get the bits of e into a,b,c, and d For example, in the second case, assume that a,b,c,d represent 2-bit integers, and e represents an 8-bit...
3
7722
by: Bill Brother | last post by:
Is it possible to retrieve the local full path of an image ( not the url )?
23
12320
by: John | last post by:
Last year, I remember finding a web page describing how to pass the name of a file to another web page, and have that web page load that image file. Now, I can't find my record of that (it was saved on another computer that I can't get to right now), and I can't remember what search parameters I used to find it when I googled the topic. Can anyone point me the right direction? I'd like to use a method that would be accessible to the...
10
7425
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
33
4725
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most of articles I read from different experts and programmers tell me that their "gut feelings" for using stringBuilder instead of string concatenation is when the number of string concatunation is more then N ( N varies between 3 to max 15 from...
5
2401
by: Camet | last post by:
I have been trying to create a dynamic id for a number of images in a table so that I can identify which image was clicked on later. ie I need to set a variable to the id of each image, that is generated by a loop. The info is read from an XML file in another function and each section of info is stored as a separate object; Each object is pertaining to one row in the table. function createTable () { var output, dynamId;
34
2701
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ____________ THE OVERVIEW I don't remember where I picked it up, but I remember reading years ago that the simple, obvious Python approach for string concatenation: x = "a" + "b"
34
3615
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding 200000 strings of 8 char each, string took over 25 minutes while StringBuilder took 40 milliseconds! Can anybody explain such a radical difference?
0
9989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11582
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11181
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11355
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9898
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8257
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4543
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3547
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.