473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how to merge to picture box

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Drawing.Imaging;
  8. namespace load_image
  9. {
  10.  /// <summary>
  11.  /// Summary description for Form1.
  12.  /// </summary>
  13.  public class Form1 : System.Windows.Forms.Form
  14.  {
  15.   private System.Windows.Forms.OpenFileDialog openFileDialog1;
  16.   private System.Windows.Forms.PictureBox pictureBox1;       
  17.   private System.Windows.Forms.PictureBox pictureBox2;  
  18.         private System.Windows.Forms.PictureBox pictureBox3;
  19.         private Button button1;
  20.         private Button button2;
  21.         private IContainer components;
  22.   public Form1()
  23.   {
  24.    //
  25.    // Required for Windows Form Designer support
  26.    //
  27.    InitializeComponent();
  28.    //
  29.    // TODO: Add any constructor code after InitializeComponent call
  30.    //
  31.   }
  32.   /// <summary>
  33.   /// Clean up any resources being used.
  34.   /// </summary>
  35.   protected override void Dispose( bool disposing )
  36.   {
  37.    if( disposing )
  38.    {
  39.     if (components != null)
  40.     {
  41.      components.Dispose();
  42.     }
  43.    }
  44.    base.Dispose( disposing );
  45.   }
  46.   #region Windows Form Designer generated code
  47.   /// <summary>
  48.   /// Required method for Designer support - do not modify
  49.   /// the contents of this method with the code editor.
  50.   /// </summary>
  51.   private void InitializeComponent()
  52.   {
  53.             this.components = new System.ComponentModel.Container();
  54.             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
  55.             this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  56.             this.pictureBox1 = new System.Windows.Forms.PictureBox();
  57.  
  58.             this.pictureBox2 = new System.Windows.Forms.PictureBox();
  59.             this.pictureBox3 = new System.Windows.Forms.PictureBox();
  60.             this.button1 = new System.Windows.Forms.Button();
  61.             this.button2 = new System.Windows.Forms.Button();
  62.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  63.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
  64.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
  65.             this.SuspendLayout();
  66.             //
  67.             // pictureBox1
  68.             //
  69.             this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  70.             this.pictureBox1.Location = new System.Drawing.Point(13, 3);
  71.             this.pictureBox1.Name = "pictureBox1";
  72.             this.pictureBox1.Size = new System.Drawing.Size(256, 240);
  73.             this.pictureBox1.TabIndex = 0;
  74.             this.pictureBox1.TabStop = false;
  75.  
  76.             //
  77.             // pictureBox2
  78.             //
  79.             this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
  80.             this.pictureBox2.Location = new System.Drawing.Point(284, 1);
  81.             this.pictureBox2.Name = "pictureBox2";
  82.             this.pictureBox2.Size = new System.Drawing.Size(256, 240);
  83.             this.pictureBox2.TabIndex = 2;
  84.             this.pictureBox2.TabStop = false;
  85.             //
  86.             // pictureBox3
  87.             //
  88.             this.pictureBox3.Location = new System.Drawing.Point(12, 256);
  89.             this.pictureBox3.Name = "pictureBox3";
  90.             this.pictureBox3.Size = new System.Drawing.Size(425, 231);
  91.             this.pictureBox3.TabIndex = 3;
  92.             this.pictureBox3.TabStop = false;
  93.             //
  94.             // button1
  95.             //
  96.             this.button1.Location = new System.Drawing.Point(465, 429);
  97.             this.button1.Name = "button1";
  98.             this.button1.Size = new System.Drawing.Size(75, 23);
  99.             this.button1.TabIndex = 4;
  100.             this.button1.Text = "Merge ";
  101.             this.button1.UseVisualStyleBackColor = true;
  102.             this.button1.Click += new System.EventHandler(this.button1_Click);
  103.             //
  104.             // button2
  105.             //
  106.             this.button2.Location = new System.Drawing.Point(465, 458);
  107.             this.button2.Name = "button2";
  108.             this.button2.Size = new System.Drawing.Size(75, 23);
  109.             this.button2.TabIndex = 5;
  110.             this.button2.Text = "Save";
  111.             this.button2.UseVisualStyleBackColor = true;
  112.             this.button2.Click += new System.EventHandler(this.button2_Click);
  113.             //
  114.             // Form1
  115.             //
  116.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  117.             this.ClientSize = new System.Drawing.Size(561, 497);
  118.             this.Controls.Add(this.button2);
  119.             this.Controls.Add(this.button1);
  120.             this.Controls.Add(this.pictureBox3);
  121.             this.Controls.Add(this.pictureBox2);
  122.             this.Controls.Add(this.pictureBox1);           
  123.             this.Name = "Form1";
  124.             this.Text = "Form1";
  125.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  126.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
  127.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
  128.             this.ResumeLayout(false);
  129.   }
  130.   #endregion
  131.   /// <summary>
  132.   /// The main entry point for the application.
  133.   /// </summary>
  134.   [STAThread]
  135.   static void Main()
  136.   {
  137.    Application.Run(new Form1());
  138.   } 
  139.  
  140.  
  141.   public Bitmap Merge( Bitmap bmp , Bitmap bmpimg)
  142.   {
  143.    BitmapData bmpData = bmpimg.LockBits( new Rectangle( 0 , 0 , bmpimg.Width , bmpimg.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
  144.    BitmapData bmpData2 = bmp.LockBits( new Rectangle( 0 , 0 , bmp.Width  , bmp.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
  145.    int width = bmpData.Width;
  146.    int height = bmpData.Height;
  147.    if( bmpData2.Width > width )
  148.     width = bmpData2.Width;
  149.    if( bmpData2.Height > height )
  150.     height = bmpData2.Height;
  151.    bmpimg.UnlockBits( bmpData );
  152.    bmp.UnlockBits( bmpData2 );
  153.  
  154.    Bitmap bit1 = new Bitmap( bmpimg , width , height );
  155.    Bitmap bit2 = new Bitmap( bmp , width , height );
  156.    Bitmap bmpresult = new Bitmap( width , height );
  157.    BitmapData data1 = bit1.LockBits( new Rectangle( 0 , 0 , bit1.Width , bit1.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
  158.    BitmapData data2 = bit2.LockBits( new Rectangle( 0 , 0 , bit2.Width , bit2.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb );
  159.    BitmapData data3 = bmpresult.LockBits( new Rectangle( 0 , 0 , bmpresult.Width , bmpresult.Height ) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb);
  160.    unsafe
  161.    {
  162.     int remain1 = data1.Stride - data1.Width * 3;
  163.     int remain2 = data2.Stride - data2.Width * 3;
  164.     int remain3 = data3.Stride - data3.Width * 3;
  165.  
  166.     byte* ptr1 = ( byte* )data1.Scan0;
  167.     byte* ptr2 = ( byte* )data2.Scan0;
  168.     byte* ptr3 = ( byte* )data3.Scan0;
  169.  
  170.     for( int i = 0 ; i < height ; i ++ )
  171.     {
  172.      for( int j = 0 ; j < width * 3 ; j ++ )
  173.      {
  174.       ptr3[ 0 ] = ( ptr2[ 0 ] > ptr1[ 0 ] ) ? ptr2[ 0 ] : ptr1[ 0 ];
  175.  
  176.       ptr1 ++;
  177.       ptr2 ++;
  178.       ptr3 ++;
  179.      }
  180.      ptr1 += remain1;
  181.      ptr2 += remain2;
  182.      ptr3 += remain3;
  183.     }
  184.  
  185.    }
  186.    bit1.UnlockBits( data1 );
  187.    bit2.UnlockBits( data2 );
  188.    bmpresult.UnlockBits( data3 );
  189.    return bmpresult;
  190.   } 
  191.         private void button1_Click(object sender, EventArgs e)
  192.         {
  193.             pictureBox3.Image = Merge(new Bitmap(pictureBox2.Image), new Bitmap(pictureBox1.Image));   
  194.         }
  195.         private void button2_Click(object sender, EventArgs e)
  196.         {
  197.                 pictureBox3.Image.Save("C:\\mypic.jpg");
  198.         }
  199.  
  200.  
  201.  
  202.  }
  203. }
Oct 3 '07 #1
1 1762
debasisdas
8,127 Expert 4TB
Question moved to .NET Forum.
Oct 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
6
by: GJW | last post by:
Does anybody know a simply way I can run a query on a single table and merge the results of several columns of data into a single column of data? IE Table1: First Name Second Name...
3
by: Susan Bricker | last post by:
Greetings. I've been searching for some guidance in how to merge data from a table to a document template in VBA behind an Access Project that I'm working on, but many of the posts assume some...
4
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of...
16
by: UDBDBA | last post by:
Hi All: I need some clarification on a MERGE statement. The database is on V8 FP12 (AIX) 64bit. The source table is tableA. The target is a View "FACT" with UNION ALL because of the 512 Gig...
7
by: giladp1 | last post by:
I found Albert Kallal's great "Super easy Word Merge" code in his site at: http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html Thanks Albert so much for sharing this. I am looking...
5
by: sanamsalehi | last post by:
hello I want to write a code that in the web page I have some frame then user can upload his picture on this page And choose frame to see his photo on these frame(merge her photo with frame) when...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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,...
0
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...

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.