private void createSingleImageFromMultipleImages(Bitmap bitmap, int mCounter) { if (mCounter == 0) { try { this.mManyBitmapSuperposition = Bitmap.createBitmap( DeviceInfo.mScreenWidthForPortrait, DeviceInfo.mScreenHeightForPortrait, bitmap.getConfig()); this.mCanvas = new Canvas(this.mManyBitmapSuperposition); } catch (OutOfMemoryError error) { error.printStackTrace(); System.gc(); } finally { } } if (this.mCanvas != null) { int number = DeviceInfo.mScreenHeightForPortrait / 64; if (mCounter >= (mCounter / number) * number && mCounter < ((mCounter / number) + SNOW_BLOCK) * number) { this.mCanvas.drawBitmap( bitmap, (float) ((mCounter / number) * 64), (float) ((mCounter % number) * 64), null); } } }
private void loadInput() { Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { aspectX = extras.getInt(Crop.Extra.ASPECT_X); aspectY = extras.getInt(Crop.Extra.ASPECT_Y); maxX = extras.getInt(Crop.Extra.MAX_X); maxY = extras.getInt(Crop.Extra.MAX_Y); saveUri = extras.getParcelable(MediaStore.EXTRA_OUTPUT); } sourceUri = intent.getData(); if (sourceUri != null) { exifRotation = CropUtil.getExifRotation(CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri)); InputStream is = null; try { sampleSize = calculateBitmapSampleSize(sourceUri); is = getContentResolver().openInputStream(sourceUri); BitmapFactory.Options option = new BitmapFactory.Options(); option.inSampleSize = sampleSize; rotateBitmap = new RotateBitmap(BitmapFactory.decodeStream(is, null, option), exifRotation); } catch (IOException e) { Log.e("Error reading image: " + e.getMessage(), e); setResultException(e); } catch (OutOfMemoryError e) { Log.e("OOM reading image: " + e.getMessage(), e); setResultException(e); } finally { CropUtil.closeSilently(is); } } }
public static String getFileSha1(String path) throws IOException { File file = new File(path); FileInputStream in = new FileInputStream(file); MessageDigest messagedigest; try { messagedigest = MessageDigest.getInstance("SHA-1"); byte[] buffer = new byte[1024 * 1024 * 10]; int len = 0; while ((len = in.read(buffer)) > 0) { // 该对象通过使用 update()方法处理数据 messagedigest.update(buffer, 0, len); } // 对于给定数量的更新数据,digest 方法只能被调用一次。在调用 digest 之后,MessageDigest // 对象被重新设置成其初始状态。 return getFormattedText(messagedigest.digest()); // byte2hex(messagedigest.digest()); } catch (NoSuchAlgorithmException e) { // NQLog.e("getFileSha1->NoSuchAlgorithmException###", e.toString()); e.printStackTrace(); } catch (OutOfMemoryError e) { // NQLog.e("getFileSha1->OutOfMemoryError###", e.toString()); e.printStackTrace(); throw e; } finally { in.close(); } return null; }
public static void dolayout( Graph2D graph, CycleEnum cycleType, byte partitionLayoutStyle, int maxDevAngle, boolean fromSketch, boolean enableOnlyCore, boolean groupNodeHiding, boolean selfLoopLayouter, boolean parallelEdgeLayouter, boolean subgraphLayouter, boolean labelLayouter, boolean componentLayouter, boolean orientationLayouter) { CircularLayouter clo = new CircularLayouter(); switch (cycleType) { case SINGLE_CYCLE: clo.setLayoutStyle(CircularLayouter.SINGLE_CYCLE); break; case BCC_ISOLATED: clo.setLayoutStyle(CircularLayouter.BCC_ISOLATED); break; case BCC_COMPACT: clo.setLayoutStyle(CircularLayouter.BCC_COMPACT); break; case CIRCULAR_CUSTOM_GROUPS: clo.setLayoutStyle(CircularLayouter.CIRCULAR_CUSTOM_GROUPS); break; default: clo.setLayoutStyle(CircularLayouter.BCC_COMPACT); break; } clo.setMaximalDeviationAngle(maxDevAngle); clo.setPartitionLayoutStyle(partitionLayoutStyle); clo.setFromSketchModeEnabled(fromSketch); if (enableOnlyCore) { clo.enableOnlyCore(); } clo.setLabelLayouterEnabled(labelLayouter); clo.setSubgraphLayouterEnabled(subgraphLayouter); clo.setSelfLoopLayouterEnabled(selfLoopLayouter); clo.setComponentLayouterEnabled(componentLayouter); clo.setParallelEdgeLayouterEnabled(parallelEdgeLayouter); clo.setOrientationLayouterEnabled(orientationLayouter); clo.setGroupNodeHidingEnabled(groupNodeHiding); try { new BufferedLayouter(clo).doLayout(graph); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void run() { try { if (end) return; if (evercamCamera.loadingStatus == ImageLoadingStatus.not_started) { if (evercamCamera.isActive()) { // showAndSaveLiveSnapshot(); } } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_received) { setLayoutForLiveImageReceived(); } else if (evercamCamera.loadingStatus == ImageLoadingStatus.live_not_received) { setLayoutForNoImageReceived(); } } catch (OutOfMemoryError e) { Log.e(TAG, e.toString() + "-::OOM::-" + Log.getStackTraceString(e)); handler.postDelayed(LoadImageRunnable, 5000); } catch (Exception e) { Log.e(TAG, e.toString() + "::" + Log.getStackTraceString(e)); if (!end) { handler.postDelayed(LoadImageRunnable, 5000); } } }
/** * Rotate. * * @param b the b * @param degrees the degrees * @return the bitmap */ private Bitmap rotate(final Bitmap b, int degrees) { Logger.v(TAG, "rotate entry"); Bitmap bitmap = b; if (degrees != 0 && bitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try { Bitmap bitmapRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (bitmap != bitmapRotated) { bitmap.recycle(); bitmap = bitmapRotated; } else { Logger.d(TAG, "no need to rotate"); } } catch (OutOfMemoryError ex) { // We have no memory to rotate. Return the original bitmap. ex.printStackTrace(); } } else { Logger.d(TAG, "rotate no need to rotate"); } Logger.v(TAG, "rotate exit"); return bitmap; }
public static Bitmap loadBitmap(String url, UrlBitmapDownloadCallback callback) { if (TextUtils.isEmpty(url)) { return null; } SoftReference<Bitmap> sf = mapUrlToBitmap.get(url); Bitmap bmp = null; if (sf != null) { bmp = sf.get(); } if (bmp == null) { String filePath = FilePaths.getUrlFileCachePath(url); if (new File(filePath).exists()) { BitmapFactory.Options op = new BitmapFactory.Options(); SystemUtils.computeSampleSize(op, filePath, 1024, 1024 * 512); try { bmp = BitmapFactory.decodeFile(filePath, op); } catch (OutOfMemoryError e) { e.printStackTrace(); op.inSampleSize *= 2; bmp = BitmapFactory.decodeFile(filePath, op); } } if (bmp == null) { if (callback != null) { mapUrlToCallback.put(url, callback); } requestDownloadBitmap(url, filePath); } else if (bmp != null) { mapUrlToBitmap.put(url, new SoftReference<Bitmap>(bmp)); } } return bmp; }
public void m3980a(int i) { try { this.f3127b = BitmapFactory.decodeResource(this.f3132g, i); } catch (OutOfMemoryError e) { e.printStackTrace(); } }
private final Bitmap compress(String uri, int reqWidth, int reqHeight) { Bitmap bitmap = null; try { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(uri, opts); int height = opts.outHeight; int width = opts.outWidth; int inSampleSize = 1; if (width > height && width > reqWidth) { inSampleSize = Math.round((float) width / (float) reqWidth); } else if (height > width && height > reqHeight) { inSampleSize = Math.round((float) height / (float) reqHeight); } if (inSampleSize <= 1) inSampleSize = 1; opts.inSampleSize = inSampleSize; opts.inJustDecodeBounds = false; opts.inPreferredConfig = Config.RGB_565; opts.inPurgeable = true; opts.inInputShareable = true; opts.inTargetDensity = getResources().getDisplayMetrics().densityDpi; opts.inScaled = true; opts.inTempStorage = new byte[16 * 1024]; bitmap = BitmapFactory.decodeStream(new BufferedInputStream(new FileInputStream(uri)), null, opts); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }
/** * Runs the job using the XProcEngine as script loader. * * @param engine the engine */ public final synchronized void run(XProcEngine engine) { changeStatus(Status.RUNNING); XProcPipeline pipeline = null; try { pipeline = engine.load(this.ctxt.getScript().getURI()); Properties props = new Properties(); props.setProperty("JOB_ID", this.ctxt.getId().toString()); XProcResult results = pipeline.run(this.ctxt.getInputs(), this.ctxt.getMonitor(), props); this.ctxt.writeResult(results); // if the validation fails set the job status if (!this.checkValid()) { changeStatus(Status.VALIDATION_FAIL); } else { changeStatus(Status.DONE); } } catch (Exception e) { changeStatus(Status.ERROR); broadcastError(e.getMessage()); logger.error("job finished with error state", e); } catch (OutOfMemoryError e) { // this one needs it's own catch! changeStatus(Status.ERROR); broadcastError(e.getMessage()); logger.error("job consumed all heap space", e); } }
@Override public View instantiateItem(ViewGroup container, int position) { PhotoView photoView = new PhotoView(container.getContext()); ImageFetcher fetcher = ImageLoader.createImageFetcher((BaseActivity) context); fetcher.setLoadingImage(R.drawable.default_weibo_image); try { Msg_ChatMessageBean bean = data.get(position); Bitmap bitmap = ImageUtil.byteArray2Bitmap(bean.Image); photoView.setImageBitmap(bitmap); photoView.setOnPhotoTapListener( new OnPhotoTapListener() { @Override public void onPhotoTap(View view, float x, float y) { Msg_ImageZoomActivity.this.onBackPressed(); } }); container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError ex) { ex.printStackTrace(); } return photoView; }
public static boolean compressBitmapFile( String dstPath, String srcPath, int reqWidth, int reqHeight) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; options.inPurgeable = true; BitmapFactory.decodeFile(srcPath, options); if (options.outWidth > 0) { if (options.outWidth > reqWidth || options.outHeight > reqHeight) { options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; try { Bitmap bmp = BitmapFactory.decodeFile(srcPath, options); FileHelper.saveBitmapToFile(dstPath, bmp, 90); } catch (OutOfMemoryError e) { e.printStackTrace(); return false; } } else { FileHelper.copyFile(dstPath, srcPath); } } else { return false; } return true; }
private Bitmap inMemoryCrop( RotateBitmap rotateBitmap, Bitmap croppedImage, Rect r, int width, int height, int outWidth, int outHeight) { // In-memory crop means potential OOM errors, // but we have no choice as we can't selectively decode a bitmap with this API level System.gc(); try { croppedImage = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.RGB_565); RectF dstRect = new RectF(0, 0, width, height); Matrix m = new Matrix(); m.setRectToRect(new RectF(r), dstRect, Matrix.ScaleToFit.FILL); m.preConcat(rotateBitmap.getRotateMatrix()); if (isCircleCrop) { return cropCircleView(rotateBitmap.getBitmap(), croppedImage, m); } Canvas canvas = new Canvas(croppedImage); canvas.drawBitmap(rotateBitmap.getBitmap(), m, null); } catch (OutOfMemoryError e) { Log.e("OOM cropping image: " + e.getMessage(), e); setResultException(e); System.gc(); } // Release bitmap memory as soon as possible clearImageView(); return croppedImage; }
/** * 获取编辑文件夹高光图标的副本 * * @return */ public BitmapDrawable getEditLightIconCopy() { try { if (mEditLightIcon == null) { // BitmapDrawable origImg = (BitmapDrawable) mActivity // .getResources().getDrawable( // R.drawable.eidt_folder_light); if (mThemeController == null) { mThemeController = AppFuncFrame.getThemeController(); } BitmapDrawable origImg = (BitmapDrawable) mThemeController.getDrawable( mThemeController.getThemeBean().mAppIconBean.mEditHighlightFolder); if (origImg != null) { Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true); if (copy != null) { mEditLightIcon = new BitmapDrawable(mContext.getResources(), copy); } } } } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } catch (Exception e) { e.printStackTrace(); } return mEditLightIcon; }
protected void onCreateIcons() { ImageView icon_small = (ImageView) getOptionView().findViewById(R.id.icon_small); ImageView icon_big = (ImageView) getOptionView().findViewById(R.id.icon_big); Resources res = getContext().getBaseContext().getResources(); if (null != res) { int id = res.getIdentifier( "feather_tool_icon_" + mResourceName, "drawable", getContext().getBaseContext().getPackageName()); if (id > 0) { Bitmap big, small; try { Bitmap bmp = BitmapFactory.decodeResource(res, id); big = ThumbnailUtils.extractThumbnail( bmp, (int) (bmp.getWidth() / 1.5), (int) (bmp.getHeight() / 1.5)); bmp.recycle(); small = ThumbnailUtils.extractThumbnail( big, (int) (big.getWidth() / 1.5), (int) (big.getHeight() / 1.5)); } catch (OutOfMemoryError e) { e.printStackTrace(); return; } icon_big.setImageBitmap(big); icon_small.setImageBitmap(small); } } }
public Level(int length, int height) { // ints = new Vector(); // booleans = new Vector(); this.length = length; this.height = height; xExit = 50; yExit = 10; // System.out.println("Java: Level: lots of news here..."); // System.out.println("length = " + length); // System.out.println("height = " + height); try { map = new byte[length][height]; // System.out.println("map = " + map); data = new byte[length][height]; // System.out.println("data = " + data); spriteTemplates = new SpriteTemplate[length][height]; marioTrace = new int[length][height + 1]; } catch (OutOfMemoryError e) { System.err.println("Java: MarioAI MEMORY EXCEPTION: OutOfMemory exception. Exiting..."); e.printStackTrace(); System.exit(-3); } // System.out.println("spriteTemplates = " + spriteTemplates); // observation = new byte[length][height]; // System.out.println("observation = " + observation); }
@Override public View getView(int position, View convertView, ViewGroup arg2) { // TODO Auto-generated method stub convertView = mInflater.inflate(R.layout.test_list_row, null); ImageView iv = (ImageView) convertView.findViewById(R.id.imageView); // 用try catch 块包围住 try { setImage(iv); } catch (OutOfMemoryError e) { // 这里就是当内存泄露时 需要做的事情 e.printStackTrace(); Log.d("memory", "out"); // 释放内存资源 recycleMemory(); // 将刚才 发生异常没有执行的 代码 再重新执行一次 setImage(iv); } return convertView; }
/** 获得功能表底部背景图片:当拖动图标至桌面时的背景效果图 */ public MImage getMoveToDeskBg() { if (isVertical()) { if (mMoveToDesk_v == null) { try { mMoveToDesk_v = generateMImage(R.drawable.appfunc_movetodesk, getScreenWidth(), getRealNum(85), 0); } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } } return mMoveToDesk_v; } else { if (mMoveToDesk_h == null) { try { mMoveToDesk_h = generateMImage( R.drawable.appfunc_movetodesk, getScreenHeight(), getRealNum(85), -90.0f); } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } } return mMoveToDesk_h; } }
/** * 预防竖屏切横屏时壁纸不全问题 * * @param walllPaper * @return */ private Drawable prepareOrientationChange(Drawable walllPaper) { Drawable ret = walllPaper; Activity activity = mActivityReference.get(); if (null != activity && activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int width = walllPaper.getIntrinsicWidth(); int height = walllPaper.getIntrinsicHeight(); int screenW = GoLauncher.getScreenWidth(); int screenH = GoLauncher.getScreenHeight(); if (screenW < screenH) { int temp = screenW; screenW = screenH; screenH = temp; } if (width >= screenW && height >= screenH) { return ret; } float wScale = (float) screenW / (float) width; float hScale = (float) screenH / (float) height; float scale = wScale > hScale ? wScale : hScale; int w = (int) (width * scale); int h = (int) (height * scale); try { Drawable newWallpaper = BitmapUtility.zoomDrawable(activity, walllPaper, w, h); ret = newWallpaper; } catch (OutOfMemoryError e) { Log.e(TAG, "发生了内存溢出 in prepareOrientationChange(Drawable),壁纸交给系统处理" + e.getMessage()); } catch (Exception e) { Log.e(TAG, "prepareOrientationChange" + e.getMessage()); } } return ret; }
/** 获得功能表底部背景图片: 底层为BitmapDrawable格式 */ public MImage getBottomBg() { if (isVertical()) { if (mBottomBg_v == null) { try { mBottomBg_v = generateMImage(R.drawable.shorcut_slaver, getScreenWidth(), getRealNum(85), 0); } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } } return mBottomBg_v; } else { if (mBottomBg_h == null) { try { mBottomBg_h = generateMImage(R.drawable.shorcut_slaver, getScreenHeight(), getRealNum(85), -90.0f); } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } } return mBottomBg_h; } }
public OperationResponse commitAndOptimize() { try { if (logger.isDebugEnabled()) { logger.debug("commiting..."); } indexWriter.commit(); if (logger.isDebugEnabled()) { logger.debug("commit finish."); } if (logger.isDebugEnabled()) { logger.debug("optimizing..."); } indexWriter.forceMerge(defaultMergeSize); if (logger.isDebugEnabled()) { logger.debug("optimize finish."); } reopenSearcher(); } catch (IOException e) { logger.error("optimize error", e); return new OperationResponse(e.getMessage(), ResultCodes.COMMON_ERROR); } catch (OutOfMemoryError e) { CloseUtil.close(indexWriter); logger.error("error of OOM", e); return new OperationResponse(e.getMessage(), ResultCodes.COMMON_ERROR); } return new OperationResponse(); }
/** * 获取关闭高光图标的副本 * * @return */ public BitmapDrawable getColseLightIconCopy() { try { if (mCloseLightIcon == null) { if (mThemeController == null) { mThemeController = AppFuncFrame.getThemeController(); } BitmapDrawable origImg = (BitmapDrawable) mThemeController.getDrawable( mThemeController.getThemeBean().mAppIconBean.mKillAppLight); if (origImg != null) { Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true); if (copy != null) { mCloseLightIcon = new BitmapDrawable(mContext.getResources(), copy); } } } } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } catch (Exception e) { e.printStackTrace(); } return mCloseLightIcon; }
/** * 获取卸载图标的副本 * * @return */ public BitmapDrawable getKillIconCopy() { try { if (mKillImg == null) { // BitmapDrawable origImg = (BitmapDrawable) mActivity // .getResources().getDrawable(R.drawable.kill); if (mThemeController == null) { mThemeController = AppFuncFrame.getThemeController(); } BitmapDrawable origImg = (BitmapDrawable) mThemeController.getDrawable( mThemeController.getThemeBean().mAppIconBean.mDeletApp); if (origImg != null) { Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true); if (copy != null) { mKillImg = new BitmapDrawable(mContext.getResources(), copy); } } } } catch (OutOfMemoryError e) { e.printStackTrace(); OutOfMemoryHandler.handle(); } catch (Exception e) { e.printStackTrace(); } return mKillImg; }
@Override protected CacheableBitmapDrawable doInBackground(String... params) { try { // Return early if the ImageView has disappeared. if (holder.userId != userId) { return null; } final String url = params[0]; // Now we're not on the main thread we can check all caches CacheableBitmapDrawable result; try { result = mCache.get(url, null); } catch (Exception e) { result = null; } if (null == result) { Log.d("ImageUrlAsyncTask", "Downloading: " + url); // The bitmap isn't cached so download from the web HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); InputStream is = new BufferedInputStream(conn.getInputStream()); Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 500, 500); try { is.close(); } catch (Exception e) { } try { conn.disconnect(); } catch (Exception e) { } // Add to cache try { result = mCache.put(url, b); } catch (Exception e) { result = null; } } else { Log.d("ImageUrlAsyncTask", "Got from Cache: " + url); } return result; } catch (IOException e) { Log.e("ImageUrlAsyncTask", e.toString()); } catch (OutOfMemoryError e) { e.printStackTrace(); } return null; }
@TargetApi(10) private Bitmap decodeRegionCrop(Bitmap croppedImage, Rect rect) { // Release memory now clearImageView(); InputStream is = null; try { is = getContentResolver().openInputStream(sourceUri); BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false); final int width = decoder.getWidth(); final int height = decoder.getHeight(); if (exifRotation != 0) { // Adjust crop area to account for image rotation Matrix matrix = new Matrix(); matrix.setRotate(-exifRotation); RectF adjusted = new RectF(); matrix.mapRect(adjusted, new RectF(rect)); // Adjust to account for origin at 0,0 adjusted.offset(adjusted.left < 0 ? width : 0, adjusted.top < 0 ? height : 0); rect = new Rect( (int) adjusted.left, (int) adjusted.top, (int) adjusted.right, (int) adjusted.bottom); } try { croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options()); } catch (IllegalArgumentException e) { // Rethrow with some extra information throw new IllegalArgumentException( "Rectangle " + rect + " is outside of the image (" + width + "," + height + "," + exifRotation + ")", e); } } catch (IOException e) { Log.e("Error cropping image: " + e.getMessage(), e); finish(); } catch (OutOfMemoryError e) { Log.e("OOM cropping image: " + e.getMessage(), e); setResultException(e); } finally { CropUtil.closeSilently(is); } return croppedImage; }
/** * @param dataStore A ShapeFileDataStore containing geometries to convert. * @param keyAttributes The names of attributes to be concatenated to generate record keys. * @throws Exception */ public static void convertFeatures( GeometryStreamConverter converter, ShapefileDataStore dataStore, List<String> keyAttributes) throws Exception { SimpleFeatureType schema = dataStore.getSchema(); int numFeatures = dataStore.getCount(Query.ALL); FeatureReader<SimpleFeatureType, SimpleFeature> reader = null; try { List<AttributeDescriptor> attrDesc = schema.getAttributeDescriptors(); String header = "\"the_geom_id\", \"the_geom_key\""; for (int i = 1; i < attrDesc.size(); i++) { String colName = attrDesc.get(i).getLocalName(); if (GeometryStreamConverter.debugDBF) header += ", \"" + colName + '"'; // if any specified attribute matches colName, case insensitive, overwrite specified // attribute name with name having correct case for (int j = 0; j < keyAttributes.size(); j++) if (keyAttributes.get(j).equalsIgnoreCase(colName)) keyAttributes.set(j, colName); } // debug: read schema and print it out if (GeometryStreamConverter.debugDBF) System.out.println(header); // loop through features and parse them long startTime = System.currentTimeMillis(), endTime = startTime, debugInterval = 60000, nextDebugTime = startTime + debugInterval; int featureCount = 0; reader = dataStore.getFeatureReader(); CoordinateReferenceSystem projection = schema.getCoordinateReferenceSystem(); // may be null String projectionWKT = projection == null ? null : projection.toWKT(); while (reader.hasNext()) { endTime = System.currentTimeMillis(); if (GeometryStreamConverter.debugTime && endTime > nextDebugTime) { System.out.println( String.format( "Processing %s/%s features, %s minutes elapsed", featureCount, numFeatures, (endTime - startTime) / 60000.0)); while (endTime > nextDebugTime) nextDebugTime += debugInterval; } convertFeature(converter, reader.next(), keyAttributes, projectionWKT); featureCount++; } if (GeometryStreamConverter.debugTime && endTime - startTime > debugInterval) System.out.println( String.format( "Processing %s features completed in %s minutes", numFeatures, (endTime - startTime) / 60000.0)); } catch (OutOfMemoryError e) { e.printStackTrace(); throw e; } finally { try { if (reader != null) reader.close(); } catch (IOException e) { } } }
public static void loadImage(String path, ImageLoadingListener listener) { ImageLoader loader = ImageLoader.getInstance(); try { loader.loadImage(path, DEFAULT_DISPLAY_IMAGE_OPTIONS, listener); } catch (OutOfMemoryError e) { e.printStackTrace(); } }
/** * @param path * @param limitMax 限制最大边 * @param quality 质量 * @return */ public static byte[] getAddBitmapByte(String path, int limitMax, int quality) { // 用于存储bitmap的字节数组 int LIMIT_MAX_MARGIN = limitMax; byte[] data = null; Bitmap localBitmap = null; try { localBitmap = revitionImageSize(path, 2 * LIMIT_MAX_MARGIN); } catch (IOException e1) { e1.printStackTrace(); } if (localBitmap != null) { int width = localBitmap.getWidth(); int height = localBitmap.getHeight(); if (width > LIMIT_MAX_MARGIN || height > LIMIT_MAX_MARGIN) { // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); // 计算宽高缩放率. float scaleWidth = 0; float scaleHeight = 0; int newWidth = 0; int newHeight = 0; if (width > height) { newWidth = LIMIT_MAX_MARGIN; newHeight = (LIMIT_MAX_MARGIN * height) / width; scaleWidth = ((float) newWidth) / width; scaleHeight = ((float) newHeight) / height; } else { newHeight = LIMIT_MAX_MARGIN; newWidth = (LIMIT_MAX_MARGIN * width) / height; scaleWidth = ((float) newWidth) / width; scaleHeight = ((float) newHeight) / height; } // 缩放图片动作 matrix.postScale(scaleWidth, scaleHeight); // 创建缩放后的图片 try { localBitmap = Bitmap.createBitmap(localBitmap, 0, 0, (int) width, (int) height, matrix, true); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); // 压缩图片质量 localBitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); data = bos.toByteArray(); try { localBitmap.recycle(); bos.close(); } catch (IOException e) { e.printStackTrace(); } } return data; }
public static void displayRoundImage(ImageView view, String path, ImageLoadingListener listener) { ImageLoader loader = ImageLoader.getInstance(); try { loader.displayImage(path, view, ROUND_DISPLAY_IMAGE_OPTIONS, listener); } catch (OutOfMemoryError e) { e.printStackTrace(); loader.clearMemoryCache(); } }
public static void safeSetImageBitmap(ImageView iv, String path) { BitmapFactory.Options op = new BitmapFactory.Options(); computeSampleSize(op, path, 512, 512 * 512); try { iv.setImageBitmap(BitmapFactory.decodeFile(path, op)); } catch (OutOfMemoryError e) { e.printStackTrace(); } }