How do I load and edit a bitmap file at the pixel level in Swift for iOS?

This is how I am getting a color from an image at a touch location. I translated this answer: https://stackoverflow.com/a/12579413/359578 (This sample does no error checking for nil) func createARGBBitmapContext(inImage: CGImage) -> CGContext { var bitmapByteCount = 0 var bitmapBytesPerRow = 0 //Get image width, height let pixelsWide = CGImageGetWidth(inImage) let pixelsHigh = CGImageGetHeight(inImage) // … Read more

c# Bitmap.Save transparancy doesn’t save in png

Are you sure the pixel format of the Bitmap is System.Drawing.Imaging.PixelFormat.Format32bppArgb? I just stumbled on this question because I was having the same problem, but it was because I was loading an image which had no alpha component to its pixel format. I did Bitmap output = original.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppArgb); and it properly saved the PNG … Read more

Read an Image/file from External storage Android

If i have file abc.jpg on the sdcard then: String photoPath = Environment.getExternalStorageDirectory() + “/abc.jpg”; and to get bitmap. BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options); or Bitmap bitmap1 = BitmapFactory.decodeFile(photoPath); to avoide out of memory error I suggest you use the below code… BitmapFactory.Options options = new BitmapFactory.Options(); … Read more

Sharpen on a Bitmap using C#

I took Daniel’s answer and modified it for performance, by using BitmapData class, since using GetPixel/SetPixel is very expensive and inappropriate for performance-hungry systems. It works exactly the same as the previous solution and can be used instead. public static Bitmap Sharpen(Bitmap image) { Bitmap sharpenImage = (Bitmap)image.Clone(); int filterWidth = 3; int filterHeight = … Read more

How to resize a bitmap eficiently and with out losing quality in android

Resizing a Bitmap: public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // create a matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // recreate … Read more

How to programmatically change contrast of a bitmap in android?

Here is complete method: /** * * @param bmp input bitmap * @param contrast 0..10 1 is default * @param brightness -255..255 0 is default * @return new bitmap */ public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness) { ColorMatrix cm = new ColorMatrix(new float[] { contrast, 0, 0, 0, brightness, 0, contrast, 0, … Read more

How to Display a Bitmap in a WPF Image [duplicate]

I have used this snipped now to convert the Bitmap to a ImageSource: BitmapImage BitmapToImageSource(Bitmap bitmap) { using (MemoryStream memory = new MemoryStream()) { bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); memory.Position = 0; BitmapImage bitmapimage = new BitmapImage(); bitmapimage.BeginInit(); bitmapimage.StreamSource = memory; bitmapimage.CacheOption = BitmapCacheOption.OnLoad; bitmapimage.EndInit(); return bitmapimage; } }