logo
down
shadow

All images in XPS look identical when loaded from a byte array


All images in XPS look identical when loaded from a byte array

Content Index :

All images in XPS look identical when loaded from a byte array
Tag : wpf , By : shehan
Date : November 28 2020, 09:01 AM

hope this fix your issue
Investigation shows, that when Image.Source is assigned to a byte array, ImageSourceConverter class is used by WPF to convert the array to the proper ImageSource. BitmapFrame.Create() is called inside to perform the actual bitmap loading. So this code have absolutely the same effect:
var view = new StackPanel
{
    Orientation = Orientation.Horizontal,
    Children =
    {
        new Image { Source = BitmapFrame.Create(new MemoryStream(pic1Bytes), BitmapCreateOptions.None, BitmapCacheOption.Default) },
        new Image { Source = BitmapFrame.Create(new MemoryStream(pic2Bytes), BitmapCreateOptions.None, BitmapCacheOption.Default) },
    }
};
using (var xps = new XpsDocument(@"1.xps", FileAccess.Write))
    XpsDocument.CreateXpsDocumentWriter(xps).Write(view);
private static BitmapSource ImageFromBytes(byte[] bytes)
{
    var bmp = new BitmapImage();
    using (var stream = new MemoryStream(bytes))
    {
        bmp.BeginInit();
        bmp.CacheOption = BitmapCacheOption.OnLoad;
        bmp.StreamSource = stream;
        bmp.EndInit();
    }
    return bmp;
}

// usage example:
new Image { Source = ImageFromBytes(picBytes) }

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

What are the other ways to determine two file contents are identical except for byte-by-byte checking?


Tag : algorithm , By : Jet Thompson
Date : March 29 2020, 07:55 AM
will be helpful for those in need The only proven way is to do a byte-by-byte compare. It's also the fastest way and you can cut the memory usage all the way down to 2 bytes if you read a byte at a time. Reading larger chunks at a time is beneficial for performance though.
Hashing will also work. Due to the pigeonhole principle there will be a small chance that you'll get false positives but for all intents and purposes it is negligible if you use a secure hash like SHA. Memory usage is also small, but performance is less than byte-by-byte compare because you'll have the overhead of hashing. Unless you can reuse the hashes to do multiple compares.

Why comparing two identical byte array takes different amount of time to complete ?


Tag : chash , By : user121405
Date : March 29 2020, 07:55 AM
This might help you You get different times because the stopwatch resolution is too low to measure so little code. Eventhough the resolution of the stopwatch is very high, the CPU still have time to run thousands of instructions between every tick of the stopwatch.
During the execution of the method the stopwatch will only go a few ticks, so the resulting times will vary very much.

converting multiple images as a byte array back into images xamarin forms


Tag : arrays , By : SilverRuby
Date : March 29 2020, 07:55 AM
seems to work fine You dont have to convert anything. you can simply use your image url path
var image = new Image();
    image.Source = new UriImageSource {
    Uri = new Uri("YOUR IMAGE URL"),
    CachingEnabled = true,
    CacheValidity = new TimeSpan(4,0,0,0)
    };
Content = image;
var image = new Image(); 
    image.Source = ImageSource.FromStream(() => new MemoryStream(YOURBYTES));
Content = image;

C# byte array to image not working with identical byte arrays


Tag : chash , By : Mark W
Date : March 29 2020, 07:55 AM

Identical images have different pixel data when loaded as a QImage in Release


Tag : cpp , By : Puneet Madaan
Date : March 29 2020, 07:55 AM
hop of those help? I think I can see what's going on here.
Your image is 8-bit grayscale with a width of 127 pixels. All those indices where the differences occur are multiples of 128 (minus 1, i.e the last column in a 128-byte row). Since you have obtained the raw image bits, it's most likely that row data in the image is aligned (commonly 2 or 4 bytes).
Related Posts Related QUESTIONS :
  • WPF datagrid column heading span more than once column
  • WPF DatePicker IsEnabled property not changing appearance
  • Can a custom WPF control implement the IsDefault property
  • Strange Behaviour WPF TreeView ItemContainerStyle and ItemTemplate
  • what's the difference between MVVM and Prism v2
  • WPF DataGrid multiselect binding
  • Bind two Textboxes to one and the same Checkbox
  • How to bind a DataTemplate datatype to a View which receives ViewModels a dependency injected by DI
  • How to start using MvvmLight on a .net core 3 WPF app?
  • Set Button Click handler with a DataTrigger
  • Remove lines between rows in WPF grid
  • How we can set scrollbar on last row of data grid in WPF
  • WPF change ItemsPanel and ItemTemplate in code behind
  • Locating binding errors
  • Databinding an enum to a ComboBox in WPF + MVVM
  • Rendering EMF/WMF images in WPF XAML
  • Using Unit of Work design pattern / NHibernate Sessions in an MVVM WPF
  • Implementing commands in MMVM
  • What is the WPF equivalent for the FlowLayoutPanel?
  • Button ControlTemplate and rounded corners
  • Need help understanding WPF MeasureOverride and ArrangeOverride infinity and 0 sizes
  • Key strokes in wpf window hosted in MFC ActiveX running in Internet Explorer
  • WPF - simple relative path - FindAncestor
  • Possible to InvalidateVisual() on a given region instead of entire WPF control?
  • Xaml parse exception is thrown when i define a duplex contract
  • Horizonatal Scrolling in FlowDocumentScrollViewer
  • Setting properties of auto-generated listboxitem
  • ContentTemplateSelector is only called one time showing always the same datatemplate
  • Why do I get a NullReferenceException when using a style on a ContentPresenter?
  • Using TextOptions.TextFormattingMode with FormattedText
  • Setting a theme in WPF
  • How to make an invisible button to run a command
  • WPF DialogResult declaratively?
  • WPF Using commands to slow to update UI controls
  • DataGridCheckBoxColumn immediate binding
  • HeaderedContentControl ItemsSource
  • Can't override a global WPF style that is set by TargetType on a single specific control
  • wpf cancel backgroundworker on application exits
  • WPF charting/visualization of realtime data
  • bind a WPF datagrid to a datatable
  • Is there a way to do simple calculations in a xaml element binding statement other than using a converter?
  • WPF How to get window reference that is loaded from a page that is into it?
  • WPF Check/Uncheck all checkboxes located in a gridview
  • Selected item in listbox unreadable because of the color
  • dynamic ContextMenu in TreeView vs. MVVM
  • wpf prism (CAL) - Closing Window in Popup Region when the ViewModel knows nothing of the View
  • Free WPF Flow charting Component
  • Some doubts in WPF
  • WPF DataGrid programmatic multiple row selection
  • WPF Best point to update a progress bar from BackgroundWorker
  • WPF Validation & IDataErrorInfo
  • How to return a value with Dispatcher.Invoke?
  • Playing audio files in WPF
  • How much better is the WPF Designer in Visual Studio 2010?
  • XAML C# WPF Best efficient way to do an ordered sequence of animations
  • WPF + Communicate between multiple application instances
  • WPF: control.ItemContainerGenerator.Status is NotStarted. How do I tell it to start now?
  • wpf do animation until background worker finishes its work
  • Exit thread automatically when WPF application closes
  • WPF: How do I set the focus on a datagrid to a specific row?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com