bitmap

Why ByteArrayOutputStream sometimes gives me null pointer exception?

旧时模样 提交于 2020-01-05 05:11:07
问题 When loading a picture into byte[] in smartphone app sometimes ByteArrayOutputStream gives me nullpointerexception any explanation? Bitmap bm = BitmapFactory.decodeFile(path); System.out.println("BITMAP: "+bm != null); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 100, buffer); 回答1: Are you sure it's ByteArrayOutputStream that's giving you the NullPointerException? Or is it happening at bm.compress? bm can be null - likely due to you passing in

Converting colorspace in Imagemagick is not working

旧城冷巷雨未停 提交于 2020-01-05 03:25:29
问题 I am trying to convert an sRGB bitmap file to greyscale using ImageMagick. I've tried using convert -set colorspace Gray and convert colorspace Gray , which according to the documentation should do it. However, when I try to check the output file using identify -format "%[colorspace]" <outputfile> it still tells me that it is in sRGB. I am aware that not all file formats support all colourspaces, and tried converting the bitmap to a png first, then changing the colorspace and converting it

BitmapFactory decode an BMP image

被刻印的时光 ゝ 提交于 2020-01-04 14:12:11
问题 I am using this code from android developer blog for downloading a BMP file like this one. BitmapFactory.decodeStream always returns null with skia returning false. I've also tried using BitmapFactory.decodeByteArray with same result. The framework supports BMP files, so what am i missing? Thanks EDIT: The code in the blog works for PNG and JPEG images. 回答1: Okay, i found here, you need to wrap the HttpEntity with a BufferedHttpEntity. BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity

Bitmap

落花浮王杯 提交于 2020-01-04 09:29:19
一、Bitmap 1、Bitmap组成 Bitmap的存储包含两个部分: 像素 以及 长、宽、颜色等描述信息 。像素是Bitmap最占内存的地方,长宽和像素位数是用来描述图片的,可以通过这些信息计算出图片的像素占用的内存的大小。 常用方法: getWidth() getHeight() Config getConfig() 枚举值 枚举类型 每个像素内存 ALPHA_8 1byte RGB_565 2byte ARGB_4444 2byte ARGB_8888(默认) 4byte (1)图片占用内存的计算 假设一张图片1024*1024,模式为ARGB_8888的图片,那么它占有的内存就是1024*1024*4=4MB 2、Bitmap加载 Bitmap的加载离不开BitMapFactory类 加载文件 (间接调用decodeStream) BitmapFactory.decodeFile(String pathName); BitmapFactory.decodeFile(String pathName,Options opts) 加载id资源(间接调用decodeStream) BitmapFactory.decodeResource(Resource res,int id,Options opts) BitmapFactory.decodeResource(Resource

Do we have to explicitly recycle the bitmap if we don't need it?

半世苍凉 提交于 2020-01-04 08:16:11
问题 Bitmap has a recycle method, but do we have to invoke it explicitly if we don't need it any more? For example, an ImageView has a bitmap now. When user click a button, it will set a new bitmap to the ImageView. Do we have to recycle the original bitmap before assign the new one? 回答1: yes you have if you are targeting devices with Android older the 3.0 . That's will avoid you to incour in the OutOfMemoryException . Note: Before android 3 the Bitmap memory is allocated in the native heap. The

How do I cancel an AsyncTask running BitmapFactory.decodeFile() and clean-up

守給你的承諾、 提交于 2020-01-04 06:15:00
问题 In my interface, the user selects from a variable number of songs, and when a song is selected, I need to display the relevant background image. The user needs to keep control of the interface while the images are loading, and still be able to change song. The way I currently do this is using an AsyncTask. I am executing it using: if (LoadBG!=null&&!LoadBG.isCancelled()) LoadBG.cancel(false); LoadBG = new loadBG(); LoadBG.execute((Object) diff.BGPath); attempting to cancel the previous task

WPF Bitmap transparent background turns black

冷暖自知 提交于 2020-01-04 05:45:26
问题 I have a listbox with Items that all have a random background color. In each Item of the listbox i want to display a Bitmap picture. Now for some reason the background of each bitmap (which I've set to Color.Transparent) Shows up black. Here a picture of how it looks My code for the listbox: <WrapPanel Grid.Row="1" Grid.Column="1" Margin="6" > <ListBox x:Name="CharListBox" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsSource="{Binding ListToDisplay,

Creating a bitmap from a byte[]

此生再无相见时 提交于 2020-01-04 05:13:10
问题 I have a byte[] which create from a stream which i need to create a Bitmap image i was trying MemoryStream ms = new MemoryStream(btarr); Bitmap img = new Bitmap(); img=img.FromStream(ms); im sure that btarr is filled with stream bytes and valid bitmap content , but this always provide the img as null .. any idea? 回答1: this method will do the job: public static Bitmap BytesToBitmap(byte[] byteArray) { using (MemoryStream ms = new MemoryStream(byteArray)) { Bitmap img = (Bitmap)Image.FromStream

Asynchronous threads drawing in Bitmaps Delphi

孤者浪人 提交于 2020-01-04 04:41:04
问题 If many asynchronous threads draw in a global TBitmap, it will rise me an error? Should I create my code using a critical section? (From my surf on the internet I found that the TBitmap.Draw is not thread safe) Another question: If many synchronous threads draw in a global TBitmap and a VCL Timer read asynchronously the content from the TBitmap will this rise me an error? Thanks! 回答1: Since your threads are all modifying the same bitmap, you need to serialize all access to that bitmap. That

How to create Bitmap object from a Graphics object?

佐手、 提交于 2020-01-04 01:05:53
问题 How to create Bitmap object from a Graphics object ? I would like to read pixels from my Graphics object. for example, like, System.Drawing.BitMap.GetPixel(). I am trying to find out empty area (all white, or of any colour) inside a pdf document, to write some graphics / image. I have tried like this, but it is not working. why the following code is not working as expected ? // // System.Drawing.Bitmap // System.Drawing.Graphics // Bitmap b = new Bitmap(width, height, graphics); // // In this