用于定位位图/图形对象的C#代码 [英] C# code for Positioning a Bitmap/graphic object

查看:53
本文介绍了用于定位位图/图形对象的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我使用以下代码创建了一个黄色的小矩形.但它始终显示在顶部.同一页面上的其他控件(例如文本框/按钮)不可见.

Hi I have created a small-yellow rectangle using following code. But it is always displaying at the top. Other control(eg.textbox/button) on same page is not visible.

//=======================================
protected void Page_Load(object sender, EventArgs e)
    {
        Bitmap objBMP = new Bitmap(60, 20);
        Graphics objGraphics = Graphics.FromImage(objBMP);

        objGraphics.Clear(Color.Yellow);
        objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

        Response.ContentType = "image/GIF";
        objBMP.Save(Response.OutputStream, ImageFormat.Gif);        
        objGraphics.Dispose();
        objBMP.Dispose();

    }
//======================================



我该怎么做才能在表格标签的td标签中显示该标签并查看同一页面的所有其他内容?



What shall I do to display this in a td-tag within a table-tag and view all other content of the same page?

推荐答案

使用以下代码:
对于定位:
下面的代码示例演示如何从文件Climber.jpg构造位图并显示位图.图像左上角的目标点(10,10)在第二个和第三个参数中指定.
C#:
位图myBitmap =新的位图("Climber.jpg");
myGraphics.DrawImage(myBitmap,10,10);

然后在这些部分中克隆,您也可以使用它们:
Bitmap类提供了一个Clone方法,可用于复制现有Bitmap. Clone方法具有一个源矩形参数,可用于指定要复制的原始位图的一部分.下面的代码示例演示如何通过克隆现有位图的上半部分来创建位图.然后绘制两个图像.
C#


位图originalBitmap = new Bitmap("Spiral.png");
Rectangle sourceRectangle = new Rectangle(0,0,originalBitmap.Width,
originalBitmap.Height/2);

位图secondBitmap = originalBitmap.Clone(sourceRectangle,
PixelFormat.DontCare);

myGraphics.DrawImage(originalBitmap,10,10);
myGraphics.DrawImage(secondBitmap,150,10);
use these code:
For Postioning:
The following code example shows how to construct a Bitmap from the file Climber.jpg and displays the bitmap. The destination point for the upper-left corner of the image, (10, 10), is specified in the second and third parameters.
C#:
Bitmap myBitmap = new Bitmap("Climber.jpg");
myGraphics.DrawImage(myBitmap, 10, 10);

Then cloning also in these part u can also use these also:
The Bitmap class provides a Clone method that you can use to make a copy of an existing Bitmap. The Clone method has a source rectangle parameter that you can use to specify the portion of the original bitmap that you want to copy. The following code example shows how to create a Bitmap by cloning the top half of an existing Bitmap. Then both images are drawn.
C#


Bitmap originalBitmap = new Bitmap("Spiral.png");
Rectangle sourceRectangle = new Rectangle(0, 0, originalBitmap.Width,
originalBitmap.Height / 2);

Bitmap secondBitmap = originalBitmap.Clone(sourceRectangle,
PixelFormat.DontCare);

myGraphics.DrawImage(originalBitmap, 10, 10);
myGraphics.DrawImage(secondBitmap, 150, 10);


这篇关于用于定位位图/图形对象的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆