Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Word Interop - Insert Image into a specific cell in a table located in the document header Pin
AshokNaik10-Jul-11 21:45
AshokNaik10-Jul-11 21:45 
QuestionRe: C# Word Interop - Insert Image into a specific cell in a table located in the document header Pin
Member 110410579-Mar-15 0:50
Member 110410579-Mar-15 0:50 
QuestionImage position in other image c# ? [modified] Pin
sodevrom19-Sep-09 12:29
sodevrom19-Sep-09 12:29 
AnswerRe: Image position in other image c# ? Pin
Dave Kreskowiak19-Sep-09 14:01
mveDave Kreskowiak19-Sep-09 14:01 
GeneralRe: Image position in other image c# ? Pin
sodevrom19-Sep-09 14:06
sodevrom19-Sep-09 14:06 
GeneralRe: Image position in other image c# ? Pin
Dave Kreskowiak19-Sep-09 14:13
mveDave Kreskowiak19-Sep-09 14:13 
GeneralRe: Image position in other image c# ? Pin
Alan Balkany21-Sep-09 10:12
Alan Balkany21-Sep-09 10:12 
AnswerRe: Image position in other image c# ? Pin
Albond22-May-10 10:27
Albond22-May-10 10:27 
Here's my method. Maybe someone need. Works quickly.

Point IndexOfImage(Bitmap bmp1, Bitmap bmp2)
        {
            Point retP = new Point(-1, -1);

            int bw = bmp1.Width;
            int bh = bmp1.Height;
            int bw2 = bmp2.Width;
            int bh2 = bmp2.Height;
            if ((bw < bw2) || (bh < bh2)) return retP;


            //------------------------------------

            Bitmap bmp = new Bitmap(bw2, bh2);

            Rectangle rect = new Rectangle(0, 0, bmp1.Width, bmp1.Height);
            System.Drawing.Imaging.BitmapData bmpData = bmp1.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            IntPtr ptr = bmpData.Scan0;

            int bytes = bmpData.Stride * bmp1.Height;

            byte[] rgbValues = new byte[bytes];

            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

            //------------------------------------

            Rectangle rect2 = new Rectangle(0, 0, bmp2.Width, bmp2.Height);
            System.Drawing.Imaging.BitmapData bmpData2 = bmp2.LockBits(rect2, System.Drawing.Imaging.ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            IntPtr ptr2 = bmpData2.Scan0;

            int bytes2 = bmpData2.Stride * bmp2.Height;

            int bm = bytes2;
            byte[] rgbValues2 = new byte[bytes2];

            System.Runtime.InteropServices.Marshal.Copy(ptr2, rgbValues2, 0, bytes2);

            //------------------------------------

            int i = -1, j = 0, i2 = -1, j2 = 0, ind_f = 0;
            int f = 0;
            int realx, realx2;
            i = -1;
            j = 0;

            for (int y = 0; y < bh - bh2 + 1; y++)
            {
                j = 0;
                realx = 0;
                for (int x = 0; x < bw * 3 - bw2 * 3; x++)
                {
                    i++;
                    j++;
                    if (j == 4)
                    {
                        j = 1;
                        realx++;
                    }
                    if (j == 1)
                    {
                        bm = 0;
                        i2 = -1;
                        j2 = 0;
                        int y2 = 0;
                        realx2 = 0;
                        f = 0;
                        while (y2 < bh2)
                        {
                            i2++;
                            j2++;
                            if (j2 == 4)
                            {
                                j2 = 1;
                                realx2++;
                            }
                            if (realx2 == bw2)
                            {
                                realx2 = 0;
                                i2 += bmpData2.Stride - bw2*3;
                                y2++;
                            }
                            if (y2 == bh2) break;
                            if (j2 == 1)
                            {
                                if ((rgbValues[i + (realx2 * 3) + (bmpData.Stride * y2)] == rgbValues2[i2]) && (rgbValues[i + (realx2 * 3) + (bmpData.Stride * y2) + 1] == rgbValues2[i2 + 1]) && (rgbValues[i + (realx2 * 3) + (bmpData.Stride * y2) + 1] == rgbValues2[i2 + 1]))
                                {
                                    f++;
                                }
                                else
                                    break;
                            }
                            bm++;
                        }
                        if (f == bh2 * bw2)
                        {
                            retP = new Point(realx, y);
                            return retP;
                        }
                    }
                }
                i += bmpData.Stride - bw * 3 + bw2 * 3;
            }

            System.Runtime.InteropServices.Marshal.Copy(rgbValues2, 0, ptr2, bytes2);
            bmp2.UnlockBits(bmpData2);
            System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);
            bmp1.UnlockBits(bmpData);

            return retP;
        }

QuestionHow to monitor key pressed? Pin
p3rson19-Sep-09 11:06
p3rson19-Sep-09 11:06 
AnswerRe: How to monitor key pressed? Pin
Christian Graus19-Sep-09 11:19
protectorChristian Graus19-Sep-09 11:19 
GeneralRe: How to monitor key pressed? Pin
p3rson19-Sep-09 11:40
p3rson19-Sep-09 11:40 
GeneralRe: How to monitor key pressed? Pin
Christian Graus19-Sep-09 11:45
protectorChristian Graus19-Sep-09 11:45 
QuestionMouting Drive through Serial Communication Pin
Paul Krueger19-Sep-09 10:49
Paul Krueger19-Sep-09 10:49 
AnswerRe: Mouting Drive through Serial Communication Pin
Luc Pattyn19-Sep-09 10:59
sitebuilderLuc Pattyn19-Sep-09 10:59 
GeneralRe: Mouting Drive through Serial Communication Pin
Sindicoro19-Sep-09 20:36
Sindicoro19-Sep-09 20:36 
GeneralRe: Mouting Drive through Serial Communication Pin
Luc Pattyn20-Sep-09 2:29
sitebuilderLuc Pattyn20-Sep-09 2:29 
JokeRe: Mouting Drive through Serial Communication Pin
Sindicoro20-Sep-09 7:50
Sindicoro20-Sep-09 7:50 
AnswerRe: Mouting Drive through Serial Communication Pin
Sindicoro19-Sep-09 20:34
Sindicoro19-Sep-09 20:34 
QuestionC# question regarding controls (textbox) and events Pin
gjx_junxian198919-Sep-09 7:20
gjx_junxian198919-Sep-09 7:20 
AnswerRe: C# question regarding controls (textbox) and events Pin
Richard MacCutchan19-Sep-09 7:32
mveRichard MacCutchan19-Sep-09 7:32 
QuestionConfigure Data Source Pin
AndreFratelli19-Sep-09 6:54
AndreFratelli19-Sep-09 6:54 
AnswerRe: Configure Data Source Pin
AndreFratelli19-Sep-09 8:36
AndreFratelli19-Sep-09 8:36 
QuestionPolyline or curved progress bar Pin
LinCorJDE19-Sep-09 6:47
LinCorJDE19-Sep-09 6:47 
AnswerRe: Polyline or curved progress bar Pin
dan!sh 19-Sep-09 7:40
professional dan!sh 19-Sep-09 7:40 
AnswerRe: Polyline or curved progress bar Pin
Henry Minute19-Sep-09 7:46
Henry Minute19-Sep-09 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.