Laden...

Farbe tauschen funzt nicht!

Erstellt von TheBrainiac vor 17 Jahren Letzter Beitrag vor 17 Jahren 2.531 Views
TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 17 Jahren
Farbe tauschen funzt nicht!

Hallo, Community!

Habe folgenden Code:


private Image ReplaceColor(Image img, Color clr)
        {
            Bitmap bmp = new Bitmap(img);
            Color pxl1 = bmp.GetPixel(0, 0);
            
            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; i < 16; j++)
                {                    
                    if (bmp.GetPixel(i, j) != pxl1)
                    {
                        bmp.SetPixel(i, j, clr);
                    }
                }
            }
            
            return bmp;
        }

Das Image, das ich übergebe ist immer 16x16, 256 Farben.

Aber bei der If-Abfrage schmeisst er mir ne Exception:

System.ArgumentOutOfRangeException was unhandled
  Message="Der Parameter muss positiv und kleiner als die Höhe sein.\r\nParametername: y"
  Source="System.Drawing"
  ParamName="y"
  StackTrace:
       bei System.Drawing.Bitmap.GetPixel(Int32 x, Int32 y)
       bei Cashier_Tablet_PC.Dialog.ReplaceColor(Image img, Color clr) in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\Dialog.cs:Zeile 187.
       bei Cashier_Tablet_PC.Dialog..ctor(String Caption, String Text, MessageBoxButtons buttons, DialogColor color) in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\Dialog.cs:Zeile 112.
       bei Cashier_Tablet_PC.Dialog.Show(String Caption, String Text, MessageBoxButtons buttons, DialogColor color) in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\Dialog.cs:Zeile 295.
       bei Cashier_Tablet_PC.MainForm.button1_Click(Object sender, EventArgs e) in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\MainForm.cs:Zeile 127.
       bei Cashier_Tablet_PC.Button.lblCaption_Click(Object sender, EventArgs e) in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\Button.cs:Zeile 116.
       bei System.Windows.Forms.Control.OnClick(EventArgs e)
       bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       bei System.Windows.Forms.Control.WndProc(Message& m)
       bei System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       bei System.Windows.Forms.Application.Run(Form mainForm)
       bei Cashier_Tablet_PC.Program.Main() in D:\Development\C#\Projects\Cashier Tablet PC\Cashier Tablet PC\Program.cs:Zeile 17.
       bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()

Hab keinen Plan, was ich machen soll, kann mir jemand helfen?

Danke schon mal,
Gruß, Christian.

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`
738 Beiträge seit 2007
vor 17 Jahren

in der inneren for-schleife steht noch einmal i statt j

blödes CopyPaste
🙂

TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 17 Jahren

lol, das hätte ich eigtl. selbst sehen müssen.
Tja, kommt davon, wenn man schon zu lange vorm PC hockt.

Danke!

[Edit]
PS: War gar kein Copy&Paste, sondern das Snippet von MS VS 05 🤔
[/Edit]

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`
B
1.529 Beiträge seit 2006
vor 17 Jahren

Benutze bmp.Width und bmp.Height anstelle der Konstanten 16 sowie Spalte und Zeile oder x und y anstelle von i und j und diese und ähnliche Fehler werden ausgeschlossen oder erschwert...

PS.: Man nenne mir einen Satz mit fünf "und"!
Malt der Malergeselle ein Schild für den Obst und Gemüse Laden und zeigt es zur Abnahme dem Meister. Dessen Kommentar: "Schon nicht übel, aber zwischen Obst und und und und und Gemüse musst du noch mehr Platz lassen!"

871 Beiträge seit 2005
vor 17 Jahren

Hallo,

... und falls das ganze mal zu langsam werden sollte (weil sich z.B. die grösse des Images ändert) dann weise ich mal gleich vorab auf LockBits hin.

Grüsse, Egon

TheBrainiac Themenstarter:in
795 Beiträge seit 2006
vor 17 Jahren

danke, werd ich gleich mal ausprobieren

`There are 10 types of people in the world: Those, who think they understand the binary system Those who don't even have heard about it And those who understand "Every base is base 10"`