Articles of bitmapfactory

在Android上将canvas保存到位图

关于将Canvas的内容放入Bitmap,我遇到了一些困难。 当我尝试这样做时,文件的文件大小约为5.80KB,但它看起来完全是空的(每个像素都是’#000’)。 canvas绘制了一系列由手写形成的相互连接的线条。 下面是我对视图的onDraw。 (我知道它阻止了UI线程/糟糕的做法/等等……但是我只需要让它工作) 谢谢。 @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); if (IsTouchDown) { // Calculate the points Path currentPath = new Path(); boolean IsFirst = true; for(Point point : currentPoints){ if(IsFirst){ IsFirst = false; currentPath.moveTo(point.x, point.y); } else { currentPath.lineTo(point.x, point.y); } } // Draw the path […]

下载外部PNG图像时丢失透明背景

我在图像视图中显示一个外部图像,通过这样下载它: bitmap = BitmapFactory.decodeStream((InputStream)new URL(url).getContent()); 然后将此位图设置为ImageView如下所示: imageView.setImageBitmap(bitmap); 除了其中一个图像是PNG并且使用BitmapFactory时我丢失透明背景外,这一切都很好。 谁能告诉我如何保持透明背景?

用于图像/ jpeg的Base64解码;在android中的base64

我试图将base64编码的字符串解码为android中的位图。 编码的字符串将以“image / jpeg; base64”开头 我使用以下方法: public static Bitmap decodeBase64(String input) { byte[] decodedByte = Base64.decode(input, Base64.DEFAULT); // also tried using Base64.URL_SAFE , Base64.NO_PADDING return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length); } 假设我将上述方法称为 ImageView get_img=(ImageView)fundViewByID(R.id.getImg); get_img.setImageBitmap(ImageCache.decodeBase64(url)) 当我运行代码时,它会抛出 — SkImageDecoder :: Factory返回null 要么 错误的base-64与IllegalArgumentException 以下是base64字符串 data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQSEhUUEhQUFRQVFBQUFBQXFxQWGBQWFxUWFhQXFRUYHSggGBwlHBQUITEhJSkrLi4uFx8zODMsNygtLisBCgoKDg0OGxAQGywmHyQsLCwsLC4sLywsLCwsLCwsLCwsLCwvLCwsLCwsLCw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RzSuL2YWCm6Ze5picp8BbmhGhBvWa8kDO0W4lUoo0xtqkW5SpOw6DpdYujDYSL75hGKjri1pizYEbZ17lFEpwUY2hQm5yplMc8yScvvdu5NNT8WWTjDe6ZKiiyeWVpdzTwY02W4tuW3i8QPGAVkr1YiYzibWOcSROsc1FEeJJNrsLw4tJ9x7W4RiIBBiD6/oipgOHVE9hy3QVFFnHPKUU3XOi5YYxk0m+QP1IOyJYRkAQQdsCAAgcI90hx2EEH0/VRRdsYI4XNidI0gs6tSROrqlU2hOQvnqHmFaizvematVG0TA7WTznxCH2rmmDHL9VFFrbVkJJoa58nqkneBBjO1kgVNQwk3tBEc1FERbYaVuEHuv1Z7QR3zlwSTWvBaZGwjzUUVW7qwik1yP/9k=

Android PNG到Bitmap – SkImageDecoder :: Factory返回null

我正在尝试从我的Environment.getExternalStorageDirectory()加载屏幕截图并尝试将其转换为位图 public void onPictureTaken(String path) throws IOException { String photoPath = filepath + “/” + path;; //UPDATE WITH YOUR OWN JPG FILE File directory = new File (filepath); File file = new File(directory, path); final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(photoPath, options); // Calculate inSampleSize options.inSampleSize = 4; options.inJustDecodeBounds = false; BitmapFactory.decodeFile(photoPath, […]

BitmapFactory返回比源更大的图像

嗨,我正在从名为image.png的png图像创建一个位图。 图像的尺寸为75(宽度)×92(高度)。 当我运行此代码时: Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.image Log.d(“image”, “height: ” + bitmap.getHeight() + ” width: ” + bitmap.getWidth()); 记录器日志: DEBUG/image(3550): height: 138 width: 113 并且屏幕上的图像比尺寸为75 x 92的其他图像大。我可以做些什么来让Android加载具有正确尺寸的图像?

BitmapFactory.decodeResource和莫名其妙的内存不足

我得到一个奇怪的Out of Memory错误解码一个可绘制的图像资源960x926px jpg,分配3555856字节。 图像仅放在drawable-xxhdpi(3x)中,我使用的是hdpi(1.5x)设备。 两个问题: 为什么我在堆中有足够的可用内存时会收到错误? 为hdpi设备分配应该是((960/2)x(926/2))x 4 = 888960字节(不是3555856)? 有人可以解释一下吗? 注意:问题是为什么在拥有22.5MB可用内存的同时获得3.5MB的OOM分配(参见日志) 03-18 17:30:15.050 32750-32750 /? D / dalvikvm:GC_FOR_ALLOC释放10809K,49%免费23735K / 46087K,暂停89ms,总计89ms 03-18 17:30:15.050 32750-32750 /? I / dalvikvm-heap:强制收集3555856字节分配的SoftReferences 03-18 17:30:15.160 32750-32750 /? D / dalvikvm:GC_BEFORE_OOM释放29K, 49%免费23705K / 46087K ,暂停103ms,总计103ms 03-18 17:30:15.160 32750-32750 /? E / dalvikvm-heap: 3555856字节分配的内存不足 。 03-18 17:30:15.160 32750-32750 /? I / […]

BitmapFactory.decodeStream无exception返回null

我尝试从服务器加载远程图像,并且由于stackoverflow上的大量代码示例,我有一个解决方案,可以在3个图像中的2个中运行。 我真的不知道第三张图片有什么问题,有时候让代码在调试器中运行时图片正在加载。 此外,如果我首先加载问题图片,有时不会加载其他两张图片。 这是代码: public static Drawable getPictureFromURL(Context ctx, String url, final int REQUIRED_SIZE) throws NullPointerException { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); int scale = 1; if (o.outWidth > REQUIRED_SIZE) { scale = (int) Math.pow(2, (int) Math.round(Math.log(REQUIRED_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } Log.i(Prototype.TAG, “scale: “+scale); //Decode with inSampleSize BitmapFactory.Options o2 […]

Android:PNG透明度失败,使用BitmapFactory.decodeStream(…)和Assets文件夹

我使用以下方法从我的Android应用程序中的assets文件夹中提取PNG文件: public static Bitmap getBitmapFromAssets(Context context, String fileName) { try { AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(fileName); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } catch(Exception ex) { ex.printStackTrace(); return null; } } 然后我在GridView的项目中将ImageView的源设置为该Bitmap。 这是有问题的布局XML: 该XML中提到的样式是: fitXY 100dp 142dp 5dp @android:color/transparent 以下是设置ImageView源代码: ImageView ivPackageIcon = (ImageView)containingView.findViewById(R.id.ivPackageIcon); if(ivPackageIcon != null) { Bitmap coverImage = getBitmapFromAssets(containingView.getContext(), […]

MediaStyle LargeIcon的大小

我正在使用新的Notification.MediaStyle类向FTP流媒体音乐播放器应用程序实现Lollipop风格的通知。 我将专辑封面设为我的“大图标”。 鉴于专辑封面直接取自当前正在播放的文件,该专辑封面的大小取决于来源(可能高达5000×5000)。 从我的棒棒糖前代码我解码位图的最大大小定义为: android.R.dimen.notification_large_icon_width 和 android.R.dimen.notification_large_icon_height 这很好,因为解码时间要快得多,内存使用也很理想。 但是,当此代码应用于我的MediaStyle样式时,展开的视图使用比尺寸参数定义的图标大得多的图标,从而在展开时产生模糊的专辑封面。 是否有一些常量来定义MediaStyle大图标的展开视图的最大大小? 或者这个问题有一些解决方法吗? 目前的情况是,艺术以全分辨率解码是不可接受的,因为它可能会导致应用程序因OOM而崩溃。

android – calculateInSampleSize,为什么当宽度>高度时Math.round处理高度(height / reqHeight)?

我正在’developer.android.com’上缩小我的位图文件,我发现了一件我不理解的事情。 所以我感谢你给我一点帮助。 这是developer.android.com的一个片段 public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = Math.round((float)height / (float)reqHeight); } […]