|
Hi,
I am using InkCanvas control for signature. Can anyone tell me how to store these signatures in sql server DB?
Vsaratkar
|
|
|
|
|
Save the strokes to a memory stream
var memoryStream = new System.IO.MemoryStream();
inkCanvas.Strokes.Save(memoryStream);
to compress the data
then store the data of the memory stream in your database as an appropriate binary type.
to load the data to an InkCanvans from a memory stream
inkCanvas1.Strokes = new StrokeCollection(memoryStream);
memoryStream = 0
Eslam Afifi
|
|
|
|
|
|
Glad to help
Eslam Afifi
|
|
|
|
|
I see how to store the strokes DB. We've been successful at this in storing signatures from a tablet application. I now want to be able to present our signatures via a web report. I want to be able to convert my strokes directly to a png or bitmap and display using SS Reporting Services image control. So, I need to convert the strokes collection, stored in the database, to to bitmap byte[], as we're unable to use the inkcavas control in SSRS. Does anyone know how to do this?
-Andy
|
|
|
|
|
Adventures into Ink API using WPF[^] does that. But it outputs only the visible parts of the ink. You may want to ensure that the InkCanvas or InkPresenter is big enough to contain all the ink in it.
The StrokeCollection has a method Draw[^] that draws on a DrawingContext, maybe you want to investigate that.
By the way, you should start a new thread instead of replying to an old one to increase the probability that someone see your question and someone may have a better solution.
Eslam Afifi
|
|
|
|
|
Hello.
Has anyone come across a nice, sturdy Tweening library for WPF? Coming from Flash I have been spoiled by Tweener, TweenMax, GTween etc and am in shock that MS has not provided something similar for WPF when us designers consider it an essential.
Cheers, E.
|
|
|
|
|
This Silverlight version[^] looks promising - a WPF version would be extremely simple to achieve.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
Chers for that, I'll give it a whirl. I found Bling too which is mighty fun.
|
|
|
|
|
Hi
I discovered that Blender can export to the .obj format which is supported in Expression Blend, so I'll be using Blender as my 3D modeling application.
The problem I'm facing though, is loading these models onto a ViewPort whenever the user wishes to do so, and not whenever the application loads e.g. I want to create a drop down menu which displays all my models, and as soon as the user clicks on a menu item ("chair" for instance), an already created model of a chair must be loaded and displayed. Is this possible, and how?
Code samples would be helpful
Thanks in advance
|
|
|
|
|
I've used the XAML Exporter for Blender[^] instead. Basically, you export your model out as XAML, which you can then bind in using XamlReader.Load.
The first step I'd take would be to define an ObservableCollection which was populated by reading in a list of items from a particular directory that end in xaml. Then, I'd bind this to the menu which would then trigger the load.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
I'm using datagrid from WPF Toolkit. And I have my owen style for column header. Here is code:
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="Background" Value="{StaticResource DataGrid_Style0_Header}" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#FFFFCB02" />
<Setter Property="BorderThickness" Value="0,0,1,1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridColumnHeader}">
<Border BorderBrush="{TemplateBinding dg:DataGridColumnHeader.BorderBrush}" BorderThickness="{TemplateBinding dg:DataGridColumnHeader.BorderThickness}">
<Grid Name="grContentHeader" Height="20" Background="{TemplateBinding dg:DataGridColumnHeader.Background}">
<ContentPresenter Content="{TemplateBinding dg:DataGridColumnHeader.Content}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" Cursor="Hand" Margin="2,0,2,0"/>
<Path Name="UpArrow" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,3,0" Visibility="Hidden">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment Point="6,0"/>
<LineSegment Point="3,5"/>
<LineSegment Point="0,0"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
<Path Name="DownArrow" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,3,0" Visibility="Hidden">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,5">
<LineSegment Point="6,5"/>
<LineSegment Point="3,0"/>
<LineSegment Point="0,5"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="SortDirection" Value="Ascending">
<Setter TargetName="DownArrow" Property="Visibility" Value="Visible"/>
<Setter TargetName="UpArrow" Property="Visibility" Value="Hidden"/>
<Setter TargetName="grContentHeader" Property="Background" Value="{StaticResource DataGrid_Header_Alt0}"/>
</Trigger>
<Trigger Property="SortDirection" Value="Descending">
<Setter TargetName="DownArrow" Property="Visibility" Value="Hidden"/>
<Setter TargetName="UpArrow" Property="Visibility" Value="Visible"/>
<Setter TargetName="grContentHeader" Property="Background" Value="{StaticResource DataGrid_Header_Alt0}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Problem is, that i can't resize column.
CanUserResize="True" for column and CanUserResizeColumns="True" for datagrid don't work.
Please help
<div class="ForumMod">modified on Thursday, March 12, 2009 5:23 AM</div>
|
|
|
|
|
Did you see this Thumb controls[^] ? You don't seem to have the resizing Thumb in your Template.
|
|
|
|
|
You right. I must look for some tutorial, how to use Thumb control and implement into my code. THX lot
|
|
|
|
|
The article I mentioned has it implemented.
|
|
|
|
|
Again... THX LOT! It works.
modified on Thursday, March 12, 2009 6:14 AM
|
|
|
|
|
Hello,
i´m trying to write a WPF User Control that looks like a matrix of LEDs.
I´ve created a RenderTargetBitmap over a DrawingVisual that looks like a matrix of quadratic dots.
The problem is that, when using the control, the dots are not displayed quadratic. The dots are displayed rectangular instead and very small.
I´ve also saved the created matrix bitmap in a bmp file. The matrix bitmap is correctly displayed if it is opened with a standard program.
How can i change rendering, so that the pixel of the matrix bitmap are displayed correctly?
In the past i´ve created such a matrix bitmap with MFC and BitBlt, ther was no such blur, if the bitmap was displayed by a control.
I used the following code in my control:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace TestWpf
{
public partial class MyControl : UserControl
{
private const double INCH_PER_UNIT = 1.0 / 96.0;
private const int BMP_DPI = 96;
private const double PIXEL_RAD = 1;
private const double PIXEL_SPACE = 1;
private static readonly Brush PIXEL_OFF_BRUSH = new SolidColorBrush(Color.FromRgb(150, 150, 150));
private static readonly Brush PIXEL_BACKGND_BRUSH = new SolidColorBrush(Colors.Black);
RenderTargetBitmap _pixelOffBmp;
RenderTargetBitmap _matrixBmp;
public MyControl()
{
InitializeComponent();
_pixelOffBmp = CreatePixelBmp(PIXEL_OFF_BRUSH);
_matrixBmp = CreateMatrixBmp();
SaveBmp(_matrixBmp);
}
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawImage(_matrixBmp, new Rect(0, 0, _matrixBmp.Width, _matrixBmp.Height));
}
RenderTargetBitmap CreatePixelBmp(Brush pixBrush)
{
double unitWidth, unitHeight;
unitWidth = 2 * PIXEL_RAD;
unitHeight = unitWidth;
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext dc = drawingVisual.RenderOpen())
{
dc.DrawRectangle(pixBrush, null, new Rect(0, 0, unitWidth, unitHeight));
}
int pixelWidth, pixelHeight;
pixelWidth = (int)(BMP_DPI * unitWidth * INCH_PER_UNIT);
pixelHeight = (int)(BMP_DPI * unitHeight * INCH_PER_UNIT);
RenderTargetBitmap bmp = new RenderTargetBitmap(pixelWidth, pixelHeight, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
bmp.Freeze();
return bmp;
}
RenderTargetBitmap CreateMatrixBmp()
{
int xMatrixPixel = 20 * 6;
int yMatrixPixel = 2 * 8;
double xUnitsMatrixBmp = xMatrixPixel * (2 * PIXEL_RAD + PIXEL_SPACE) + PIXEL_SPACE;
double yUnitsMatrixBmp = yMatrixPixel * (2 * PIXEL_RAD + PIXEL_SPACE) +PIXEL_SPACE;
int pixelWidthMatrixBmp = (int)(BMP_DPI * xUnitsMatrixBmp * INCH_PER_UNIT);
int pixelHeightMatrixBmp = (int)(BMP_DPI * yUnitsMatrixBmp * INCH_PER_UNIT);
this.Width = xUnitsMatrixBmp + BorderThickness.Left + BorderThickness.Right;
this.Height = yUnitsMatrixBmp + BorderThickness.Top + BorderThickness.Bottom;
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext dc = drawingVisual.RenderOpen())
{
dc.DrawRectangle(PIXEL_BACKGND_BRUSH, null, new Rect(0, 0, xUnitsMatrixBmp, yUnitsMatrixBmp));
double xOffset = 0;
double yOffset = PIXEL_SPACE;
for (int y = 0; y < yMatrixPixel; y++)
{
xOffset = PIXEL_SPACE;
for (int x = 0; x < xMatrixPixel; x++)
{
dc.DrawImage(_pixelOffBmp, new Rect(xOffset, yOffset, _pixelOffBmp.Width, _pixelOffBmp.Height));
xOffset += _pixelOffBmp.Width + PIXEL_SPACE;
}
yOffset += _pixelOffBmp.Height + PIXEL_SPACE;
}
}
RenderTargetBitmap bmp = new RenderTargetBitmap(pixelWidthMatrixBmp, pixelHeightMatrixBmp, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
bmp.Freeze();
return bmp;
}
void SaveBmp(BitmapSource bmpSource)
{
BmpBitmapEncoder bmp = new BmpBitmapEncoder();
bmp.Frames.Add(BitmapFrame.Create(bmpSource));
using (Stream stm = File.Create("foo.bmp"))
{
bmp.Save(stm);
}
}
}
}
Thanks,
Andy
|
|
|
|
|
This problem occurs due to WPFs resolution independence and most noticible with images like your example. An overview is at http://msdn.microsoft.com/en-us/library/aa970908.aspx and if you search with terms like "wpf pixel snapping" you'll find a lot of blog posts about the subject.
In the end I got your example working with a rather crude method.
public MyControl()
{
InitializeComponent();
RenderOptions.SetBitmapScalingMode(this,BitmapScalingMode.NearestNeighbor);
_pixelOffBmp = CreatePixelBmp(PIXEL_OFF_BRUSH);
_matrixBmp = CreateMatrixBmp();
SaveBmp(_matrixBmp);
LayoutUpdated += (s, e) => InvalidateVisual();
}
protected override void OnRender(DrawingContext drawingContext)
{
var pos = this.PointFromScreen(this.PointToScreen(new Point(0, 0)));
double x = pos.X - Math.Floor(pos.X);
double y = pos.Y - Math.Floor(pos.Y);
drawingContext.DrawImage(_matrixBmp, new Rect(1-x,1-y, _matrixBmp.Width, _matrixBmp.Height));
}
If you just want a repeating pattern ImageBrush might be what your after.
You may want to rethink your approach if you want to get the best out of WPF. For example each LED could be an individual control laid out inside a UniformGrid and have its appearance change using data binding. This sudoku tutorial might give you some ideas although I don't know what your control is going to display, I was thinking along the lines of a graph/audio spectrum.
|
|
|
|
|
Thanks a lot for your anwser, it helps a lot.
The matrix bitmap is now correctly displayed.
To update the LEDs, i use a second bitmap, the _contentBmp, with the same size as the matrix bmp.
Now the matrix bmp is copied into the content bmp and for each LED whch is on, a bmp that represent the on status is copied into the content bmp.
The content bmp is now used in the OnRender().
A timer in the main window sets and resets the LEDs every 200 milli seconds:
MyCtrl.PixelEnabled = !MyCtrl.PixelEnabled
RenderTargetBitmap _pixelOffBmp;
RenderTargetBitmap _pixelGreenBmp;
RenderTargetBitmap _matrixBmp;
RenderTargetBitmap _contentBmp;
int _xMatrixPixel;
int _yMatrixPixel;
double _xUnitsMatrixBmp;
double _yUnitsMatrixBmp;
private bool _pixelEnabled = false;
public bool PixelEnabled
{
get { return _pixelEnabled; }
set
{
_pixelEnabled = value;
UpdateDisplay();
}
}
RenderTargetBitmap CreateMatrixBmp()
{
......
RenderTargetBitmap bmp = new RenderTargetBitmap(pixelWidthMatrixBmp, pixelHeightMatrixBmp, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
bmp.Freeze();
_contentBmp = new RenderTargetBitmap(pixelWidthMatrixBmp, pixelHeightMatrixBmp, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);
return bmp;
}
void UpdateDisplay()
{
RenderTargetBitmap pixelBmp;
if (!PixelEnabled) pixelBmp = _pixelOffBmp;
else pixelBmp = _pixelGreenBmp;
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext dc = drawingVisual.RenderOpen())
{
dc.DrawImage(_matrixBmp, new Rect(0, 0, _xUnitsMatrixBmp, _yUnitsMatrixBmp));
double xOffset = 0;
double yOffset = PIXEL_SPACE;
for (int y = 0; y < _yMatrixPixel; y++)
{
xOffset = PIXEL_SPACE;
for (int x = 0; x < _xMatrixPixel; x++)
{
if (x % 5 == 0)
dc.DrawImage(pixelBmp, new Rect(xOffset, yOffset, pixelBmp.Width, pixelBmp.Height));
xOffset += pixelBmp.Width + PIXEL_SPACE;
}
yOffset += pixelBmp.Height + PIXEL_SPACE;
}
}
_contentBmp.Render(drawingVisual);
}
protected override void OnRender(DrawingContext drawingContext)
{
var pos = this.PointFromScreen(this.PointToScreen(new Point(0, 0)));
double x = pos.X - Math.Floor(pos.X);
double y = pos.Y - Math.Floor(pos.Y);
drawingContext.DrawImage(_contentBmp, new Rect(1-x, 1-y, _contentBmp.Width, _contentBmp.Height));
}
Now the problem is that the CPU usage is about 50%!
The cause that the LayoutUpdated Event calls InvalidateVisual().
But without calling InvalidateVisual() the Bitmap is not correctly displayed if the size of the main window is changed by user.
The Sudoku sample is very interesting and i will study it exactly by the next opportunity.
But i´m skeptic about the performance.
Earlier than the approach with bitmaps, i´ve created a LED matrix with Shapes and that takes a lot of performance.
I like to create the LED matrix for simulating a LED Display, which can display text and graphic, the text can flash or it can by marquee text etc.
The size of the display can be 240 x 48 pixel, so i have 11520 controls.
|
|
|
|
|
That is probably too many controls.
I just tried a few other methods for the offset that I thought might work but they produced artifacts.
Overlaying an ImageBrush of the gridlines on to normal content might be good enough or you could try writing a custom pixel shader. The one below is based on PixelateEffect but puts gaps inbetween. Shazzam is quite handy.
float HorizontalPixelCounts : register(C0);
float VerticalPixelCounts : register(C1);
sampler2D implicitInputSampler : register(S0);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float2 brickCounts = { HorizontalPixelCounts, VerticalPixelCounts };
float2 brickSize = 1.0 / brickCounts;
float2 brickNum = floor(uv / brickSize);
float2 centerOfBrick = brickNum * brickSize + brickSize / 2;
float2 edge = uv - (brickNum * brickSize);
if(edge.x < 0.01 || edge.y < 0.01)
{
return float4(0,0,0,0);
}
return tex2D(implicitInputSampler, centerOfBrick);
}
|
|
|
|
|
Thanks for the hint about PixelShader.
I´ve played around with the Pixel Shader Effects Library, it´s very interesting.
The test of your 'GapEffect' shows, that the gaps are not equally spaced.
I´m not familiar with that HLSL, so i can´t test if the gaps can made equally spaced by adjusting the PixelShader or if there is no chance to do this with PixelShader.
It seems to me that to learn HLSL is very time-consuming.
It´s a little bit frustrating that a new technology like WPF, which can do much comlex things with a few commands makes a lot of problems by doing such basic things like drwing rectangles with defined size. These things are not complex to do with older technologies.
|
|
|
|
|
Hi,
I'm trying to bind an own made attached property but I can't get it to work. I know how to do it with a normal dependency property and I have found help on the internet that concerns canvas attached properties but that isn't exactly what I need.
XAML code:
<Button Tooltip="Edge Color" IsEnabled="{Binding Path=(SCOLOR), ElementName=nsifCanvas, Mode=OneWay, Converter={StaticResource convGraphicColour}}">
<Image Source="Resources\Icons\LineColorHS.png" Style="{StaticResource IconStyle}"/>
</Button>
Next is my attached property. The value in it comes from an enum "GraphicColour". That enum just contains 2 values (for the moment) that defines the kind of colorscheme a graphic has: C (colored) and M (monochrome). I want that a button on my GUI gets disabled if I select a "graphic" (actually a UIElement) that is monochrome (value "M"). When the value is "C", the button must be enabled so the user can select a color. So I want that the button gets enabled or disables depending on the graphic I have selected at the moment. With the code I have now, the button just stays disabled! The converter in XAML converts the enum value to a boolean (true if graphic can contain colors, else false).
/// <summary>
/// Graphic color.
/// </summary>
public static readonly DependencyProperty SCOLORProperty;
/// <summary>
/// Get graphic SCOLOR.
/// </summary>
public static GraphicColour GetSCOLOR(Annotation graphic)
{
return (GraphicColour)graphic.GetValue(SCOLORProperty);
}
/// <summary>
/// Set graphic SCOLOR.
/// </summary>
public static void SetSCOLOR(Annotation graphic, GraphicColour value)
{
graphic.SetValue(SCOLORProperty, value);
}
static NSIFCanvas()
{
SCOLORProperty = DependencyProperty.RegisterAttached(
"SCOLOR",
typeof(GraphicColour),
typeof(NSIFCanvas),
new PropertyMetadata(GraphicColour.M));
}
I have no idea how to connect the enable propertie of the button to that attached property of the graphic selected on the moment. Is this possible and do you maybe have an example? (I can set and get the property value in code for a certain graphic.)
Thanks!
|
|
|
|
|
Does your converter get called and with the proper values ? I am suspecting databinding problem to the canvas object. Did you see in the output window if you get any databinding errors logged ? I couldn't run your example, it says Annotation does not have a SetValue/GetValue.
Secondly, you might be having a reason, but the scenario you have mentioned would be covered with a normal dependency property, why do you want to make it an attached property ?
|
|
|
|
|
The converter only gets called when the program starts. GetSCOLOR never gets called. The biggest problem is that I don't exactly know how to bind an attached property so I guess that is the problem. I don't get any errors.
Annotation is a control that I wrote to contain graphics (rectangles, circles, ... drawn by the user). That control gets added to a canvas (nsifCanvas) multiple times. Every annotation control has the property SCOLOR (so some can be monochrome and other can contain colors). That is the reason why I use an attached property. When I click on an annotation, that one gets active and depending on the property, a button in a toolbar must be enabled (if the annotation can contain colors) or disabled (monochrome annotation).
Next is a part of the XAML code. In nsifCanvas the user can add Images and also Annotations (the control where the user can add graphics). Everything works except the binding to the attached property.
<Grid>
<DockPanel>
<!-- Add toolbar tray to window -->
<ToolBarTray DockPanel.Dock="Top" Orientation="Horizontal" IsLocked="False">
<!-- tbTools -->
<ToolBar Name="tbTools" Band="1" BandIndex="1">
<Button ToolTip="Edge Color" IsEnabled="{Binding Path=(SCOLOR), ElementName=nsifCanvas, Mode=OneWay, Converter={StaticResource convGraphicColour}}">
<Image Source="Resources\Icons\LineColorHS.png" Style="{StaticResource IconStyle}"/>
</Button>
</ToolBar>
</ToolBarTray>
<!-- Window -->
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<controls:NSIFCanvas x:Name="nsifCanvas" Background="LightGray">
<!-- Add children in code to populate canvas -->
</controls:NSIFCanvas>
</ScrollViewer>
</DockPanel>
</Grid>
So, I guess I am correct to use an attached property? And if it is correct, does anybody has an example how to bind it? I guess the binding needs to contact the Get function but like I said, the way I do it now, the program doesn't get there. The elementname in the binding is nsifCanvas. nsifCanvas contains the property but the property depends on the annotation control that is a child of that canvas.
I hope someone has an example or something.
Thx
|
|
|
|
|
Ok, here are my thoughts on this.
Pauwels Bart wrote: don't exactly know how to bind an attached property so I guess that is the problem
I think the binding syntax is correct.
"The value which an element has for an attached property is stored by that element, not by the element which exposes the attached property." - Josh Smitt[^]
Relating to your scenario. You would have the SCOLOR attached property in each of the Annotation object. And I am sure that is not what you are expecting ?
What you want is, SCOLOR behave like a "SelectedItem" or "SelectedColor". I would suggest, make a dependency property named "SelectedAnnotation" in your Canvas which will hold the currently selected Annotation object. When an annotation object is selected, set this DP to the selected annotation object.
Bind the button to the SelectedItem property in NFSICanva. Something like this,
IsEnabled="{Binding Path=SelectedAnnotation.SCOLOR , ElementName=nsifCanvas, Mode=OneWay, Converter={StaticResource convGraphicColour}}"
Pauwels Bart wrote: GetSCOLOR never gets called.
Take a look here Debugging dependency properties[^]
|
|
|
|
|