Image 如何在windows phone 8中在图像上写入文本?
我有一个图像,我想在上面写文字。在图像上写入文本后,我想将文本移动到屏幕上我喜欢的任何地方。我试着在图像上写文字,但我只能在屏幕上写,我不能移动它。你能帮助我吗。谢谢大家:) 这是我的代码:Image 如何在windows phone 8中在图像上写入文本?,image,windows-phone-8,windows-phone,photos,Image,Windows Phone 8,Windows Phone,Photos,我有一个图像,我想在上面写文字。在图像上写入文本后,我想将文本移动到屏幕上我喜欢的任何地方。我试着在图像上写文字,但我只能在屏幕上写,我不能移动它。你能帮助我吗。谢谢大家:) 这是我的代码: WriteableBitmap wb; wb = new WriteableBitmap((BitmapSource)ImgZoom.Source); TextBlock tb = new TextBlock(); tb.Text = Txt.Text; tb.TextWrapping = TextWrap
WriteableBitmap wb;
wb = new WriteableBitmap((BitmapSource)ImgZoom.Source);
TextBlock tb = new TextBlock();
tb.Text = Txt.Text;
tb.TextWrapping = TextWrapping.Wrap;
tb.Foreground = new SolidColorBrush(Colors.Black);
tb.FontSize = 70;
tb.FontWeight = FontWeights.Bold;
wb.Render(tb, new TranslateTransform() { X = 25, Y = 191 });
wb.Invalidate();
你有一个图像,你想在上面写文字,然后把文字移到任何地方。希望这段代码能对你有所帮助
Xaml :
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Source="/Images/3.png" />
</Grid>
C# :
private TranslateTransform move = new TranslateTransform();
private TransformGroup rectangleTransforms = new TransformGroup();
public TestPage()
{
InitializeComponent();
TextBlock tb = new TextBlock();
tb.Text = "Hello..!";
tb.TextWrapping = TextWrapping.Wrap;
tb.Foreground = new SolidColorBrush(Colors.Black);
tb.FontSize = 70;
tb.FontWeight = FontWeights.Bold;
ContentPanel.Children.Add(tb);
rectangleTransforms.Children.Add(move);
tb.RenderTransform = rectangleTransforms;
tb.ManipulationStarted +=
new EventHandler<ManipulationStartedEventArgs>(Rectangle_ManipulationStarted);
tb.ManipulationDelta +=
new EventHandler<ManipulationDeltaEventArgs>(Rectangle_ManipulationDelta);
tb.ManipulationCompleted +=
new EventHandler<ManipulationCompletedEventArgs>(Rectangle_ManipulationCompleted);
}
void Rectangle_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
//your code
}
void Rectangle_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// Move the Textbox.
move.X += e.DeltaManipulation.Translation.X;
move.Y += e.DeltaManipulation.Translation.Y;
}
void Rectangle_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
//your code
}
Xaml:
C#:
私有TranslateTransform move=新TranslateTransform();
私有TransformGroup rectangleTransforms=新TransformGroup();
公共测试页()
{
初始化组件();
TextBlock tb=新的TextBlock();
tb.Text=“你好!”;
tb.TextWrapping=TextWrapping.Wrap;
tb.Foreground=新的SolidColorBrush(Colors.Black);
tb.FontSize=70;
tb.FontWeight=FontWeights.Bold;
ContentPanel.Children.Add(tb);
矩形变换。子对象。添加(移动);
tb.RenderTransform=矩形变换;
结核杆菌+=
新的EventHandler(矩形_操作开始);
结核杆菌+=
新的EventHandler(矩形_操作delta);
结核病控制完成+=
新的EventHandler(矩形_操作完成);
}
空矩形\u操纵开始(对象发送器,操纵开始目标e)
{
//你的代码
}
void Rectangle_操纵delta(对象发送器,操纵deltaeventargs e)
{
//移动文本框。
move.X+=e.DeltaManipulation.Translation.X;
move.Y+=e.DeltaManipulation.Translation.Y;
}
无效矩形\u操作已完成(对象发送方,操作已完成事件参数e)
{
//你的代码
}
有关此代码的更多信息,请参阅此链接。您有一个图像,希望在其上写入文本,然后将文本移动到任意位置。希望这段代码能对你有所帮助
Xaml :
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image Source="/Images/3.png" />
</Grid>
C# :
private TranslateTransform move = new TranslateTransform();
private TransformGroup rectangleTransforms = new TransformGroup();
public TestPage()
{
InitializeComponent();
TextBlock tb = new TextBlock();
tb.Text = "Hello..!";
tb.TextWrapping = TextWrapping.Wrap;
tb.Foreground = new SolidColorBrush(Colors.Black);
tb.FontSize = 70;
tb.FontWeight = FontWeights.Bold;
ContentPanel.Children.Add(tb);
rectangleTransforms.Children.Add(move);
tb.RenderTransform = rectangleTransforms;
tb.ManipulationStarted +=
new EventHandler<ManipulationStartedEventArgs>(Rectangle_ManipulationStarted);
tb.ManipulationDelta +=
new EventHandler<ManipulationDeltaEventArgs>(Rectangle_ManipulationDelta);
tb.ManipulationCompleted +=
new EventHandler<ManipulationCompletedEventArgs>(Rectangle_ManipulationCompleted);
}
void Rectangle_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
//your code
}
void Rectangle_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// Move the Textbox.
move.X += e.DeltaManipulation.Translation.X;
move.Y += e.DeltaManipulation.Translation.Y;
}
void Rectangle_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
//your code
}
Xaml:
C#:
私有TranslateTransform move=新TranslateTransform();
私有TransformGroup rectangleTransforms=新TransformGroup();
公共测试页()
{
初始化组件();
TextBlock tb=新的TextBlock();
tb.Text=“你好!”;
tb.TextWrapping=TextWrapping.Wrap;
tb.Foreground=新的SolidColorBrush(Colors.Black);
tb.FontSize=70;
tb.FontWeight=FontWeights.Bold;
ContentPanel.Children.Add(tb);
矩形变换。子对象。添加(移动);
tb.RenderTransform=矩形变换;
结核杆菌+=
新的EventHandler(矩形_操作开始);
结核杆菌+=
新的EventHandler(矩形_操作delta);
结核病控制完成+=
新的EventHandler(矩形_操作完成);
}
空矩形\u操纵开始(对象发送器,操纵开始目标e)
{
//你的代码
}
void Rectangle_操纵delta(对象发送器,操纵deltaeventargs e)
{
//移动文本框。
move.X+=e.DeltaManipulation.Translation.X;
move.Y+=e.DeltaManipulation.Translation.Y;
}
无效矩形\u操作已完成(对象发送方,操作已完成事件参数e)
{
//你的代码
}
有关此代码的更多信息,请参阅此链接。请尝试仅在图像边界中移动此链接
C# :
int trX = 0;
int trY = 0;
TextBlock croppingRectangle;
public TestPage()
{
InitializeComponent();
init();
}
public void init()
{
TextBlock rect = new TextBlock();
rect.Text = "Hello......Hello......";
rect.Height = 94; //fixed
rect.MaxHeight = image1.Height;
rect.MaxWidth = image1.Width;
rect.Width = 300; //fixed
rect.TextWrapping = TextWrapping.Wrap;
rect.Foreground = new SolidColorBrush(Colors.Black);
rect.FontSize = 70;
rect.FontWeight = FontWeights.Bold;
rect.Margin = image1.Margin;
rect.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(rect_ManipulationDelta);
LayoutRoot.Children.Add(rect);
LayoutRoot.Height = image1.Height;
LayoutRoot.Width = image1.Width;
}
private void rect_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
GeneralTransform gt = ((TextBlock)sender).TransformToVisual(LayoutRoot);
Point p = gt.Transform(new Point(0, 0));
int intermediateValueY = (int)((LayoutRoot.Height - ((TextBlock)sender).Height));
int intermediateValueX = (int)((LayoutRoot.Width - ((TextBlock)sender).Width));
croppingRectangle = (TextBlock)sender;
TranslateTransform tr = new TranslateTransform();
trX += (int)e.DeltaManipulation.Translation.X;
trY += (int)e.DeltaManipulation.Translation.Y;
if (trY < (-intermediateValueY / 2))
{
trY = (-intermediateValueY / 2);
}
else if (trY > (intermediateValueY / 2))
{
trY = (intermediateValueY / 2);
}
if (trX < (-intermediateValueX / 2))
{
trX = (-intermediateValueX / 2);
}
else if (trX > (intermediateValueX / 2))
{
trX = (intermediateValueX / 2);
}
tr.X = trX;
tr.Y = trY;
croppingRectangle.RenderTransform = tr;
}
C#
int-trX=0;
int trY=0;
文本块裁剪矩形;
公共测试页()
{
初始化组件();
init();
}
公共void init()
{
TextBlock rect=新的TextBlock();
rect.Text=“你好……你好……”;
rect.Height=94;//固定
rect.MaxHeight=image1.Height;
rect.MaxWidth=image1.Width;
矩形宽度=300;//固定
rect.TextWrapping=TextWrapping.Wrap;
rect.Foreground=新的SolidColorBrush(Colors.Black);
rect.FontSize=70;
rect.FontWeight=FontWeights.Bold;
矩形边距=图像1.边距;
rect.operationDelta+=新事件处理程序(rect_-operationDelta);
LayoutRoot.Children.Add(rect);
LayoutRoot.Height=image1.Height;
LayoutRoot.Width=image1.Width;
}
私有void rect_操纵delta(对象发送方,操纵deltaeventargs e)
{
GeneralTransform gt=((文本块)发送方).TransformToVisual(LayoutRoot);
点p=gt.变换(新点(0,0));
int intermediateValueY=(int)((LayoutRoot.Height-((TextBlock)sender.Height));
int intermediateValueX=(int)((LayoutRoot.Width-((TextBlock)sender.Width));
裁剪矩形=(文本块)发送方;
TranslateTransform tr=新的TranslateTransform();
trX+=(int)e.DeltaManipulation.Translation.X;
trY+=(int)e.DeltaManipulation.Translation.Y;
如果(trY<(-intermediateValueY/2))
{
trY=(-mediatevaluey/2);
}
否则如果(尝试>(中间值/2))
{
trY=(中间值/2);
}
如果(trX<(-intermediateValueX/2))
{
trX=(-mediatevaluex/2);
}
否则如果(trX>(中间值/2))
{
trX=(中间值/2);
}
tr.X=trX;
tr.Y=尝试;
cropingrectangle.RenderTransform=tr;
}
XAML:
<Grid x:Name="LayoutRoot" >
<Image Width="300" Height="300" x:Name="image1" Source="/Images/3.png" Stretch="Fill"/>
</Grid>
嗨,请尝试仅在图像边界中移动
C# :
int trX = 0;
int trY = 0;
TextBlock croppingRectangle;
public TestPage()
{
InitializeComponent();
init();
}
public void init()
{
TextBlock rect = new TextBlock();
rect.Text = "Hello......Hello......";
rect.Height = 94; //fixed
rect.MaxHeight = image1.Height;
rect.MaxWidth = image1.Width;
rect.Width = 300; //fixed
rect.TextWrapping = TextWrapping.Wrap;
rect.Foreground = new SolidColorBrush(Colors.Black);
rect.FontSize = 70;
rect.FontWeight = FontWeights.Bold;
rect.Margin = image1.Margin;
rect.ManipulationDelta += new EventHandler<ManipulationDeltaEventArgs>(rect_ManipulationDelta);
LayoutRoot.Children.Add(rect);
LayoutRoot.Height = image1.Height;
LayoutRoot.Width = image1.Width;
}
private void rect_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
GeneralTransform gt = ((TextBlock)sender).TransformToVisual(LayoutRoot);
Point p = gt.Transform(new Point(0, 0));
int intermediateValueY = (int)((LayoutRoot.Height - ((TextBlock)sender).Height));
int intermediateValueX = (int)((LayoutRoot.Width - ((TextBlock)sender).Width));
croppingRectangle = (TextBlock)sender;
TranslateTransform tr = new TranslateTransform();
trX += (int)e.DeltaManipulation.Translation.X;
trY += (int)e.DeltaManipulation.Translation.Y;
if (trY < (-intermediateValueY / 2))
{
trY = (-intermediateValueY / 2);
}
else if (trY > (intermediateValueY / 2))
{
trY = (intermediateValueY / 2);
}
if (trX < (-intermediateValueX / 2))
{
trX = (-intermediateValueX / 2);
}
else if (trX > (intermediateValueX / 2))
{
trX = (intermediateValueX / 2);
}
tr.X = trX;
tr.Y = trY;
croppingRectangle.RenderTransform = tr;
}
C#
int-trX=0;
int trY=0;
文本块裁剪矩形;
公共测试页()
{
初始化组件();
init();
}
公共void init()
{
TextBlock rect=新的TextBlock();
rect.Text=“你好……你好……”;
rect.Height=94;//固定
rect.MaxHeight=image1.Height;
rect.MaxWidth=image1.Width;