Change background color of an image
-
i want to change the background color of an image in that way that only visible part get new background color, is there any in built function for this ? well, i tried with this but i dont know what to do next
Bitmap bmp = new Bitmap("C:\abc.png");
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color tmp_oldColor = bmp.GetPixel(x, y);
if (tmp_oldColor != Color.Transparent)
{
Color tmp_newColor = ??; // how to get new color ? Multiply, Add ?
tmp_newColor.A = tmp_oldColor.A;
bmp.SetPixel(x, y, tmp_newColor);
}
}
}TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
i want to change the background color of an image in that way that only visible part get new background color, is there any in built function for this ? well, i tried with this but i dont know what to do next
Bitmap bmp = new Bitmap("C:\abc.png");
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color tmp_oldColor = bmp.GetPixel(x, y);
if (tmp_oldColor != Color.Transparent)
{
Color tmp_newColor = ??; // how to get new color ? Multiply, Add ?
tmp_newColor.A = tmp_oldColor.A;
bmp.SetPixel(x, y, tmp_newColor);
}
}
}TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
As you are not using the transparency to determine background color, what do you want the background color to be?
Despite everything, the person most likely to be fooling you next is yourself.
hmmm....my mistake, i wrote "change". The actual thing is that the image is transparent, like vista glass and but have some shapes on it those are tranparent too and i want to set its backcolor, like green, blue or any. That my question.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
i want to change the background color of an image in that way that only visible part get new background color, is there any in built function for this ? well, i tried with this but i dont know what to do next
Bitmap bmp = new Bitmap("C:\abc.png");
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
Color tmp_oldColor = bmp.GetPixel(x, y);
if (tmp_oldColor != Color.Transparent)
{
Color tmp_newColor = ??; // how to get new color ? Multiply, Add ?
tmp_newColor.A = tmp_oldColor.A;
bmp.SetPixel(x, y, tmp_newColor);
}
}
}TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Xmen wrote:
Color tmp_newColor = ??; // how to get new color ? Multiply, Add ?
Color tmp_newColor = Color.Green; or Color.FromArgb(....) or Color.FromName(...) or Color.FromKnownName(...) choose whatever... HTH [Modified] one more thing, you are using GetPixel and SetPixel which are extremely slow. try using LockBits() and UnlockBits() for speed. [/Modified]
regards :)
-
hmmm....my mistake, i wrote "change". The actual thing is that the image is transparent, like vista glass and but have some shapes on it those are tranparent too and i want to set its backcolor, like green, blue or any. That my question.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Ok, create a new bitmap with the same size, create a graphics object for it using Graphics.FromImage, fill the image with the background image using the Clear method and draw your image on it using the DrawImage method.
Despite everything, the person most likely to be fooling you next is yourself.
-
Xmen wrote:
Color tmp_newColor = ??; // how to get new color ? Multiply, Add ?
Color tmp_newColor = Color.Green; or Color.FromArgb(....) or Color.FromName(...) or Color.FromKnownName(...) choose whatever... HTH [Modified] one more thing, you are using GetPixel and SetPixel which are extremely slow. try using LockBits() and UnlockBits() for speed. [/Modified]
regards :)
PandemoniumPasha wrote:
Color tmp_newColor = Color.Green;or Color.FromArgb(....)or Color.FromName(...)or Color.FromKnownName(...)choose whatever...
this is not that simple, i have to calculate the RGB values for new color.
PandemoniumPasha wrote:
one more thing, you are using GetPixel and SetPixel which are extremely slow. try using LockBits() and UnlockBits() for speed.
thanks for the info ;)
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
Ok, create a new bitmap with the same size, create a graphics object for it using Graphics.FromImage, fill the image with the background image using the Clear method and draw your image on it using the DrawImage method.
Despite everything, the person most likely to be fooling you next is yourself.
No, you misunderstood, here is some example :) Transparent Image Added Red Back Color now see the last image, i added color red but i just want color back to the image, not in entire image i can do something nearly, Fill a rectangle with Red color, draw image then use
MakeTransparent(Color.Red)
but it wont do exactly what i want, it will not set alpha. My image wont be transparent anymore. the otherway i can use is : (just wrote directly, not tested)Bitmap bmp = new Bitmap(ofd.FileName); Bitmap bmp\_backColor = new Bitmap(bmp.Width, bmp.Height); for (int x = 0; x < bmp.Width; x++) { for (int y = 0; y < bmp.Height; y++) { Color tmp\_oldColor = bmp.GetPixel(x, y); if (tmp\_oldColor != Color.Transparent) { Color tmp\_newColor = Color.FromArgb(tmp\_oldColor.A, 255, 0, 0); bmp\_backColor.SetPixel(x, y, tmp\_newColor); } } } Graphics m\_gr = Graphics.FromImage(bmp\_backColor); m\_gr.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height); m\_gr.Dispose(); pictureBox1.BackgroundImage = bmp\_backColor;
Is this way right ? Modified : I updated the code with working one, The Working Output My question, is that the only way or is that way good ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
modified on Tuesday, January 27, 2009 4:21 AM