WPF – converting Bitmap to ImageSource

For others, this works: //If you get ‘dllimport unknown’-, then add ‘using System.Runtime.InteropServices;’ [DllImport(“gdi32.dll”, EntryPoint = “DeleteObject”)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DeleteObject([In] IntPtr hObject); public ImageSource ImageSourceFromBitmap(Bitmap bmp) { var handle = bmp.GetHbitmap(); try { return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } finally { DeleteObject(handle); } }

view.getDrawingCache() is deprecated in Android API 28

Two ways to get bitmap of view Using Canvas Using Pixel Api Canvas Java Bitmap getBitmapFromView(View view) { Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888 ); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; } Bitmap getBitmapFromView(View view,int defaultColor) { Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888 ); Canvas canvas = new Canvas(bitmap); canvas.drawColor(defaultColor); view.draw(canvas); … Read more

How to attach image from drawable to gmail?

Here is the working code which you need: Firstly save image from Drawable to SD Card here is the code: try{ Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.bubble_green); //replace “R.drawable.bubble_green” with the image resource you want to share from drawable ByteArrayOutputStream bytes = new ByteArrayOutputStream(); largeIcon.compress(Bitmap.CompressFormat.JPEG, 40, bytes); // you can create a new file name “test.jpg” … Read more

Drawing control to memory (Bitmap)

As the control has no parent container, you need to call Measure and Arrange in order to do a proper layout. As layout is done asynchronously (see Remarks in Measure and Arrange), you may also need to call UpdateLayout to force the layout to be updated immediately. public BitmapSource RenderToBitmap(UIElement element, Size size) { element.Measure(size); … Read more

How to pass bitmap from one activity to another

Your code is correct for putting bitmaps into the extras and works fine for me with small images. But it seems that there is a limit for the size of the Parcelable extra. See http://groups.google.com/group/android-developers/browse_thread/thread/7322a84adcfee567?pli=1. You might want to store the image first and only hand over the URI to the store location. Edit: Using … Read more

Android SkImageDecoder::Factory returned null Error

Solved. Change the code to this. @Override protected Bitmap doInBackground(String… params) { // TODO Auto-generated method stub String urlStr = params[0]; Bitmap img = null; HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(urlStr); HttpResponse response; try { response = (HttpResponse)client.execute(request); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity); InputStream inputStream = bufferedEntity.getContent(); … Read more

How to load tiles from a large bitmap in Android?

Answer from Romain Guy in Is it possible to chop a bitmap to small pieces without loading the entire thing into memory?: Android 2.3.3 has a new API called android.graphics.BitmapRegionDecoder that lets you do exactly what you want. You would for instance do the following: BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(myStream, false); Bitmap region = decoder.decodeRegion(new Rect(10, … Read more

Byte Array to Bitmap Image

This is an alternative method int w= 100; int h = 200; int ch = 3; //number of channels (ie. assuming 24 bit RGB in this case) byte[] imageData = new byte[w*h*ch]; //you image data here Bitmap bitmap = new Bitmap(w,h,PixelFormat.Format24bppRgb); BitmapData bmData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); IntPtr pNative = bmData.Scan0; … Read more