bitmapimage

How to Change Pixel Color of an Image in C#.NET

佐手、 提交于 2019-11-27 07:52:29
I am working with Images in Java, I have designed more over 100+ images(.png) format, They were all Trasparent and Black Color Drawing. The problem is, Now I have been asked to change the color of the Drawing (Black -to ). I have searched many code snipped at google,that changes the Bitmap (pixels) of the Image, but i am not guessing what i have to do to match the exact pixel and replace specially when the images if in Transparent mode. Below is the code in .Net (C#) Bitmap newBitmap = new Bitmap(scrBitmap.Width, scrBitmap.Height); for (int i = 0; i < scrBitmap.Width; i++) { for (int j = 0; j

Silverlight: BitmapImage from stream throws exception (Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)))

纵饮孤独 提交于 2019-11-27 06:57:48
问题 I need to dynamically load many (sometimes hundreds) of thumbnail images. For performance reasons I need to do this in a limited number of requests, I am using a single request/response for testing. I am sending the binary data for the images in the response and loading them into BitmapImage's using a MemoryStream. This works correctly until I load more than about 80 thumbnails, then I get the Catastrophic Failure exception. To make sure my data was not corrupt I tried loading a BitmapImage

How can I get a BitmapImage from a Resource?

本秂侑毒 提交于 2019-11-27 05:41:41
问题 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

How to download image from facebook Graph API

岁酱吖の 提交于 2019-11-27 04:57:23
问题 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

How to free the memory after the BitmapImage is no longer needed?

狂风中的少年 提交于 2019-11-27 04:32:32
First, I load a BitmapImage on the Image control on the Window . Second, I work with the Image control and then close the Window . I do it 2-3 times in a minute and my memory fills up very quickly because the images do not unload back when the window is closed. So how to unload BitmapImage from Image.Source control manually to free the memory? I believe the solution you are looking for is at http://www.ridgesolutions.ie/index.php/2012/02/03/net-wpf-bitmapimage-file-locking/ . In my case, I was trying to find a way to delete the file after it was created, but it appears to be a solution to both

Save HBITMAP to *.bmp file using only Win32

前提是你 提交于 2019-11-27 04:17:21
I have a HBITMAP in my pure Win32 project (no external libraries are used). Can I export it to a *.bmp file using only Winapi and/or CRT functions so I don't incur any extra dependencies? Roman R. There is no API to save into file directly because, generally, having a bitmap handle does not mean you have direct access to bitmap data. Your solution is to copy bitmap into another bitmap with data access (DIB) and then using it data to write into file. You typically either create another bitmap using CreateDIBSection , or you get bitmap data with GetDIBits . CreateFile , WriteFile writes data

Reduce the size of a bitmap to a specified size in Android

醉酒当歌 提交于 2019-11-27 03:14:18
问题 I want to reduce the size of a bitmap to 200kb exactly. I get an image from the sdcard, compress it and save it to the sdcard again with a different name into a different directory. Compression works fine (3 mb like image is compressed to around 100 kb). I wrote the following lines of codes for this: String imagefile ="/sdcard/DCIM/100ANDRO/DSC_0530.jpg"; Bitmap bm = ShrinkBitmap(imagefile, 300, 300); //this method compresses the image and saves into a location in sdcard Bitmap ShrinkBitmap

How to convert Byte[] to BitmapImage

江枫思渺然 提交于 2019-11-27 03:13:03
问题 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

BitmapImage to byte[]

独自空忆成欢 提交于 2019-11-27 01:17:14
I have a BitmapImage that I'm using in a WPF application, I later want to save it to a database as a byte array (I guess it's the best way), how can I perform this conversion? Or, alternatively, is there a better way to save a BitmapImage (or any of its base classes, BitmapSource or ImageSource ) to a data repository? To convert to a byte[] you can use a MemoryStream: byte[] data; JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapImage)); using(MemoryStream ms = new MemoryStream()) { encoder.Save(ms); data = ms.ToArray(); } Instead of the

Create a BitmapImage from a byte array

心不动则不痛 提交于 2019-11-26 23:06:52
I am creating a byte array with arbitrary values in it and want to convert it into a BitmapImage. bi = new BitmapImage(); using (MemoryStream stream = new MemoryStream(data)) { try { bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; bi.StreamSource = stream; bi.DecodePixelWidth = width; bi.EndInit(); } catch (Exception ex) { return null; } } This code gives me a NotSupportedException all the time. How could I create a BitmapSource from any byte array? Given an array of bytes where each byte represents a pixel value, you may create a grayscale bitmap like shown below. You need to