[英]How do I draw an image reflection in WinForms?
我想在圖像的C#(WinForms)中繪制一個反射,所以我需要能夠水平翻轉圖像。 我知道我可以用image.RotateFlip做到這一點,但這種方法的問題是我必須翻轉圖像兩次才能在下一個畫面上再次繪制它。 每張圖片每次塗裝兩次這樣做似乎很慢。
我想在繪制圖像時進行翻轉,所以我只需翻轉一次,但我找不到任何方法來做到這一點。 這可能嗎?
我考慮的另一種方法是以某種方式翻轉圖形對象,正常繪制圖像,然后向后翻轉圖形對象,以便下一個繪圖是正確的。 如果這比翻轉圖像快兩倍,是否可以這樣做?
此外,我不想在內存中保留2張圖像,因此我無法復制圖像並翻轉克隆。
從這里得到這個代碼並檢查,看看它是否有任何幫助。
using System;
using System.Drawing;
using System.Windows.Forms;
class ImageReflection: Form
{
Image image = Image.FromFile("Color.jpg");
public static void Main()
{
Application.Run(new ImageReflection());
}
public ImageReflection()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
int cxImage = image.Width;
int cyImage = image.Height;
grfx.DrawImage(image, cx / 2, cy / 2, cxImage, cyImage);
grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, cyImage);
grfx.DrawImage(image, cx / 2, cy / 2, cxImage, -cyImage);
grfx.DrawImage(image, cx / 2, cy / 2, -cxImage, -cyImage);
}
}
編輯
這樣的事情呢?
draw(new Bitmap (img).rotateflip(param))
好的,rotateflip不會返回圖像
看着這個 ,旋轉翻轉只有一次翻轉就足夠了。 沒有?
RotateNoneFlipNone Specifies no rotation and no flipping.
Rotate90FlipNone Specifies a 90-degree rotation without flipping.
Rotate180FlipNone Specifies a 180-degree rotation without flipping.
Rotate270FlipNone Specifies a 270-degree rotation without flipping.
RotateNoneFlipX Specifies no rotation followed by a horizontal flip.
Rotate90FlipX Specifies a 90-degree rotation followed by a horizontal flip.
Rotate180FlipX Specifies a 180-degree rotation followed by a horizontal flip.
Rotate270FlipX Specifies a 270-degree rotation followed by a horizontal flip.
RotateNoneFlipY Specifies no rotation followed by a vertical flip.
Rotate90FlipY Specifies a 90-degree rotation followed by a vertical flip.
Rotate180FlipY Specifies a 180-degree rotation followed by a vertical flip.
Rotate270FlipY Specifies a 270-degree rotation followed by a vertical flip.
RotateNoneFlipXY Specifies no rotation followed by a horizontal and vertical flip.
Rotate90FlipXY Specifies a 90-degree rotation followed by a horizontal and vertical flip.
Rotate180FlipXY Specifies a 180-degree rotation followed by a horizontal and vertical flip.
Rotate270FlipXY Specifies a 270-degree rotation followed by a horizontal and vertical flip.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.