您的位置:首页 > 移动开发 > Objective-C

绘制bitmap图片保存,生成ico文件或者对象

2008-09-10 15:49 615 查看
自己绘制bitmap图片保存,生成ico文件或者对象
今天回答一个问题的时候的随笔
 

Bitmap bit = new Bitmap(100, 30);

            Graphics g = Graphics.FromImage(bit);

            SolidBrush sb = new SolidBrush(Color.Blue);

            Rectangle rg = new Rectangle(new Point(0, 0), bit.Size);

            g.FillRectangle(sb, rg);

            g.DrawString("测试测试呵呵", this.Font, new SolidBrush(Color.White), new PointF(0, 0));

            bit.Save("d://123.bmp");//保存下来这个可以看生成的图片

 
msdn上面有详解,先将你需要生成的图片与文字合成一个image对象,然后生成icon对象,最后用Graphics 操作或者直接用icon类进行操作

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse(这是 Paint 事件处理程序的参数)。代码执行下列操作:

创建一个 Bitmap。

将该对象绘制到屏幕。

获取 Bitmap 的图标句柄。

将窗体的 Form.Icon 属性设置为从该句柄创建的图标。

调用 Win32 API 函数 DestroyIcon 以释放资源。

C# code
 [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);

private void GetHicon_Example(PaintEventArgs e)
{

// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap(@"c:/FakePhoto.jpg");

// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0);

// Get an Hicon for myBitmap.
IntPtr Hicon = myBitmap.GetHicon();

// Create a new icon from the handle.
Icon newIcon = Icon.FromHandle(Hicon);

// Set the form Icon attribute to the new icon.
this.Icon = newIcon;

// Destroy the Icon, since the form creates
// its own copy of the icon.
DestroyIcon(newIcon.Handle);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐