本文整理汇总了C#中System.Drawing.Bitmap类的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap类的具体用法?C# System.Drawing.Bitmap怎么用?C# System.Drawing.Bitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Drawing.Bitmap类属于命名空间,在下文中一共展示了System.Drawing.Bitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Terrain
public Terrain(Device device, String texture, int pitch, Renderer renderer)
{
HeightMap = new System.Drawing.Bitmap(@"Data/Textures/"+texture);
WaterShader = new WaterShader(device);
TerrainShader = new TerrainShader(device);
_width = HeightMap.Width-1;
_height = HeightMap.Height-1;
_pitch = pitch;
_terrainTextures = new ShaderResourceView[4];
_terrainTextures[0] = new Texture(device, "Sand.png").TextureResource;
_terrainTextures[1] = new Texture(device, "Grass.png").TextureResource;
_terrainTextures[2] = new Texture(device, "Ground.png").TextureResource;
_terrainTextures[3] = new Texture(device, "Rock.png").TextureResource;
_reflectionClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
_refractionClippingPlane = new Vector4(0.0f, -1.0f, 0.0f, 0.0f);
_noClippingPlane = new Vector4(0.0f, 1.0f, 0.0f, 10000);
_reflectionTexture = new RenderTexture(device, renderer.ScreenSize);
_refractionTexture = new RenderTexture(device, renderer.ScreenSize);
_renderer = renderer;
_bitmap = new Bitmap(device,_refractionTexture.ShaderResourceView,renderer.ScreenSize, new Vector2I(100, 100), 0);
_bitmap.Position = new Vector2I(renderer.ScreenSize.X - 100, 0);
_bitmap2 = new Bitmap(device, _reflectionTexture.ShaderResourceView, renderer.ScreenSize, new Vector2I(100, 100), 0);
_bitmap2.Position = new Vector2I(renderer.ScreenSize.X - 100, 120);
_bumpMap = _renderer.TextureManager.Create("OceanWater.png");
_skydome = new ObjModel(device, "skydome.obj", renderer.TextureManager.Create("Sky.png"));
BuildBuffers(device);
WaveTranslation = new Vector2(0,0);
}
示例2: Wolf
public Wolf()
{
name = "Wolf";
family = "Carnivore";
food = "Rabbits";
image = new System.Drawing.Bitmap("wolf.jpg");
}
示例3: Run
public static void Run()
{
// ExStart:ExtractAllImagesFromPage
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Shapes();
// Call a Diagram class constructor to load a VSD diagram
Diagram diagram = new Diagram(dataDir + "ExtractAllImagesFromPage.vsd");
// Enter page index i.e. 0 for first one
foreach (Shape shape in diagram.Pages[0].Shapes)
{
// Filter shapes by type Foreign
if (shape.Type == Aspose.Diagram.TypeValue.Foreign)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(shape.ForeignData.Value))
{
// Load memory stream into bitmap object
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
// Save bmp here
bitmap.Save(dataDir + "ExtractAllImages" + shape.ID + "_out.bmp");
}
}
}
// ExEnd:ExtractAllImagesFromPage
}
示例4: Intitial
/// <summary>
/// 初始化
/// </summary>
public void Intitial( FontMgr.FontLoadInfo fontLoadInfo )
{
try
{
privateFontCollection = new PrivateFontCollection();
foreach (FontMgr.FontInfo info in fontLoadInfo.UnitCodeFontInfos)
{
privateFontCollection.AddFontFile( info.path );
}
fontFamilys = privateFontCollection.Families;
if (fontFamilys.Length != fontLoadInfo.UnitCodeFontInfos.Count)
throw new Exception( "导入的各个字体必须属于不同类别" );
for (int i = 0; i < fontFamilys.Length; i++)
{
fonts.Add( fontLoadInfo.UnitCodeFontInfos[i].name, new System.Drawing.Font( fontFamilys[i], fontLoadInfo.DefualtEmSize ) );
}
System.Drawing.Bitmap tempBitMap = new System.Drawing.Bitmap( 1, 1 );
mesureGraphics = System.Drawing.Graphics.FromImage( tempBitMap );
}
catch (Exception)
{
throw new Exception( "读取字体文件出错" );
}
}
示例5: ScaleByFixedHeight
private static void ScaleByFixedHeight(String fileName, int newHeight, String outputFile)
{
System.Drawing.Bitmap resizedImage = null;
try
{
using (System.Drawing.Image originalImage = System.Drawing.Image.FromFile(fileName))
{
double resizeRatio = (double)newHeight / originalImage.Size.Height;
int newWidth = (int)(originalImage.Size.Width * resizeRatio);
System.Drawing.Size newSize = new System.Drawing.Size(newWidth, newHeight);
resizedImage = new System.Drawing.Bitmap(originalImage, newSize);
}
// Save resized picture.
CheckAndCreatePath(outputFile);
resizedImage.Save(outputFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
finally
{
if (resizedImage != null)
{
resizedImage.Dispose();
}
}
}
示例6: BatchClassificationDialog
public BatchClassificationDialog(ref Klu klu, ref TrainingDataSet dataSet, ProcessOptions processOptions)
{
InitializeComponent();
_BackgroundWorker = new BackgroundWorker();
_BackgroundWorker.WorkerReportsProgress = true;
_BackgroundWorker.WorkerSupportsCancellation = true;
_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);
BrowseButton.IsEnabled = true;
CancelButton.IsEnabled = false;
ClassifyButton.IsEnabled = false;
_DataSet = dataSet;
_SelectedFiles = new ArrayList();
_ProcessOptions = processOptions;
// We want the images to be as less distorded as possible, so we disable all the overlays.
_ProcessOptions.DrawAnthropometricPoints = 0;
_ProcessOptions.DrawDetectionTime = 0;
_ProcessOptions.DrawFaceRectangle = 0;
_ProcessOptions.DrawSearchRectangles = 0;
_ProcessOptions.DrawFeaturePoints = 0;
_KLU = klu;
_FFP = new FaceFeaturePoints();
_TempBitmap = new System.Drawing.Bitmap(10, 10);
ExpressionsComboBox.ItemsSource = _DataSet.Expression;
ClassifyButton.Content = "Classify";
}
示例7: reveal
public static string reveal(string path)
{
string result = "";
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(path);
// FIXME
return result;
}
示例8: MakeImagesNegative
static void MakeImagesNegative(string sourceDirectoryPath, string targetDirectoryPath)
{
string[] filenames = System.IO.Directory.GetFiles(sourceDirectoryPath);
foreach (var filename in filenames)
{
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(filename);
Parallel.For(0, bitmap.Height, (bitmapRowIndex) =>
{
lock (bitmap)
{
for (int bitmapColIndex = 0; bitmapColIndex < bitmap.Width; bitmapColIndex++)
{
var pixel = bitmap.GetPixel(bitmapColIndex, bitmapRowIndex);
var negativePixel = System.Drawing.Color.FromArgb(
byte.MaxValue - pixel.A,
byte.MaxValue - pixel.R,
byte.MaxValue - pixel.G,
byte.MaxValue - pixel.B);
bitmap.SetPixel(bitmapColIndex, bitmapRowIndex, negativePixel);
}
}
});
bitmap.Save(filename.Replace(sourceDirectoryPath, targetDirectoryPath));
}
}
示例9: CreateAvatar
public static byte[] CreateAvatar(int sideLength, System.IO.Stream fromStream)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (var image = System.Drawing.Image.FromStream(fromStream))
using (var thumbBitmap = new System.Drawing.Bitmap(sideLength, sideLength))
{
var a = Math.Min(image.Width, image.Height);
var x = (image.Width - a) / 2;
var y = (image.Height - a) / 2;
using (var thumbGraph = System.Drawing.Graphics.FromImage(thumbBitmap))
{
thumbGraph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
var imgRectangle = new System.Drawing.Rectangle(0, 0, sideLength, sideLength);
thumbGraph.DrawImage(image, imgRectangle, x, y, a, a, System.Drawing.GraphicsUnit.Pixel);
thumbBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
return (ms.ToArray());
}
示例10: ThumbnailEventArgs
// Constructor
public ThumbnailEventArgs(System.Drawing.Bitmap bmp, string filename,int count, int totalcount)
{
this.bmp = bmp;
this.filename = filename;
this.count = count;
this.totalCount = totalcount;
}
示例11: create_hue_bitmap
public static System.Drawing.Bitmap create_hue_bitmap(int width, int height)
{
var bitmap = new System.Drawing.Bitmap(width, height);
using (var gfx = System.Drawing.Graphics.FromImage(bitmap))
{
var colorblend = new System.Drawing.Drawing2D.ColorBlend();
const int num_steps = 34;
var range_steps = EnumerableUtil.RangeSteps(0.0, 1.0, num_steps);
colorblend.Colors = new System.Drawing.Color[num_steps];
colorblend.Positions = new float[num_steps];
double _sat = 1.0;
double _val = 1.0;
var colors = range_steps.Select(x => VisioAutomation.UI.ColorUtil.HSVToSystemDrawingColor(x, _sat, _val));
var positions = range_steps.Select(x => (float) x);
EnumerableUtil.FillArray( colorblend.Colors, colors );
EnumerableUtil.FillArray(colorblend.Positions, positions);
using (var brush_rainbow = new System.Drawing.Drawing2D.LinearGradientBrush(
new System.Drawing.Point(0, 0),
new System.Drawing.Point(bitmap.Width, 0),
System.Drawing.Color.Black,
System.Drawing.Color.White))
{
brush_rainbow.InterpolationColors = colorblend;
gfx.FillRectangle(brush_rainbow, 0, 0, bitmap.Width, bitmap.Height);
}
}
return bitmap;
}
示例12: Koala
public Koala()
{
name = "Koala";
family = "Herbavore";
food = "Leaves";
image = new System.Drawing.Bitmap("koala.jpg");
}
示例13: ThumbnailCreator
/// <summary>
/// Initializes a new instance of the <see cref="ThumbnailCreator"/> class.
/// </summary>
/// <param name="tnSettings">The <see cref="ThumbnailSettings"/> to use.</param>
/// <param name="worker">The <see cref="System.ComponentModel.BackgroundWorker"/>worker to use.
/// </param>
public ThumbnailCreator(ThumbnailSettings tnSettings, System.ComponentModel.BackgroundWorker worker)
{
this._tnSettings = tnSettings;
this._worker = worker;
#if false
_imageCodec = GetEncoder (System.Drawing.Imaging.ImageFormat.Png);
_qualityParameter = new System.Drawing.Imaging.EncoderParameter (
System.Drawing.Imaging.Encoder.Quality, 75L);
_qualityParameters = new System.Drawing.Imaging.EncoderParameters (1);
_qualityParameters.Param[0] = _qualityParameter;
#else
_imageCodec = GetEncoder (System.Drawing.Imaging.ImageFormat.Jpeg);
_qualityParameter = new System.Drawing.Imaging.EncoderParameter (
System.Drawing.Imaging.Encoder.Quality, 75L);
_qualityParameters = new System.Drawing.Imaging.EncoderParameters (1);
_qualityParameters.Param[0] = _qualityParameter;
#endif
#if false
using (System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap (1, 1))
{
System.Drawing.Imaging.EncoderParameters paramList =
bitmap1.GetEncoderParameterList (_imageCodec.Clsid);
System.Drawing.Imaging.EncoderParameter[] encParams = paramList.Param;
foreach (System.Drawing.Imaging.EncoderParameter p in encParams)
{
THelper.Information ("Type {0}, GUID {1}", p.ValueType, p.Encoder.Guid);
}
paramList.Dispose ();
}
#endif
}
示例14: ActionDefinition
public ActionDefinition(ActionLibrary parent, string name, int id)
{
Library = parent;
GameMakerVersion = 520;
Name = name;
ActionID = id;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
Properties.Resources.DefaultAction.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
OriginalImage = ms.ToArray();
ms.Close();
Image = new System.Drawing.Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Graphics.FromImage(Image).DrawImage(Properties.Resources.DefaultAction, new System.Drawing.Rectangle(0, 0, 24, 24), new System.Drawing.Rectangle(0, 0, 24, 24), System.Drawing.GraphicsUnit.Pixel);
(Image as System.Drawing.Bitmap).MakeTransparent(Properties.Resources.DefaultAction.GetPixel(0, Properties.Resources.DefaultAction.Height - 1));
Hidden = false;
Advanced = false;
RegisteredOnly = false;
Description = string.Empty;
ListText = string.Empty;
HintText = string.Empty;
Kind = ActionKind.Normal;
InterfaceKind = ActionInferfaceKind.Normal;
IsQuestion = false;
ShowApplyTo = true;
ShowRelative = true;
ArgumentCount = 0;
Arguments = new ActionArgument[8];
for (int i = 0; i < 8; i++) Arguments[i] = new ActionArgument();
ExecutionType = ActionExecutionType.None;
FunctionName = string.Empty;
Code = string.Empty;
}
示例15: TextureData
public TextureData(string src)
{
try
{
System.Drawing.Bitmap texture = new System.Drawing.Bitmap(src);
width = texture.Width;
height = texture.Height;
Clear();
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
Color xnaColor = new Color();
System.Drawing.Color formsColor = texture.GetPixel(x, y);
xnaColor.R = formsColor.R;
xnaColor.G = formsColor.G;
xnaColor.B = formsColor.B;
xnaColor.A = formsColor.A;
data[y * width + x] = xnaColor.PackedValue;
}
}
catch(Exception e)
{
Console.WriteLine("Failed to load file: " + e.Message);
Clear();
}
}