Silverlight zoom in Out of Browser - silverlight

Is it possible to use Zoom functionality of whole Silverlight application (CTRL+MouseWheel / zoom in browser) in Out of Browser mode?

You can use the following in your Application_Startup:
RootVisual = new WebBrowser() {Source = new Uri(Current.Host.Source, "../")};

Ok.. I have implemented this code for "Zoom In" and "Zoom Out" Button Click.
In Button Click Event :
commonwidth = commonwidth + (commonwidth * zoomPercent / 100) //For Zoom Out
commonwidth = commonwidth + (commonwidth * zoomPercent / 100) //For Zoom In
Then Call this Method :
Private Sub ChangZoom()
If Not fresult Is Nothing Then
If fresult.Count() > 0 Then
Dim mainFrame As StackPanel
mainFrame = fresult(_currentPage)
Dim docBorder As Border
docBorder = mainFrame.Children(1)
Dim docImage As FrameworkElement
docImage = docBorder.Child
If Not docImage Is Nothing Then
Dim actualWidth As Double
Dim actualHeight As Double
actualWidth = commonwidth 'Me.ActualWidth - 30
actualHeight = Me.ActualHeight
Dim newHeight As Double
newHeight = actualWidth * docImage.Height / docImage.Width
docImage.Width = actualWidth
docImage.Height = newHeight
RenderResutlFrame(_currentPage)
End If
End If
End If
End Sub
Public Property ImageUrl As String Implements IDocumentViewer.ImageUrl
Get
Return _imageUrl
End Get
Set(ByVal value As String)
_imageUrl = value
'Me.Dispatcher.BeginInvoke(AddressOf OnInitialized)
End Set
End Property

Related

How to Resize height and width of a image dynamically in SSRS Report?

I want to resize image height and width dynamically in SSRS report based on expression but there is no expression option available in image size properties its only take numeric values.
I want resize my image like below c# code.
private void GetImageSize(string path)
{
try
{
System.Drawing.Image image = System.Drawing.Image.FromFile(path);
if (image != null)
{
System.Drawing.Image imageResized = ((System.Drawing.Image)image.Clone());
int resizeWidth = 0;
int resizeHeight = 0;
bool heightIsLongerDimension = (imageResized.Height > imageResized.Width);
float heightInches = (float)(imageResized.Height / imageResized.VerticalResolution);
float widthInches = (float)(imageResized.Width / imageResized.HorizontalResolution);
if (heightIsLongerDimension)
{
resizeHeight = (int)(imageResized.VerticalResolution * 3);
//resizeWidth = Convert.ToInt32((((heightInches - 3) / heightInches) * widthInches) * imageResized.HorizontalResolution);
resizeWidth = Convert.ToInt32((((float)imageResized.Width) / (float)imageResized.Height) * imageResized.HorizontalResolution) * 3;
}
else
{
resizeWidth = (int)(imageResized.HorizontalResolution * 3);
//resizeHeight = Convert.ToInt32((((widthInches - 3) / widthInches) * heightInches) * imageResized.VerticalResolution);
resizeHeight = Convert.ToInt32((((float)imageResized.Height) / (float)imageResized.Width) * imageResized.VerticalResolution) * 3;
}
//image height and width set in pixel
Image1.Height = resizeHeight;
Image1.Width = resizeWidth;
//image height and width set in inches
float width = (float)(Math.Round((resizeWidth / imageResized.HorizontalResolution), 1));
float height = (float)(Math.Round((resizeHeight / imageResized.VerticalResolution), 1));
}
}
catch
{
throw;
}
}
Use custom code in your report to define following vb.net function:
Public Function ResizeImage(ByVal picbytes as Byte()) As Byte()
Try
Dim ms as System.IO.MemoryStream = Nothing
Dim rms as System.IO.MemoryStream
Dim bm as System.Drawing.Bitmap
ms = new System.IO.MemoryStream(picbytes)
bm = new System.Drawing.Bitmap(ms)
Dim newWidth As Integer
Dim newHeight As Integer
Dim originalWidth As Integer =bm.Width
Dim originalHeight As Integer = bm.Height
Dim percentWidth As Single = CSng(1280) / CSng(originalWidth)
Dim percentHeight As Single = CSng(960) / CSng(originalHeight)
Dim percent As Single = IIf(percentHeight < percentWidth, percentHeight, percentWidth)
newWidth = CInt(originalWidth * percent)
newHeight = CInt(originalHeight * percent)
Dim newImage As System.Drawing.Image = New System.Drawing.Bitmap(newWidth, newHeight)
Using graphicsHandle As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newImage)
graphicsHandle.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
graphicsHandle.DrawImage(bm, 0, 0, newWidth, newHeight)
End Using
Dim ms2 = new System.IO.MemoryStream()
newImage.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim bytes = ms2.ToArray()
Return bytes
Catch ex As Exception
Return nothing
End Try
End Function
reference in report the System.Drawing .NET assembly.
then you can reuse function in your expression like:
Code.ResizeImage(Fields!Bild.Value)
If you click on image box and right click you will see properties option.
You could click image and then hit F4 properties window will show.
There you have Size option. You will see various option there. By default fit proportionally is automatically selected.
You might want to change that to fit to size.
This will resize your image automatically.
Also below link will help you more in details. Have a look at it.
https://www.tutorialgateway.org/display-image-in-ssrs-report/

Convert high DPI images to lower DPI for printing throws OutOfMemoryException

I have some images that I'am trying to print out. Those images can come in varying format, from different DPI's to different formats (JPEG, PNG, etc.)
Now what I've done for now, is to load the image into my application and try and
convert the dpi to say 96. However in this process i get an OutOfMemoryException, and I'm not sure how to continue.
Private Sub PrintImage(Optional providedPrintDialog As PrintDialog = Nothing)
Dim objPrintDialog As PrintDialog
If providedPrintDialog IsNot Nothing Then
objPrintDialog = providedPrintDialog
Else
objPrintDialog = New PrintDialog()
End If
Dim myPanel As New StackPanel
myPanel.Margin = New Thickness(15)
Dim myImage As New Controls.Image
Dim tempBitmapImage = ConvertBitmapToXDPI(Me.SelectedFileViewModel.File.GetPath, 96)
Dim tempBitmapImageWidth As Integer = CInt(objPrintDialog.PrintableAreaWidth)
' A4 max width = 793
If tempBitmapImage.Width > tempBitmapImageWidth Then
myImage.Stretch = System.Windows.Media.Stretch.Uniform
Else
myImage.Stretch = System.Windows.Media.Stretch.None
End If
myImage.Source = tempBitmapImage
myPanel.Children.Add(myImage)
myPanel.Measure(New System.Windows.Size(objPrintDialog.PrintableAreaWidth, objPrintDialog.PrintableAreaHeight))
myPanel.Arrange(New Rect(New System.Windows.Point(0, 0), myPanel.DesiredSize))
objPrintDialog.PrintVisual(myPanel, "Billede") ' <- OutOfMemoryException thrown here
End Sub
Private Function ConvertBitmapToXDPI(path As String, newDpi As Integer) As BitmapSource
Using bitmap As Bitmap = DirectCast(System.Drawing.Image.FromFile(path), Bitmap)
Dim bitmapData = bitmap.LockBits(New System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.[ReadOnly], bitmap.PixelFormat)
Dim bmSource = BitmapSource.Create(
bitmapData.Width,
bitmapData.Height, 96, 96, PixelFormats.Bgr24, Nothing,
bitmapData.Scan0,
bitmapData.Stride * bitmapData.Height,
bitmapData.Stride)
bitmap.UnlockBits(bitmapData)
Return bmSource
End Using
End Function
There is no need to do any DPI conversion. Just create a DrawingVisual and draw a BitmapImage into it with an appropriate size:
Dim image As New BitmapImage()
image.BeginInit()
image.CacheOption = BitmapCacheOption.OnLoad
image.UriSource = New Uri(path)
image.EndInit()
image.Freeze()
Dim size As New Size()
If image.Width < printDialog.PrintableAreaWidth Then
size.Width = image.Width
size.Height = image.Height
Else
size.Width = printDialog.PrintableAreaWidth
size.Height = size.Width / image.Width * image.Height
End If
Dim visual As New DrawingVisual()
Using dc As DrawingContext = visual.RenderOpen()
dc.DrawImage(image, New Rect(size))
End Using
printDialog.PrintVisual(visual, "Billede")

Return a value that gives the relative position of a GridSplitter in a WPF application

In a WPF application the user can double click a line in a DataGrid to open a new page that contain tabs with grids - some of these have GridSplitters like this
Private Function CentreGrid() As Grid
Try
Dim vGrid As New Grid
For i As Integer = 0 To 2
Dim vCol As New ColumnDefinition
If i = 1 Then
vCol.Width = New GridLength(5, GridUnitType.Auto)
End If
vGrid.ColumnDefinitions.Add(vCol)
Next
Dim vLeftGrid As Grid = LeftGrid()
Grid.SetColumn(vLeftGrid, 0)
vGrid.Children.Add(vLeftGrid)
Dim vGridSplitter As New GridSplitter
With vGridSplitter
.VerticalAlignment = Windows.VerticalAlignment.Stretch
.HorizontalAlignment = Windows.HorizontalAlignment.Center
.ResizeBehavior = GridResizeBehavior.PreviousAndNext
.Background = New SolidColorBrush(Colors.Blue)
.Width = 5
.Margin = New Thickness(5)
End With
Grid.SetColumn(vGridSplitter, 1)
vGrid.Children.Add(vGridSplitter)
Dim vRightGrid As Grid = RightGrid()
Grid.SetColumn(vRightGrid, 2)
vGrid.Children.Add(vRightGrid)
Return vGrid
Catch ex As Exception
EmailError(ex)
Return Nothing
End Try
End Function
As everything is generated dynamically from code-behind is there any method to get a handle on the relative grid position that has been changed by the user so that when the page is closed and another instance opened the GridSplitter can be in the same relative position that the user selected beforehand?
Thanks

wpf processing data before binding

I have a canvas that shows an audio waveform, which is made using a lot of Lines. Each line is Tagged with it's time code so I can identify where in the audio it is.
I want to put a rectangle on the canvas based on data stored in an observable collection.
Basically, Timespan start and end points so I can show a block of audio.
The problem I'm having is that to show the rectangle, I have to know the Canvas left value and width.
I can get these by scanning through the canvas children until I find the correct line and getting its X1 value, but I don't know how to do it in a binding.
I want to bind the observable collection ItemsControl so I can show the rectangles on the canvas.
Is it possible to bind to a function or something that would do the calculations based on the data in the observable collection?
XAML:
<ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<Canvas Name="waveform" >
<ItemsControl Name="RectArea"> <!-- Where I hope to have the rectangles appear on top of the waveform canvas -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Stroke="Yellow" Fill="Yellow" Opacity="0.2" Height="200" Width="{Binding Width}" Canvas.Left="{Binding Left}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Canvas>
</ScrollViewer>
Creating the waveform:
Dim seconds As Integer = 0
lines = New Dictionary(Of String, Line)
Using Reader As New AudioFileReader(openfile.FileName)
Dim samples = Reader.Length / (Reader.WaveFormat.Channels * Reader.WaveFormat.BitsPerSample / 8)
Dim f = 0.0F
Dim max = 0.0F
Dim batch As Integer = Math.Max(10, samples / samplecount)
Dim mid = 100
Dim yScale = 100
Dim buffer(batch) As Single
Dim read As Integer
Dim xPos = 0
read = Reader.Read(buffer, 0, batch)
While read = batch
For n As Integer = 0 To read
max = Math.Max(Math.Abs(buffer(n)), max)
Next
Dim line As New Line
line.X1 = xPos
line.X2 = xPos
line.Y1 = mid + (max * yScale)
line.Y2 = mid - (max * yScale)
line.Tag = Reader.CurrentTime
line.StrokeThickness = 1
line.Stroke = Brushes.DarkGray
AddHandler line.MouseDown, AddressOf Line_MouseDown
waveform.Children.Add(line)
' lines is a dictionary that holds all of the line information. nothing is bound to it, it just allows me to search against time code so I can highlight the line as the audio is playing'
If Not lines.ContainsKey(Reader.CurrentTime.Hours.ToString().PadLeft(2, "0") & Reader.CurrentTime.Minutes.ToString().PadLeft(2, "0") & Reader.CurrentTime.Seconds.ToString().PadLeft(2, "0") & Reader.CurrentTime.Milliseconds.ToString().PadLeft(3, "0").Substring(0, 1)) Then
lines.Add(Reader.CurrentTime.Hours.ToString().PadLeft(2, "0") & Reader.CurrentTime.Minutes.ToString().PadLeft(2, "0") & Reader.CurrentTime.Seconds.ToString().PadLeft(2, "0") & Reader.CurrentTime.Milliseconds.ToString().PadLeft(3, "0").Substring(0, 1), line)
End If
' Draw a tall black line and show timecode every 10 seconds to make it easier to see where you are on the code '
If Reader.CurrentTime.TotalSeconds > (seconds + 10) Then
seconds = Reader.CurrentTime.TotalSeconds
line = New Line
line.X1 = xPos
line.X2 = xPos
line.Y1 = mid + yScale
line.Y2 = mid - yScale
line.StrokeThickness = 1
line.Stroke = Brushes.Black
waveform.Children.Add(line)
Dim textblock As New TextBlock
textblock.Text = Reader.CurrentTime.Hours.ToString().PadLeft(2, "0") & ":" & Reader.CurrentTime.Minutes.ToString().PadLeft(2, "0") & ":" & Reader.CurrentTime.Seconds.ToString().PadLeft(2, "0") & "," & Reader.CurrentTime.Milliseconds.ToString().PadLeft(3, "0")
textblock.Foreground = Brushes.Black
Canvas.SetLeft(textblock, xPos)
Canvas.SetTop(textblock, yScale)
waveform.Children.Add(textblock)
End If
max = 0
xPos += 1
read = Reader.Read(buffer, 0, batch)
End While
waveform.Width = xPos
End Using
ObservableCollection:
Imports System.ComponentModel
Imports System.Collections.ObjectModel
Public Class ocAudioSelection
Implements INotifyPropertyChanged
Private _Changed As Boolean
Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub OnPropertyChanged(ByVal Propertyname As String)
On Error GoTo sError
If Not Propertyname.Contains("Changed") Then
Changed = True
End If
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Propertyname))
Exit Sub
sError:
MsgBox(ErrorToString)
End Sub
Public Property Changed() As Boolean
Get
Return _Changed
End Get
Set(ByVal value As Boolean)
If _Changed <> value Then
_Changed = value
OnPropertyChanged("Changed")
End If
End Set
End Property
Private _startTime As String
Private _endTime As String
Public Sub New()
End Sub
Public Sub New(startTime As String)
_startTime = startTime
End Sub
Public Sub New(startTime As String, endTime As String)
_startTime = startTime
_endTime = endTime
End Sub
Public Property StartTime As String
Get
Return _startTime
End Get
Set(value As String)
If value <> _startTime Then
_startTime = value
OnPropertyChanged("StartTime")
End If
End Set
End Property
Public Property EndTime As String
Get
Return _endTime
End Get
Set(value As String)
If value <> _endTime Then
_endTime = value 'TimeSpan.Parse()
OnPropertyChanged("EndTime")
End If
End Set
End Property
End Class

Anchoring a Form in vb.net 2010

my question is how to anchor a child mdi to its parent mdi so that each time the user expands or minimizes the parent form the child form automatically follows. I already tried to use the resize function in form but it doesn't help
thanks all help is appriciated
See below - a quick version I wrote, which seems to handle most anchoring scenarios. You may need to polish this code a bit. But this should get you started:
Imports System.ComponentModel
Public Class MDIChildForm
Dim p_eMyAnchor As AnchorStyles
Dim p_mdiParent As Form
Dim p_iOldHeight, p_iOldWidth As Integer
<DefaultValue(AnchorStyles.Left Or AnchorStyles.Top)>
Public Property MyAnchor As AnchorStyles
Get
Return p_eMyAnchor
End Get
Set(value As AnchorStyles)
p_eMyAnchor = value
chkAnchorTop.Checked = (p_eMyAnchor And AnchorStyles.Top)
chkAnchorLeft.Checked = (p_eMyAnchor And AnchorStyles.Left)
chkAnchorRight.Checked = (p_eMyAnchor And AnchorStyles.Right)
chkAnchorBottom.Checked = (p_eMyAnchor And AnchorStyles.Bottom)
End Set
End Property
Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
p_eMyAnchor = AnchorStyles.Left Or AnchorStyles.Top
End Sub
Public Sub ShowAsMDIChild(mdiParent As Form)
p_mdiParent = mdiParent
Me.MdiParent = mdiParent
AddHandler mdiParent.ResizeBegin, AddressOf MDIParentForm_ResizeBegin
AddHandler mdiParent.ResizeEnd, AddressOf MDIParentForm_ResizeEnd
Me.Show()
End Sub
Private Sub MDIParentForm_ResizeBegin(sender As Object, e As EventArgs)
Dim frm As Form = DirectCast(sender, Form)
p_iOldWidth = frm.Width
p_iOldHeight = frm.Height
End Sub
Private Sub MDIParentForm_ResizeEnd(sender As Object, e As EventArgs)
Dim parentForm As Form = DirectCast(sender, Form)
'handling for horizontal anchoring
Dim deltaWidth As Integer = parentForm.Width - p_iOldWidth
Dim fAnchorLeft As Boolean = p_eMyAnchor And AnchorStyles.Left
Dim fAnchorRight As Boolean = p_eMyAnchor And AnchorStyles.Right
Select Case fAnchorLeft
Case True : If fAnchorRight Then Me.Width += deltaWidth
Case False
Dim coef As Single = If(fAnchorRight, 1, 0.5)
Me.Left += deltaWidth * coef
End Select
'handling for vertical anchoring
Dim deltaHeight As Integer = parentForm.Height - p_iOldHeight
Dim fAnchorTop As Boolean = p_eMyAnchor And AnchorStyles.Top
Dim fAnchorBottom As Boolean = p_eMyAnchor And AnchorStyles.Bottom
Select Case fAnchorTop
Case True : If fAnchorBottom Then Me.Height += deltaHeight
Case False
Dim coef As Single = If(fAnchorBottom, 1, 0.5)
Me.Top += deltaHeight * coef
End Select
End Sub
End Class
For horizonal anchoring, the following rules are used:
left - nothing happens (default behavior)
left and right - expand width to parent form width delta
right - move left by parent form width delta
no anchor - move left by half parent form width delta.
Same principle applies to vertical anchoring, for top and bottom respectively.
You can get the full project to play with here (Mediafire).
try this:
Me.Anchor = AnchorStyles.Bottom
Me.Anchor = AnchorStyles.Left
Me.Anchor = AnchorStyles.Right
Me.Anchor = AnchorStyles.Top

Resources