Tag: bitmapfactory

BitmapFactory.decodeFile返回null

我想从网络上的照片创建一个位图。 首先,我尝试使用BitmapFactory.decodeStream但由于存在错误而返回null(http://code.google.com/p/android/issues/detail?id=6066)。 现在我保存图像然后使用BitmapFactory.decodeFile但它仍然返回null。 任何想法是错误的还是其他解决方法? 谢谢! try { URL uri = new URL(“http://sofzh.miximages.com/java/scooter-dj-munchen.jpg”); URLConnection connection = uri.openConnection(); Log.i(TAG, “connecting…”); connection.connect(); InputStream is = connection.getInputStream(); //BufferedInputStream bis = new BufferedInputStream(is, 8 * 1024); File myfile = new File(getApplicationContext().getCacheDir(), “wallpaper.tmp”); myfile.createNewFile(); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(myfile)); byte buf[]=new byte[1024]; int len; while((len=is.read(buf))>0) out.write(buf,0,len); out.close(); is.close(); Log.d(TAG, String.valueOf(myfile.exists())); […]

来自URL的Android位图始终为null

我正在尝试从URL下载图像并将其转换为位图,但该行 Bitmap myBitmap = BitmapFactory.decodeStream(input); 始终导致调试器跳到以下行 return null; 没有实际打印出堆栈跟踪,并且调试器中列出的变量中也不存在Exception变量。 我读了很多关于url可能没有实际导致图像问题,没有格式化图像之类的问题,但它仍然存在与我积极存在的硬编码图像相同的问题。 public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL( “http://www.helpinghomelesscats.com/images/cat1.jpg”); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } } 由于似乎可能涉及manifest.xml文件,因此我已编辑添加到此处。

使用蓝牙热敏打印机从Android应用程序打印图像?

我一直试图获得一张图片的印刷品,但到目前为止我还没有成功。 该打印机是本地制造的2英寸热敏打印机,打印分辨率为8点/ mm,384点/线,203 dpi。 该打印机基于具有“NXP 2388 ARM v7 Microproc”的电路板。 内存FLASH大小为512 KB,RAM:128 KB,接收缓冲区大小为16KB。 我一直跟着这个问题 。 问题:我尝试打印的图像是576×95 res。 打印图像(有一些错误LED点亮并调试蜂鸣器噪音:D)但图像的方向是垂直的而不是水平打印; 也是在页面的最左侧,图像的顶部也被切断了 假设我没有通过一些标志(同时使“数据包”)与我拥有的打印机兼容。 我之前没有从事蓝牙打印,所以任何帮助都很明显:) 我现有的主要活动: public class MainActivity extends Activity { // will show the statuses TextView myLabel; // will enable user to enter any text to be printed EditText myTextbox; EditText devName; public TableLayout tl2; String devid; String[] […]

图像不是使用BitmapFactory.decodeByteArray创建的

编辑:当我在txt文件中保存这些字节时,当我将其保存为png文件时,它会显示图像,但它在这里不起作用为什么……? 我正在使用此代码从doInBackground()上的字节数组创建图像 String base64data=StringEscapeUtils.unescapeJava(IOUtils.toString(resp.getEntity().getContent())); base64data=base64data.substring(1,base64data.length()-1); JSONObject obj=new JSONObject(base64data); JSONArray array=obj.getJSONArray(“EMRTable”); JSONObject childobj=array.getJSONObject(0); results=childobj.getString(“DocumentInternalFormat”); 和onPostExecute if(jsondata!=null) { receiveData(jsondata); } logcat中没有错误,即使它没有exception..但图像没有显示。 我也是这样做的 String data=(String)object; data=data.trim(); byte[] base64converted=Base64.decode(data,Base64.DEFAULT); ImageView image=new ImageView(context); image.setImageBitmap(bmp); setContentView(image); 但结果相同的图像没有显示,但没有exception或错误,问题是什么… 注释行是当我尝试将这些字节存储到文本文件中时,当我拉动文件时,它会显示带有Windows默认图像查看器的图像。