By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Graphics Question

P: n/a
I am trying to simply embed a opaque image over another image...

if i use a windows form it works..

e.g.

Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
Bitmap bitmap = new Bitmap(@"d:\\club_home_page_feature.jpg");

float[][] ptsArray ={

new float[] {1, 0, 0, 0, 0},

new float[] {0, 1, 0, 0, 0},

new float[] {0, 0, 1, 0, 0},

new float[] {0, 0, 0, 0.5f, 0},

new float[] {0, 0, 0, 0, 1}};

Rectangle rect = new Rectangle(0,0,bitmap.Width,bitmap.Height);

//Rectangle rect = new Rectangle20, 20, 200, 100);

ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
ImageAttributes imgAttributes = new ImageAttributes();

imgAttributes.SetColorMatrix(clrMatrix,

ColorMatrixFlag.Default,

ColorAdjustType.Bitmap);

g.FillRectangle(Brushes.Black, rect);

g.DrawImage(bitmap,

new Rectangle(0, 0, bitmap.Width, bitmap.Height),

0, 0, bitmap.Width, bitmap.Height,

GraphicsUnit.Pixel, imgAttributes);

g.Dispose();

however how can i then save this newly createed image to the files sytem?
Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Darren Clark wrote:
however how can i then save this newly createed image to the files sytem?


I guess you should first create an image that holds all the combined
information:

Bitmap bitmap = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bitmap);

// now draw whatever you want into g
// you can also save the bitmap however you want

// Last, get the Graphics for your picture box and copy the
// complete image there

Graphics pictureBoxGraphics = pictureBox1.CreateGraphics();
pictureBoxGraphics.DrawImage(bitmap, 0, 0);
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2

P: n/a
Ski
to save it as a jpeg do something like this

EncoderParameters encoderParams = new EncoderParameters();
long[] quality = new long[1];
quality[0] = 90;
EncoderParameter encoderParam = new EncoderParameter(Encoder.Quality,
quality);
encoderParams.Param[0] = encoderParam;

ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo jpegICI = null;
for (int x = 0; x < arrayICI.Length; x++)
{
if (arrayICI[x].FormatDescription.Equals("JPEG"))
{
jpegICI = arrayICI[x];
break;
}
}

if (jpegICI != null)
{
bm.Save(sOutputFilename, jpegICI, encoderParams);
}

bm is the bitmap you have drawn on.

hth
Scott

Darren Clark wrote:
I am trying to simply embed a opaque image over another image...

if i use a windows form it works..

e.g.

Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
Bitmap bitmap = new Bitmap(@"d:\\club_home_page_feature.jpg");

float[][] ptsArray ={

new float[] {1, 0, 0, 0, 0},

new float[] {0, 1, 0, 0, 0},

new float[] {0, 0, 1, 0, 0},

new float[] {0, 0, 0, 0.5f, 0},

new float[] {0, 0, 0, 0, 1}};

Rectangle rect = new Rectangle(0,0,bitmap.Width,bitmap.Height);

//Rectangle rect = new Rectangle20, 20, 200, 100);

ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
ImageAttributes imgAttributes = new ImageAttributes();

imgAttributes.SetColorMatrix(clrMatrix,

ColorMatrixFlag.Default,

ColorAdjustType.Bitmap);

g.FillRectangle(Brushes.Black, rect);

g.DrawImage(bitmap,

new Rectangle(0, 0, bitmap.Width, bitmap.Height),

0, 0, bitmap.Width, bitmap.Height,

GraphicsUnit.Pixel, imgAttributes);

g.Dispose();

however how can i then save this newly createed image to the files sytem?

Nov 17 '05 #3

P: n/a
Whenever it saves to a file it save as a black image?
Any ideas?

Bitmap bitmap = new Bitmap(@"d:\\club_home_page_feature.jpg");

Bitmap nImage = new Bitmap(bitmap,200,200);

Graphics g = Graphics.FromImage(nImage);

float[][] ptsArray ={

new float[] {1, 0, 0, 0, 0},

new float[] {0, 1, 0, 0, 0},

new float[] {0, 0, 1, 0, 0},

new float[] {0, 0, 0, 0.5f, 0},

new float[] {0, 0, 0, 0, 1}};

Rectangle rect = new Rectangle(0,0,bitmap.Width,bitmap.Height);

//Rectangle rect = new Rectangle20, 20, 200, 100);

nImage.Save("d:\\1.jpg");

ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
ImageAttributes imgAttributes = new ImageAttributes();

imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);

g.FillRectangle(Brushes.Black, rect);

g.DrawImage(nImage, new Rectangle(0, 0, bitmap.Width, bitmap.Height),

0, 0, bitmap.Width, bitmap.Height,

GraphicsUnit.Pixel, imgAttributes);

nImage.Save("d:\\2.jpg");

g.Dispose();

nImage.Save("d:\\3.jpg");

Graphics pictureBoxGraphics = this.pictureBox1.CreateGraphics();

pictureBoxGraphics.DrawImage(nImage, 0, 0);

"Oliver Sturm" <ol****@sturmnet.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Darren Clark wrote:
however how can i then save this newly createed image to the files
sytem?
I guess you should first create an image that holds all the combined
information:

Bitmap bitmap = new Bitmap(100, 100);
Graphics g = Graphics.FromImage(bitmap);

// now draw whatever you want into g
// you can also save the bitmap however you want

// Last, get the Graphics for your picture box and copy the
// complete image there

Graphics pictureBoxGraphics = pictureBox1.CreateGraphics();
pictureBoxGraphics.DrawImage(bitmap, 0, 0);
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog

Nov 17 '05 #4

P: n/a
Darren Clark wrote:
Whenever it saves to a file it save as a black image?
Any ideas?
I haven't tried your code, but I found that you seem to have a few
things mangled up a bit. Maybe it has to do with that. See below.
Bitmap bitmap = new Bitmap(@"d:\\club_home_page_feature.jpg");

Bitmap nImage = new Bitmap(bitmap,200,200);

Graphics g = Graphics.FromImage(nImage);

float[][] ptsArray ={

new float[] {1, 0, 0, 0, 0},

new float[] {0, 1, 0, 0, 0},

new float[] {0, 0, 1, 0, 0},

new float[] {0, 0, 0, 0.5f, 0},

new float[] {0, 0, 0, 0, 1}};

Rectangle rect = new Rectangle(0,0,bitmap.Width,bitmap.Height);

//Rectangle rect = new Rectangle20, 20, 200, 100);

nImage.Save("d:\\1.jpg");
At a glance, I would expect that this saved image shouldn't be black? Is it?
ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
ImageAttributes imgAttributes = new ImageAttributes();

imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);

g.FillRectangle(Brushes.Black, rect);
Now here you fill the complete nImage with black, don't you?
g.DrawImage(nImage, new Rectangle(0, 0, bitmap.Width, bitmap.Height),

0, 0, bitmap.Width, bitmap.Height,

GraphicsUnit.Pixel, imgAttributes);

Now you draw the image nImage on its own canvas (which is g, remember),
using a rectangle with the height and width of the original loaded
image? I can't imagine the result of that, but I suppose it would still
be black, regardless of the attributes you pass in.
nImage.Save("d:\\2.jpg");
Black, I guess.
g.Dispose();

nImage.Save("d:\\3.jpg");
Black, still.
Graphics pictureBoxGraphics = this.pictureBox1.CreateGraphics();

pictureBoxGraphics.DrawImage(nImage, 0, 0);


Black, sure.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.