积极答复者
如何对Canvas上内容做缩略图,类似word里面的缩略图?

问题
-
我想对canvas上的内容做缩略图,类似于word里面的缩略图。canvas上的内容会移动(如移出边界),也能放大缩小,因此加了滚动条。如果使用Imagebrush的话,缩略图失真非常严重。使用visualbrush,如果viewbox设置为相对值,会显示canvas上的所有内容,移出边界的也会显示。如果设置为绝对值,缩略图会跟随滚动条进行滚动。怎么样才能做到就对canvas当前的页面内容缩略,边界外的不显示,不管放大缩小,就显示当前canvas上的内容?
请问还有其他的解决方案没有?
急盼解答!
麻烦大家了!
- 已编辑 张柱敏 2012年1月10日 10:02
答案
-
还是根据我的上次的那个思路下去吧,依据你现在遇到的问题,推荐使用 RenderTargetBitmap:
private void button3_Click(object sender, RoutedEventArgs e) { this.listBox1.Items.Clear(); Canvas canvas = new Canvas(); canvas.Width = this.listBox1.ActualWidth; canvas.Height = this.listBox1.ActualHeight / 5; RenderTargetBitmap bitmap = new RenderTargetBitmap(300, 300, 96, 96, PixelFormats.Pbgra32); bitmap.Render(canvas1); canvas.Background = new ImageBrush(bitmap); this.listBox1.Items.Add(canvas); }
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 MakubeXSoft 2012年1月12日 0:56
- 取消建议作为答案 张柱敏 2012年1月12日 7:09
- 已标记为答案 张柱敏 2012年1月13日 1:52
全部回复
-
还是根据我的上次的那个思路下去吧,依据你现在遇到的问题,推荐使用 RenderTargetBitmap:
private void button3_Click(object sender, RoutedEventArgs e) { this.listBox1.Items.Clear(); Canvas canvas = new Canvas(); canvas.Width = this.listBox1.ActualWidth; canvas.Height = this.listBox1.ActualHeight / 5; RenderTargetBitmap bitmap = new RenderTargetBitmap(300, 300, 96, 96, PixelFormats.Pbgra32); bitmap.Render(canvas1); canvas.Background = new ImageBrush(bitmap); this.listBox1.Items.Add(canvas); }
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已建议为答案 MakubeXSoft 2012年1月12日 0:56
- 取消建议作为答案 张柱敏 2012年1月12日 7:09
- 已标记为答案 张柱敏 2012年1月13日 1:52
-
-
其实要显示多少, 显示谁,主要看你要 Render的大小和 Render的对象。不是很难,比如按照你所说的,你只要
bitmap.Render(scrollViewer1); 就可以了。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us