Benutzer mit den meisten Antworten
Image einfärben

Frage
Antworten
-
Hi,
das funktioniert sicher:
public partial class Form1 : Form { private PictureBox pictureBox1; public Form1() { this.InitializeComponent(); this.pictureBox1 = new PictureBox(); this.Controls.Add(this.pictureBox1); } private void button1_Click(object sender, EventArgs e) { Image bild = new Bitmap(@"C:\Users\Holger\Pictures\soKompliertEsSichSehrFlott.png"); this.pictureBox1.Width = bild.Width; this.pictureBox1.Height = bild.Height; this.pictureBox1.Image = bild; Form1.ChangeBackColor(bild, Color.FromArgb(128,255,0,0)); this.pictureBox1.Invalidate(); this.pictureBox1.Update(); } public static Image ChangeBackColor(Image source, Color backcolor) { Image bitmapImage = new Bitmap(source.Width, source.Height); using(Graphics objGfx = Graphics.FromImage(source)) { objGfx.FillRectangle(new SolidBrush(backcolor), 0, 0, source.Width, source.Height); objGfx.DrawImage(source, 0,0); } return bitmapImage; } }
Viele Grüße
Holger M. Rößler
Kaum macht man es richtig, schon funktioniert es- Als Antwort vorgeschlagen Holger M. Rößler Montag, 28. November 2011 20:04
- Als Antwort markiert majoba-it Dienstag, 29. November 2011 12:19
Alle Antworten
-
Hi,
du hast die Frage sehr generell gestellt und daher ist sie auch nur sehr generell zu Beantworten. Ein speziellerer Ansatzpunkt könnte den Beantwortern das Leben erleichtern. Meinstes du sowas in der Art?
public static Image ChangeBackColor(Image Source, Color Back) { Image bitmapImage = new Bitmap(Source.Width, Source.Height); using (Graphics objGfx = System.Drawing.Graphics.FromImage(bitmapImage)) { objGfx.FillRectangle(new SolidBrush(Back), 0, 0, Source.Width, Source.Height); objGfx.DrawImage(Source, 0, 0); } return bitmapImage; }
Wenn es das nicht ist was du brauchst, dann Frage bitte genauer nachdem, was du brauchst! ;-)
Viele Grüße
Holger M. Rößler
Kaum macht man es richtig, schon funktioniert es- Bearbeitet Holger M. Rößler Sonntag, 27. November 2011 23:02
- Als Antwort vorgeschlagen Oliver Michalski Montag, 28. November 2011 09:15
-
Ich habe das Bild in einer Variablen gespeichert, und möchte dießes einfärben:
Image bild;
Color farbe;
farbe = new Color(200,130,130,255); (Beispielwerte)
bild = Properties.Ressources.MeinBild;
Hier muss bild mit der farbe eingefärbt werden.
Picturebox1.Image = bild;
majoba-it- Bearbeitet majoba-it Montag, 28. November 2011 13:11
-
Es funktioniert leider nicht!
Hier der Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = ChangeBackColor(Properties.Resources.Neue_Bitmap, Color.FromArgb(255,0,255,0));
}
public static Image ChangeBackColor(Image Source, Color Back)
{
Image bitmapImage = new Bitmap(Source.Width, Source.Height);
using (Graphics objGfx = System.Drawing.Graphics.FromImage(bitmapImage))
{
objGfx.FillRectangle(new SolidBrush(Back), 0, 0, Source.Width, Source.Height);
objGfx.DrawImage(Source, 0, 0);
}
return bitmapImage;
}
}
}
majoba-it -
Hi,
das funktioniert sicher:
public partial class Form1 : Form { private PictureBox pictureBox1; public Form1() { this.InitializeComponent(); this.pictureBox1 = new PictureBox(); this.Controls.Add(this.pictureBox1); } private void button1_Click(object sender, EventArgs e) { Image bild = new Bitmap(@"C:\Users\Holger\Pictures\soKompliertEsSichSehrFlott.png"); this.pictureBox1.Width = bild.Width; this.pictureBox1.Height = bild.Height; this.pictureBox1.Image = bild; Form1.ChangeBackColor(bild, Color.FromArgb(128,255,0,0)); this.pictureBox1.Invalidate(); this.pictureBox1.Update(); } public static Image ChangeBackColor(Image source, Color backcolor) { Image bitmapImage = new Bitmap(source.Width, source.Height); using(Graphics objGfx = Graphics.FromImage(source)) { objGfx.FillRectangle(new SolidBrush(backcolor), 0, 0, source.Width, source.Height); objGfx.DrawImage(source, 0,0); } return bitmapImage; } }
Viele Grüße
Holger M. Rößler
Kaum macht man es richtig, schon funktioniert es- Als Antwort vorgeschlagen Holger M. Rößler Montag, 28. November 2011 20:04
- Als Antwort markiert majoba-it Dienstag, 29. November 2011 12:19