bpp =每像素位数,因此对于R/G/B/A,32bpp表示8/8/8/8.
像.NET有这些"System.Drawing.Imaging.PixelFormat"的枚举.
现在,一旦我的图形具有Bitmap或Image对象,我将如何将其保存为文件/我将使用哪种格式?
什么图像文件格式(JPEG/GIF/PNG)支持低位深度,如16bpp或8bpp (而不是通常的32bpp或24bpp)
我正在为OSX的程序员图像编辑器寻找建议.我正在寻找准备用于软件和Web应用程序的图像的东西 - 我不是平面设计师.在Windows上我会使用Paint.NET.GIMP不是答案(flakey和Spaces的灾难)
必须有
2011年6月更新:在下面尝试了各种各样的建议之后,定居在Pixelmator上,我很满意.
我正在实现一个图像缓存系统来缓存下载的图像.
我的策略基于两级缓存:内存级别和磁盘级别.
我的课程类似于droidfu项目中使用的课程
我下载的图像被放入一个hashmap,Bitmap对象被包装在一个SoftRererence对象中.此外,每个图像都永久保存到磁盘.如果未找到所请求的图像
Hashmap<String,SoftReference<Bitmap>>,则将在磁盘上搜索该图像,重新加入,然后将其推回到散列图中.否则,图像将从网络下载.由于我将图像存储到物理设备momery中,因此我添加了一个检查以保留设备空间并保持在占用空间的1M以下:
private void checkCacheUsage() {
long size = 0;
final File[] fileList = new File(mCacheDirPath).listFiles();
Arrays.sort(fileList, new Comparator<File>() {
public int compare(File f1, File f2) {
return Long.valueOf(f2.lastModified()).compareTo(
f1.lastModified());
}
});
for (File file : fileList) {
size += file.length();
if (size > MAX_DISK_CACHE_SIZE) {
file.delete();
Log.d(ImageCache.class.getSimpleName(),
"checkCacheUsage: Size exceeded " + size + "("
+ MAX_DISK_CACHE_SIZE + ") wiping older file {"+file.toString()+"}");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在磁盘写入后的某个时候调用此方法:
Random r = new Random(); …Run Code Online (Sandbox Code Playgroud) 保存文件:
FileOutputStream fo = null;
try {
fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(CompressFormat.PNG, 100, fo)
Run Code Online (Sandbox Code Playgroud)
加载文件:
String fname = this.getFilesDir().getAbsolutePath()+"/test.png";
Bitmap bMap = BitmapFactory.decodeFile(fname);
i.setImageBitmap(bMap);
Run Code Online (Sandbox Code Playgroud)
最后一行给出了空指针异常,为什么BitmapFactory.decodeFile返回null?我可以验证文件是否正确保存,因为我可以使用adb将其拉出来并看到png正确显示.
如何从内置方法getPixels为Bitmap解释返回的数组?
这是我的代码:
public void foo() {
int[] pixels;
Bitmap bitmapFoo = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.test2);
int height = bitmapFoo.getHeight();
int width = bitmapFoo.getWidth();
pixels = new int[height * width];
bitmapFoo.getPixels(pixels, 0, width, 1, 1, width - 1, height - 1);
}
Run Code Online (Sandbox Code Playgroud)
返回的数组"像素"的值从-988,602,635到1,242,635,509,这只是我在一个简单的PNG文件上的几种颜色.如何解释从此方法返回的数字?
编辑:我意识到这个整数代表一种颜色.我只是不明白如何将这个单个整数解释为构成颜色的RBG和alpha值.
谢谢.
PS.如果你问自己,"他想做什么?" 我试图找出一种动态修改位图颜色的方法.
所以我试图做一个VideoView的屏幕截图.我认为最简单的方法是:
videoView.setDrawingCacheEnabled(true);
Run Code Online (Sandbox Code Playgroud)
然后我需要截取屏幕截图:
Bitmap screenshot = videoView.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,我回来的位图每次都只是黑色.任何人都有这个成功吗?我也尝试过:
Bitmap bitmap = Bitmap.createBitmap(videoView.getWidth(), videoView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
videoView.draw(canvas);
Run Code Online (Sandbox Code Playgroud)
但是再次,这给我一个黑色的图像.我可以看到VideoView几乎没有记录在Android javadocs中.有帮助吗?
当我从图库中选择一个图像以在Android应用程序中的我的imageview上设置它时,我发现它被反转180或270或90度.
所以为了检查/解决这个我使用的EXIF方向,但它总是给我"0".
我无法得到什么问题.
码:
Uri selectedImageUri = data.getData();
absolutePath = selectedImageUri.getPath();
exifMedia = new ExifInterface(absolutePath);
String exifOrint = exifMedia.getAttribute(ExifInterface.TAG_ORIENTATION);
exifOrientation = Integer.parseInt(exifOrint);
System.out.println("Orientation Tag is:"+exifOrientation);
/** Convert URI into byte */
ContentResolver cr = getBaseContext()
.getContentResolver();
InputStream inputStream = cr
.openInputStream(selectedImageUri);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
rotatedBMP = getResizedBitmapImage(
bitmap, 100, 100,exifOrientation);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rotatedBMP.compress(Bitmap.CompressFormat.PNG, 100,
stream);
byteArray = stream.toByteArray();
mimProfileImageBrowse.setImageBitmap(rotatedBMP);
Run Code Online (Sandbox Code Playgroud)
方法:
public Bitmap getResizedBitmapImage(Bitmap bm, int newHeight, int newWidth, int exifOrientation) {
int …Run Code Online (Sandbox Code Playgroud) 我的应用程序的主要目的是以图像中所示的以下方式显示图像
private void setSelectedImage(int selectedImagePosition)
{
BitmapDrawable bd = (BitmapDrawable) drawables.get(selectedImagePosition);
Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
selectedImageView.setImageBitmap(b);
selectedImageView.setScaleType(ScaleType.FIT_XY);
}
Run Code Online (Sandbox Code Playgroud)
详细代码可以在这里找到
在以下行引发异常
Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
Run Code Online (Sandbox Code Playgroud)
以上函数调用自onItemSelected.**该应用程序仍然在2.2和2.3上运行良好,但在4.1上立即抛出异常上面的代码工作正常,但抛出异常.我没有看到2.2和2.3中的任何崩溃,但它在4.1中立即崩溃了果冻豆中的内存管理是否有任何重大差异?**:
java.lang.OutOfMemoryError
AndroidRuntime(2616): at android.graphics.Bitmap.nativeCreate(Native Method)
AndroidRuntime(2616): at android.graphics.Bitmap.createBitmap(Bitmap.java:640)
AndroidRuntime(2616): at android.graphics.Bitmap.createBitmap(Bitmap.java:586)
AndroidRuntime(2616): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:466)
AndroidRuntime(2616): at com.rdx.gallery.GalleryDemoActivity.setSelectedImage(GalleryDemoActivity.java:183)
Run Code Online (Sandbox Code Playgroud) 我是Android编程的新手.最近,我开始了一个项目,并希望为Android应用程序制作一个闪屏.按照本教程,我已阅读并成功实现了启动画面.但是,我意识到我的应用程序徽标延伸到我的屏幕之外,如下所示:
以下是我的background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/splash_background" />
<item>
<bitmap
android:gravity="center"
android:src="@drawable/tap" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我试过了
android:width="75sp"
android:height="75sp"
Run Code Online (Sandbox Code Playgroud)
在<bitmap>但它不起作用.因此,我想知道是否有办法调整图像大小(最好不使用Java代码),除了使用ImageView.任何帮助,将不胜感激!
我正在尝试创建一个由渐变构成的背景可绘制,该渐变填充整个视图,并且左重力的图案调整大小以垂直适合同时保持其纵横比.
这就是我目前拥有的:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/myGradient"/>
<item>
<bitmap android:src="@drawable/myPattern"
android:gravity="left" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
两个drawable都是VectorDrawables.
这是wrap_content高度视图的背景.
这不会调整模式的大小,而是将其垂直居中.如果我将重力设置为fill_vertical,则仅在该轴上调整大小并且宽高比会中断.
有没有办法在不使用ImageViews或其他布局的情况下在XML中实现这一点?可以以编程方式完成吗?或者我需要不同的布局?