How to set the Telerik Blazor FileStream Position to 0? - telerik

Anyone know how to set the Position of a Telerik Blazor FileInfoStream to 0, so that I can Copy the stream twice?
The Seek Method and so on do not work: https://docs.telerik.com/blazor-ui/knowledge-base/fileselect-stream-exception
Thx

Related

Best way to show many mini versions of painted InkCanvas in UWP

I have a problem to depict many mini-versions of my InkCanvas. In my app it is possible to write or draw on a InkCanvas. Now I want to depict all created InkCanvas in a GridView.
But with mini versions in this GridView i can not create enough mini versions.
I tested it with 36 mini versions and after I show one and navigate back, the App crashs everytime by rendering the same mini InkCanvas with the error: Insufficient Memory. So I searched an found this post:
Insufficient memory to continue the execution of the program when trying to initialize array of InkCanvas in UWP
I checked the Memory workload:
var AppUsageLevel = MemoryManager.AppMemoryUsageLevel;
var AppMemoryLimit = MemoryManager.AppMemoryUsageLimit;
and the memory has enough free space. (is this a bug?)
So I tried to render a image from my grid with a InkCanvas but the strokes were not rendered and all pictures were empty. ( can I save Memory this way?)
So now my question is:
Can someone tell me how to solve this problem? And what is the best way?
Thank you very much in advance!
Agredo
If you want to preview your drawings, better way is to render them to bitmap and show this bitmaps in grid instead of multiple complex controls InkCanvas is.
Here is some code to render inks to bitmap from another SO Answer:
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Colors.White);
ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
}
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
You also need to add Win2D.uwp nuget package to your project.

ITextSharp open pdf at page index with zoom

I've some pdf with a lot of sheets.
I made a serach in those files and I've a list with the page numers where the string is found.
Now I have to open those files to the exact page, perhaps with a zoom and a rectangle that shows the result.
Any idea?
P.S. The code I use for reading and open the pdf files is:
Dim reader As New PdfReader(FileToOpen)
Dim stamper As New PdfStamper(reader, New System.IO.FileStream("j:\Zoom.pdf", FileMode.Open, FileAccess.ReadWrite))
Dim pdfDest As New PdfDestination(PdfDestination.FITH)
Dim OA As PdfAction = PdfAction.GotoLocalPage(2, pdfDest, stamper.Writer)
stamper.Writer.SetOpenAction(OA)
stamper.Close()
reader.Close()
I almost closed this question as a duplicate of How to set initial view properties? because I found the question in the official iText documentation with a link to Stack Overflow: How to set initial view properties?
Of as a duplicate of How to set zoom level to pdf using iTextSharp? (see How to set the zoom level of a PDF using iTextSharp?)
However, I see that the answer on the official iText web site is better than the answer on Stack Overflow, because it combines everything you need to know.
In short: you need an open action:
//Create a destination that fit's width (fit horizontal)
var D = new PdfDestination(PdfDestination.FITH);
//Create an open action that points to a specific page using this destination
var OA = PdfAction.GotoLocalPage(1, D, stamper.Writer);
//Set the open action on the writer
stamper.Writer.SetOpenAction(OA);
Obviously, you can choose to create another destination when you define D.
If you are by any chance using iText 7, then you should read chapter 7 of the iText 7: Building Blocks tutorial to learn about the open action, and chapter 6 where all the possible destinations (XYZ, FitH, FitB,...) are explained.
Please read the documentation before posting a question.

WP7 MediaElement Unable to Reposition the stream

I am using MediaElement for video playback in my app. I have added controls for play, pause, rewind and forward. In the forward button's event handler, I am trying to forward the video clip for 5 seconds. the code I have used to do that is given below.
if(myMediaElement.CanSeek)
{
myMediaElement.Position = TimeSpan.FromSeconds(2);
myMediaElement.Play();
}
But the video clip does not forward, instead it stops the video playback. Can anyone please tell me what is going wrong.
You need to start playing the stream before you can set the position.
Move the call to CanSeek and the setting of the position until after the MediaOpened event has been raised.
See the remarks in MSDN http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.position(v=VS.95).aspx for confirmation.
Using valueconverter sample here, with Slider adjustments, to get the positions
http://diggthedrazen.com/2011/07/08/using-an-ivalueconverter-to-create-a-player-with-a-seek-bar-on-windows-phone/

Image gets blurred when added to Excel through JXL

I use the JXL API to add an Image to an Excel file. Libraries used:
jcommon (1.0.14)
jfreechart (1.0.13)
jxl (2.6.10)
// chartImage is of type BufferedImage
com.KeyPoint.PngEncoder encoder = new com.KeyPoint.PngEncoder(chartImage, true, 0, 0);
jxl.write.WritableImage image = new jxl.write.WritableImage(0, 2, (chartImage.getWidth()/100),16,
encoder.pngEncode());
sheet.addImage(image);
The problem is that the WritableImage constructors take widths and heights in terms of rows and columns (width: column 0 to column chartImage.getWidth()/100, height: row 2 to row 16). This causes the chart image to blur.
How do I get the original image into the Excel using JXL? Kindly help. Thanks! :-)
The issue lies with either the compression used in Excel or the encoder you used.
A solution that works is drawing the chart larger than the intended image, and then letting Excel do the down-scaling. This ensures clarity although a chart-filled workbook will be much larger than before.
AFAIK that is the only solution to the problem. I have had similar issues with Word and PowerPoint, and the solution seems to be upscaling.
When you scale the chart you should note that the font sizes need to be changed too.
Don't use PngEncoder directly. Instead, use the relevant ChartUtilities method, which will find the Sun/Oracle PNG encoder if available.

Axapta: How to load an image from a file on disk into a grid with a Window Control

I have been trying:
to load an image into a window control with a datamethod that loads the file into a bitmap, returning a bitmap. This makes Axapta Crash.
When doing the same but returning an image does not do anything.
using the "active" method on the data source has some success if I set the "imagename" to the filename and the autodecalaration property to "true" on the window component. The Grid does not refresh properly and the pictures dissappear and reappear (while you change rows) for a while until it seems satisfied and then it stays on the screen.
Any help with this will be greatly appreciated.
I found the answer - it would help if the documentation was better.
On the WindowControl: Simply link the datasource to the table containing the field with the string(text) of the full path and filename; and link the datafield to that field. Hey - it works like a charm. I have been trying to return images and bitmaps all the time from a datamethod.

Resources