Re: Cropping or extracting ellipse from image
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 12 Apr 2006 20:18:50 +0200
JPEG images only save with 24 bits per pixel. This means no alpha channel
and hence no transparency.
The only way out is to save as GIF which brings up the issue of palette
optimization or as PNG which brings up the issue of compatibility.
Really I find that the small incidence of incompatibility with PNG is
negligable in comparison with the joys of GIF optimization.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
<brett.raven@xxxxxxxxx> wrote in message
news:1144756096.443526.262310@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Bob,
I used your code, which definitely does crop the picture with an
ellipse (thanks again!), however when I save the image as a JPEG, the
background that should be transparent is black.
Here is my code:
pics.Bitmap bm = (pics.Bitmap)pics.Bitmap.FromFile(path +
filename);
pics.Bitmap bt = new pics.Bitmap(bm.Width, bm.Height);
pics.Graphics g = pics.Graphics.FromImage(bt);
GraphicsPath gp=new GraphicsPath();
gp.AddEllipse(10,10,bm.Width-20,bm.Height-20);
g.Clear(pics.Color.Magenta);
g.SetClip(gp);
g.DrawImage(bm,new
pics.Rectangle(0, 0, bm.Width, bm.Height), 0, 0, bm.Width,
bm.Height, pics.GraphicsUnit.Pixel);
g.Dispose();
bt.MakeTransparent(pics.Color.Magenta);
bt.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
-----------------------------
I take this image and merge it with a couple others using the following
code - and it shows up on the image with a black square background ...
-----------------------------
System.Drawing.Graphics myGraphic = null;
pics.Image m = pics.Image.FromFile(imgPath +
"imgBlank.jpg");
myGraphic = System.Drawing.Graphics.FromImage(m); // this
is the blank background
pics.Image imgInvite;
imgInvite = pics.Image.FromFile(imgPath + "frame_pic.jpg");
// this is the frame
pics.Image imgPhoto;
imgPhoto = pics.Image.FromFile(imgSelectedPhoto); // this
is the user photo
myGraphic.DrawImage(imgInvite, 0, 0, 500, 311);
myGraphic.DrawImage(imgPhoto, 20, 20, 100, 100);
myGraphic.Save();
m.Save(mergedFileName,
System.Drawing.Imaging.ImageFormat.Jpeg);
It just seems like the transparency isn't working. Is this a problem
for Jpegs via GDI?
Cheers and thanks again.
Brett
.
- References:
- Cropping or extracting ellipse from image
- From: brett . raven
- Re: Cropping or extracting ellipse from image
- From: Bob Powell [MVP]
- Re: Cropping or extracting ellipse from image
- From: brett . raven
- Re: Cropping or extracting ellipse from image
- From: Bob Powell [MVP]
- Re: Cropping or extracting ellipse from image
- From: brett . raven
- Re: Cropping or extracting ellipse from image
- From: brett . raven
- Cropping or extracting ellipse from image
- Prev by Date: Re: Drawing in picturebox
- Next by Date: Re: Filled polygons print to PDF as opaque
- Previous by thread: Re: Cropping or extracting ellipse from image
- Next by thread: Convert unsafe code to safe, how to convert pointers to regular GDI+ methods?
- Index(es):
Relevant Pages
|
Loading