bitmapimage

How to convert Byte[] to BitmapImage

∥☆過路亽.° 提交于 2019-11-28 09:47:53
I need help, I have this method to get a BitmapImage from a Byte[] public BitmapSource ByteToBitmapSource(byte[] image) { BitmapImage imageSource = new BitmapImage(); using (MemoryStream stream = new MemoryStream(image)) { stream.Seek(0, SeekOrigin.Begin); imageSource.BeginInit(); imageSource.StreamSource = stream; imageSource.CacheOption = BitmapCacheOption.OnLoad; imageSource.EndInit(); } return imageSource; } imageSource.EndInit(); throws an error "We found no imaging component suitable to complete this operation." Set Image.Source to a byte array property in XAML. <Image x:Name="MyImage"

Convert RenderTargetBitmap to BitmapImage

拜拜、爱过 提交于 2019-11-28 08:41:28
I have a RenderTargetBitmap , I need to convert it to BitmapImage . Please check the code below. RenderTargetBitmap bitMap = getRenderTargetBitmap(); Image image = new Image();// This is a Image image.Source = bitMap; In the above code I have used Image.Now I need to use a BitmapImage. How can I do this? RenderTargetBitmap bitMap = getRenderTargetBitmap(); BitmapImage image = new BitmapImage();// This is a BitmapImage // how to set bitMap as source of BitmapImage ? Although it doesn't seem to be necessary to convert a RenderTargetBitmap into a BitmapImage , you could easily encode the

How to render bitmap into canvas in WPF?

喜欢而已 提交于 2019-11-28 07:46:22
I've subclassed Canvas so that I can override its Render function. I need to know how I can load a bitmap in WPF and render that to the canvas. I'm completely new to WPF and I haven't found any tutorials that show you how to do something so seemingly trivial. Step-by-step instructions with examples would be great. This should get you started: class MyCanvas : Canvas { protected override void OnRender (DrawingContext dc) { BitmapImage img = new BitmapImage (new Uri ("c:\\demo.jpg")); dc.DrawImage (img, new Rect (0, 0, img.PixelWidth, img.PixelHeight)); } } In WPF it is a rare case that you

How can I get a BitmapImage from a Resource?

江枫思渺然 提交于 2019-11-28 06:45:37
My assembly includes an image with BuildAction==Resource. I want to obtain a BitmapImage from this embedded resource. I can load a BitmapImage from file like this: var bitmap = new BitmapImage(new Uri(path)); But how to I create a Uri that will refer to an embedded resource image? When I try and create a ' pack URI ' (for example pack://application:,,,/MyImage.png or pack://application:,,,/MyAssembly;component/MyImage.png ), an exception is thrown: System.UriFormatException "Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed." I found

error in my byte[] to WPF BitmapImage conversion?

那年仲夏 提交于 2019-11-28 05:22:27
问题 I'm saving a BitmapImage to a byte[] for saving in a DB. I'm pretty sure the data is being saved and retrieved accurately so it's not an issue there. On my byte[] to BitmapImage conversion I keep getting an exception of "System.NotSupportedException: No imaging component suitable to complete this operation was found." Can anyone see what I'm doing wrong with my two functions here? private Byte[] convertBitmapImageToBytestream(BitmapImage bi) { int height = bi.PixelHeight; int width = bi

C# 4.0 unlock image after creating BitmapImage

孤街浪徒 提交于 2019-11-28 05:16:11
问题 I am creating an BitmapImage from an existing image using: BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(jpegPath, UriKind.Relative); bmp.EndInit(); After I have done this I want to delete the image from my hard drive, but it is locked. Is there a way I can unlock it so it can be removed? 回答1: bmp.CacheOption = BitmapCacheOption.OnLoad; That will load the image into memory completely and won't leave a lock on the image file. 回答2: JPG is still set as the source

How to create a BitmapImage from a pixel byte array (live video display)

与世无争的帅哥 提交于 2019-11-28 05:09:00
I need to display live images on a WPF control. I'm looking for the fastest way to do this using WPF. I'm capturing images from a camera using its dll API ( AVT ). The image is writen by the dll and the camera rises a callback with an IntPtr to a Image struct called tFrame (described below). The pixel data is stored at the ImageBuffer propertie with is an InPtr to a byte array. I know how to create a Bitmap from the pixel byte array, but not a BitmapImage. So it is possible to create a Bitmap and then create a BitmapImagem from it. Here there is a way to create a BitmapImage from a Bitmap on

How to get the size of bitmap after displaying it in ImageView

耗尽温柔 提交于 2019-11-28 03:59:13
问题 I have a imageview <ImageView android:id="@+id/imgCaptured" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/captured_image" /> I capture a image from camera, converted that image into bitmap. Bitmap thumbnail; thumbnail = MediaStore.Images.Media.getBitmap(getActivity() .getContentResolver(), imageUri); when i get the resolution of this bitmap before displaying it in my above imageview, like

How to download image from facebook Graph API

∥☆過路亽.° 提交于 2019-11-28 02:23:39
I want to download an image from facebook but my Bitmap is always null. [ private void extractFacebookIcon(String id) { Bitmap bitmap = null; InputStream in = null; try { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy( policy ); URL imageURL = new URL("http://graph.facebook.com/"+id+"/picture?type=large"); in = ( InputStream) imageURL.getContent(); bitmap = BitmapFactory.decodeStream( in ); mFacebookIcon = bitmap; } catch(Throwable e) { }] When I use http://graph.facebook.com/"+id+"/picture?type=large in browser, my Chrome

Android handling out of memory exception on image processing

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 02:11:26
This is the sequence part of this question: Combining 2 Images overlayed so the problem is: if the image size is too big - it'll got an exception (out of memory exception) what i want is, to handle even if the handset got the lower spec hardware, it doesn't go to that exception (but it'll take a longer time to process the image) is it possible to do that? the code snippet is like this: public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1