플러드 채우기 도구를 WPF 페인트 프로그램에 구현하려고합니다. 모든 드로잉 작업을 먼저 비트 맵에 작성하여 벡터 메서드를 무시하려고합니다. 그러면 비트 맵이 캔버스로 설정됩니다.이미지 추가
이미지를 캔버스에 전달할 때 문제가 있습니다. 상대 위치를 사용하여 이미지를 설정하지 않습니다. 이미지는 내가 할 수있는 것보다 훨씬 잘 설명 할 것이다. 채우기 전에
:
채우기 후 :
이미지 비트 맵은 창으로 상대를 작성하고 도구 모음을 겹쳐있다. 나는 이것이 어떻게되는 것을 막을 수 있는지 궁금합니다. 첨부 된 필자 클래스의 관련 코드입니다.
public override void OnMouseDown(CCDrawingCanvas canvas, System.Windows.Input.MouseButtonEventArgs e) {
double dpi = 96d;
// Get the size of the canvas
System.Windows.Size size = new System.Windows.Size((int)canvas.ActualWidth, (int)canvas.ActualHeight);
// Measure and arrange the surface
canvas.Measure(size);
canvas.Arrange(new Rect(size));
RenderTargetBitmap source = new RenderTargetBitmap(
(int)canvas.ActualWidth,
(int)canvas.ActualHeight,
dpi,
dpi,
PixelFormats.Pbgra32);
source.Render(canvas);
WriteableBitmap modifiedImage = new WriteableBitmap(source);
int h = modifiedImage.PixelHeight;
int w = modifiedImage.PixelWidth;
int[] pixelData = new int[h * w];
int widthInByte = modifiedImage.PixelWidth * (modifiedImage.Format.BitsPerPixel/8);
modifiedImage.CopyPixels(pixelData, widthInByte, 0);
int oldColor = BitConverter.ToInt32(new byte[] { System.Drawing.Color.White.B, System.Drawing.Color.White.G, System.Drawing.Color.White.R, System.Drawing.Color.White.A }, 0);
int newColor = BitConverter.ToInt32(new byte[] { System.Drawing.Color.Black.B, System.Drawing.Color.Black.G, System.Drawing.Color.Black.R, System.Drawing.Color.Black.A }, 0);
// Perform the recursive fill
FloodFill(pixelData, (int)p.X, (int)p.Y, w, h, oldColor, newColor);
modifiedImage.WritePixels(new Int32Rect(0, 0, w, h), pixelData, widthInByte, 0);
newFill = new GraphicsFill(modifiedImage);
// Adds newFill to canvas.GraphicsList
AddObject(canvas, newFill);
}
XAML 코드 : WPF에서
<Window x:Class="ccGui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:effects="clr-namespace:System.Windows.Media.Effects;assembly=presentationcore"
xmlns:lib="clr-namespace:ccDrawingLib;assembly=ccDrawingLib"
xmlns:local="clr-namespace:ccGui"
Title="MainWindow" Height="600" Width="800">
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="New" Command="ApplicationCommands.New" />
<MenuItem Header="Open" Command="ApplicationCommands.Open" />
<MenuItem Header="Save" Command="ApplicationCommands.Save" />
<MenuItem Header="Save As" Command="ApplicationCommands.SaveAs" />
<MenuItem Header="Close" Command="ApplicationCommands.Close" />
</MenuItem>
<MenuItem Header="Tool" Name="menuTools">
<MenuItem Header="Brush" Name="ccToolBrush" Tag="Brush" />
<MenuItem Header="Fill" Name="ccToolFill" Tag="Fill" />
</MenuItem>
</Menu>
<lib:CCDrawingCanvas x:Name="canvas" Background="White" />
</DockPanel>
</Window>
새 개체가 자식 대신 부모 또는 루트 Visual에 추가되는 것처럼 보이는 현상이 거의 보입니다. 일반적으로 레이아웃 시스템은 일반적으로 잘못된 부모/비주얼/컨테이너에 추가하거나 시도하지 않는 한 비 상대 레이아웃을 방지합니다. 관련 XAML도 공유 할 수 있습니까? –
모양 클래스를 사용하고 [RenderTargetBitmap.Render'] (http://msdn.microsoft.com/en-us/library/system)를 사용하여 이미지를 저장할 때 수동으로 모든 것을 수동으로 수행하는 이유는 무엇입니까? .windows.media.imaging.rendertargetbitmap.render.aspx) 방법? – Sheridan
@JTrana 곧 게시 할 예정입니다. – Alex