本文整理汇总了C#中System.Drawing.Bitmap.MakeTransparent方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.MakeTransparent方法的具体用法?C# System.Drawing.Bitmap.MakeTransparent怎么用?C# System.Drawing.Bitmap.MakeTransparent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.MakeTransparent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PanRight
public PanRight()
{
string[] res = GetType().Assembly.GetManifestResourceNames();
if(res.GetLength(0) > 0)
{
m_bitmap = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(GetType(), "PanRight.bmp"));
if(m_bitmap != null)
{
m_bitmap.MakeTransparent(m_bitmap.GetPixel(1,1));
m_hBitmap = m_bitmap.GetHbitmap();
}
}
m_pHookHelper = new HookHelperClass ();
}
示例2: png2img
bool png2img(string inputFileName, string outputFileName) {
tempFilesDeleter.AddFile(outputFileName);
System.Drawing.Imaging.ImageFormat format;
var extension = Path.GetExtension(outputFileName).ToLower();
switch (extension) {
case ".png":
format = System.Drawing.Imaging.ImageFormat.Png;
break;
case ".jpg":
case ".jpeg":
format = System.Drawing.Imaging.ImageFormat.Jpeg;
break;
case ".gif":
format = System.Drawing.Imaging.ImageFormat.Gif;
break;
case ".tif":
case ".tiff":
format = System.Drawing.Imaging.ImageFormat.Tiff;
break;
case ".bmp":
default:
format = System.Drawing.Imaging.ImageFormat.Bmp;
break;
}
if (controller_ != null) controller_.appendOutput("TeX2img: Convert " + inputFileName + " to " + outputFileName + "\n");
try {
using (var bitmap = new System.Drawing.Bitmap(Path.Combine(workingDir, inputFileName))) {
if (Properties.Settings.Default.transparentPngFlag && extension != ".gif") {
bitmap.MakeTransparent();
}
bitmap.Save(Path.Combine(workingDir, outputFileName), format);
}
return true;
}
catch (FileNotFoundException) { return false; }
catch (UnauthorizedAccessException) { return false; }
}
示例3: btnUpload_Click
protected void btnUpload_Click(object sender, EventArgs e)
{
if(flUploadReplace.HasFile) {
try {
Extension = flUploadReplace.FileName.Substring(flUpload.FileName.LastIndexOf(".") + 1);
Extension = "png";
var fileName = (Server.MapPath(Folder) + FileName + "." + Extension);
//flUpload.SaveAs(fileName);
lblUplderr.Text = "<br>File size: " +
flUploadReplace.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
flUploadReplace.PostedFile.ContentType;
var upImage = System.Drawing.Image.FromStream(flUploadReplace.PostedFile.InputStream);
// Get height and width of current image
int currWidth = (int)upImage.Width;
int currHeight = (int)upImage.Height;
Int32 newWidth = ImgWidth;
float ratio = 0;
Int32 newHeight = 0;
ratio = (float)currWidth / (float)newWidth;
newHeight = (int)(currHeight / ratio);
var newBmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
newBmp.SetResolution(72, 72);
newBmp.MakeTransparent();
var newGraphic = System.Drawing.Graphics.FromImage(newBmp);
//newGraphic.Clear(Color.DarkRed);\
newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newGraphic.DrawImage(upImage, 0, 0, newWidth, newHeight);
newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
newBmp.Dispose();
newGraphic.Dispose();
if(CreateSmallThumbnail) {
fileName = Server.MapPath(Folder) + "\\" + SmallThumbnailPrefix + FileName + "." + Extension;
newWidth = SmallThumbnailWidth;
ratio = (float)currWidth / (float)newWidth;
newHeight = (int)(currHeight / ratio);
newBmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
newBmp.SetResolution(72, 72);
newBmp.MakeTransparent();
newGraphic = System.Drawing.Graphics.FromImage(newBmp);
//newGraphic.Clear(Color.DarkRed);
newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newGraphic.DrawImage(upImage, 0, 0, newWidth, newHeight);
newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
newBmp.Dispose();
newGraphic.Dispose();
}
if(CreateMediumThumbnail) {
fileName = Server.MapPath(Folder) + "\\" + MediumThumbnailPrefix + FileName + "." + Extension;
newWidth = MediumThumbnailWidth;
ratio = (float)currWidth / (float)newWidth;
newHeight = (int)(currHeight / ratio);
newBmp = new System.Drawing.Bitmap(newWidth, newHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
newBmp.SetResolution(72, 72);
newBmp.MakeTransparent();
newGraphic = System.Drawing.Graphics.FromImage(newBmp);
//newGraphic.Clear(Color.DarkRed);
newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newGraphic.DrawImage(upImage, 0, 0, newWidth, newHeight);
newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
newBmp.Dispose();
newGraphic.Dispose();
}
upImage.Dispose();
// resize
// thumb
// medium
ProcessRender();
} catch(Exception ex) {
lblUplderr1.Text = "<br><font color=red>ERROR: " + ex.Message.ToString() + "</font>";
}
} else {
lblUplderr1.Text = "<br><font color=red>ERROR: You have not specified a file.</font>";
}
}
示例4: GetStyle
public SharpMap.Styles.IStyle GetStyle(SharpMap.Data.FeatureDataRow fdr)
{
var retval = new SharpMap.Styles.VectorStyle();
if (fdr["Bearing"] == DBNull.Value)
{
var bmp = new System.Drawing.Bitmap(36, 36);
using (var g = System.Drawing.Graphics.FromImage(bmp))
{
g.Clear(System.Drawing.Color.Wheat);
g.FillEllipse(System.Drawing.Brushes.Green, 0, 0, 36, 36);
g.DrawEllipse(new System.Drawing.Pen(System.Drawing.Brushes.Yellow, 3), 4, 4, 28, 28);
g.DrawString("H", new System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold),
System.Drawing.Brushes.Yellow,
new System.Drawing.RectangleF(2, 2, 34, 34),
new System.Drawing.StringFormat
{
Alignment = System.Drawing.StringAlignment.Center,
LineAlignment = System.Drawing.StringAlignment.Center
});
}
bmp.MakeTransparent(System.Drawing.Color.Wheat);
retval.Symbol = bmp;
}
else
{
retval.Symbol = ColoredArrow(_brush);
var rot = (Single)(Double)fdr["Bearing"];
retval.SymbolRotation = rot % 360f;
}
return retval;
}
示例5: ColoredArrow
private static System.Drawing.Image ColoredArrow(System.Drawing.Brush c)
{
var bmp = new System.Drawing.Bitmap(13, 36);
using (var g = System.Drawing.Graphics.FromImage(bmp))
{
g.Clear(System.Drawing.Color.Wheat);
g.FillPolygon(c, ArrowPoints);
g.DrawPolygon(System.Drawing.Pens.Black, ArrowPoints);
}
bmp.MakeTransparent(System.Drawing.Color.Wheat);
return bmp;
}
示例6: LoadImages
private void LoadImages()
{
string bmpPanName = "WpfChart.Resources.Breakpoint.bmp";
System.IO.Stream strm = null;
try
{
strm = this.GetType().Assembly.GetManifestResourceStream(bmpPanName);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(strm);
bitmap.MakeTransparent();
IntPtr h_bm = bitmap.GetHbitmap();
BitmapSource bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(h_bm, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
panCursor = bms;
}
catch (Exception)
{
//Do nothing
}
}
示例7: RandomSymbol
private byte[] RandomSymbol(int number)
{
number = number%360;
string text ="";
System.Drawing.Brush brush = null;
if (number < 60)
return null;
if (number < 120)
{
text = "<120";
brush = System.Drawing.Brushes.DarkGreen;
}
else if(number < 240)
{
text = number.ToString();
brush = System.Drawing.Brushes.Orange;
}
else
{
text = ">240";
brush = System.Drawing.Brushes.Red;
}
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(120, 60);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
System.Drawing.RectangleF size = new System.Drawing.RectangleF(0f, 0f, 120f, 60f);
g.FillRectangle(System.Drawing.Brushes.White, size);
var sf = new System.Drawing.StringFormat(System.Drawing.StringFormatFlags.NoWrap)
{Alignment = System.Drawing.StringAlignment.Center};
g.DrawString(text, new System.Drawing.Font("Arial", 24), brush, size, sf);
g.Flush();
g.Dispose();
var ms = new System.IO.MemoryStream();
bmp.MakeTransparent(System.Drawing.Color.White);
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
示例8: HandleUpload
private void HandleUpload(FileUpload fileControl)
{
if (fileControl.HasFile)
{
try
{
Extension = fileControl.FileName.Substring(fileControl.FileName.LastIndexOf(".") + 1);
Extension = "png";
var fileName = (Server.MapPath(Folder) + FileName + "." + Extension);
lblUplderr.Text = "<br>File size: " +
fileControl.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
fileControl.PostedFile.ContentType;
using (var upImage = System.Drawing.Image.FromStream(fileControl.PostedFile.InputStream))
{
// Get height and width of current image
int currWidth = (int)upImage.Width;
int currHeight = (int)upImage.Height;
Int32 newWidth = ImgWidth;
float ratio = 0;
Int32 newHeight = 0;
ratio = (float)currWidth / (float)newWidth;
newHeight = (int)(currHeight / ratio);
using (var newBmp = new System.Drawing.Bitmap(newWidth,
newHeight,
System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
newBmp.SetResolution(72, 72);
newBmp.MakeTransparent();
using (var newGraphic = System.Drawing.Graphics.FromImage(newBmp))
{
newGraphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
newGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
newGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
newGraphic.DrawImage(upImage, 0, 0, newWidth, newHeight);
newBmp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
if (CreateSmallThumbnail)
{
string thumbName = string.Format("{0}\\{1}{2}.{3}",
Server.MapPath(Folder),
SmallThumbnailPrefix,
FileName,
Extension);
CreateSquareImage(upImage, thumbName, SmallThumbnailWidth);
}
if (CreateMediumThumbnail)
{
string thumbName = string.Format("{0}\\{1}{2}.{3}",
Server.MapPath(Folder),
MediumThumbnailPrefix,
FileName,
Extension);
CreateSquareImage(upImage, thumbName, MediumThumbnailWidth);
}
}
ProcessRender();
}
catch (Exception ex)
{
lblUplderr.Text = "<br><font color=red>ERROR: " + ex.Message.ToString() + "</font>";
}
}
else {
lblUplderr.Text = "<br><font color=red>ERROR: You have not specified a file.</font>";
}
}
示例9: Form1_Load
private void Form1_Load(object sender, System.EventArgs e)
{
//Load option/command button images
System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "ZoomIn.bmp"));
bitmap1.MakeTransparent(System.Drawing.Color.Teal);
optTool0.Image = bitmap1;
System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "ZoomOut.bmp"));
bitmap2.MakeTransparent(System.Drawing.Color.Teal);
optTool1.Image = bitmap2;
System.Drawing.Bitmap bitmap3 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "Pan.bmp"));
bitmap3.MakeTransparent(System.Drawing.Color.Teal);
optTool2.Image = bitmap3;
System.Drawing.Bitmap bitmap4 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "FullExtent.bmp"));
bitmap4.MakeTransparent(System.Drawing.Color.Teal);
cmdFullExtent.Image = bitmap4;
System.Drawing.Bitmap bitmap5 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "UnDoDraw.bmp"));
bitmap5.MakeTransparent(System.Drawing.Color.Teal);
cmdUndo.Image = bitmap5;
System.Drawing.Bitmap bitmap6 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "ReDoDraw.bmp"));
bitmap6.MakeTransparent(System.Drawing.Color.Teal);
cmdRedo.Image = bitmap6;
//Disable controls
optTool0.Enabled = false;
optTool1.Enabled = false;
optTool2.Enabled = false;
cmdUndo.Enabled = false;
cmdRedo.Enabled = false;
cmdFullExtent.Enabled = false;
}
示例10: SaveQrCodeImage
private static void SaveQrCodeImage(Image image, string fileName)
{
Debug.Assert(image as Bitmap != null, "image as Bitmap != null");
using (var memoryStream = new MemoryStream((image as Bitmap).ToByteArray(ImageFormat.Png))) {
using (var bitmap = new System.Drawing.Bitmap(memoryStream)) {
bitmap.MakeTransparent(System.Drawing.Color.White);
using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096)) {
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
}
示例11: LoadDefaultImages
/// <summary>
/// Load default images for device tree.
/// </summary>
/// <param name="Images"></param>
void LoadDefaultImages(ImageList.ImageCollection Images)
{
System.Drawing.Bitmap bm = null;
//Load device categories image
System.IO.Stream stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceCategories.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
//Load device category image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceCategory.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent(System.Drawing.Color.FromArgb(255, 0, 255));
Images.Add(bm);
}
//Load device tables image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceTables.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
//Load device table image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceTable.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
//Load device properties image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceProperties.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
//Load device property image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DeviceProperty.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
//Load None image
stream = this.GetType().Assembly.GetManifestResourceStream("DLMS.Resources.DatabaseNone.bmp");
if (stream != null)
{
bm = new System.Drawing.Bitmap(stream);
bm.MakeTransparent();
Images.Add(bm);
}
}
示例12: CreateCursor
public static Cursor CreateCursor(UIElement element, int xHotSpot, int yHotSpot,bool isTransparent)
{
try
{
element.Measure(new Size(double.PositiveInfinity,
double.PositiveInfinity));
element.Arrange(new Rect(0, 0, element.DesiredSize.Width,
element.DesiredSize.Height));
RenderTargetBitmap rtb =
new RenderTargetBitmap((int)element.DesiredSize.Width,
(int)element.DesiredSize.Height, 96, 96,
PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
if (isTransparent)
{
System.Drawing.Color backColor = bmp.GetPixel(1, 1);
bmp.MakeTransparent(backColor);
}
Cursor cur = InternalCreateCursor(bmp, xHotSpot, yHotSpot);
ms.Close();
ms.Dispose();
//VictorDEBUG
bmp.Dispose();
return cur;
}
catch
{
}
return null;
}
示例13: CreateTransparentElement
public static BitmapSource CreateTransparentElement(UIElement element)
{
BitmapSource retBitmap = null;
RenderTargetBitmap rtb = new RenderTargetBitmap((int)100,
(int)50, 96, 96,
PixelFormats.Pbgra32);
rtb.Render(element);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream ms = new MemoryStream();
encoder.Save(ms);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
System.Drawing.Color backColor = bmp.GetPixel(1, 1);
bmp.MakeTransparent(backColor);
retBitmap = loadBitmap(bmp);
return retBitmap;
}
示例14: TaskImageFromName
/// <summary>
/// Returns an image from assembly resources.
/// </summary>
/// <param name="name">Name of the resource to create an image from. Should not include
/// the task namespace.</param>
/// <returns>An image</returns>
private System.Drawing.Bitmap TaskImageFromName(string name)
{
// This utility function simply returns a bitmap from a name by retrieving
// an assembly resource.
try
{
string fullName = this.GetType().Namespace + ".Images." + name + ".png";
System.Drawing.Bitmap image = new System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(fullName));
image.MakeTransparent(image.GetPixel(1, 1));
return image;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
return null;
}
示例15: Form1_Load
private void Form1_Load(object sender, System.EventArgs e)
{
System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "browse.bmp"));
bitmap1.MakeTransparent(System.Drawing.Color.Teal);
cmdLoad.Image = bitmap1;
System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "properti.bmp"));
bitmap2.MakeTransparent(System.Drawing.Color.Teal);
cmdProperties.Image = bitmap2;
cmdMapProperties.Image = bitmap2;
chkTOC.Enabled = false;
}