我正在为进度对话框设置一个drawable(pbarDialog)但我的问题是我想每次调整drawable的大小但是无法弄清楚如何.
这是一些代码:
Handler progressHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
// some more code
case UPDATE_PBAR:
pbarDialog.setIcon(mAppIcon);
pbarDialog.setMessage(mPbarMsg);
pbarDialog.incrementProgressBy(mIncrement+1);
break;
}
}
};
pbarDialog.show();
Thread myThread = new Thread(new Runnable() {
public void run() {
// some code
for (int i = 0; i < mApps.size(); i++) {
mAppIcon = mAdapter.getIcons().get(mApps.get(i).getPackageName());
// need to resize drawable here
progressHandler.sendEmptyMessage(UPDATE_PBAR);
}
handler.sendEmptyMessage(DISMISS_PBAR);
}
});
myThread.start();
Run Code Online (Sandbox Code Playgroud) 我有两个视图(Textview&ImageView)FrameLayout,我想用文本保存图像.为此,我将View转换为位图.
我的xml是:
<FrameLayout
android:id="@+id/framelayout"
android:layout_marginTop="30dip"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageView
android:id="@+id/ImageView01"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView android:id="@+id/text_view"
android:layout_marginTop="30dip"
android:layout_width="wrap_content"
android:maxLines="20"
android:scrollbars="vertical"
android:layout_height="wrap_content"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序并在运行Android 2.2的设备上进行测试.在我的代码,我使用,我检索使用BitmapFactory.decodeResource位图的,我能够通过调用进行更改bitmap.setPixels()就可以了.当我在运行Android 1.6的朋友的设备上测试时,我IllegalStateException接到了电话bitmap.setPixels.在线文档说,IllegalStateException当位图不可变时,会抛出此方法.文档没有说明decodeResource返回不可变位图,但显然必须如此.
是否有不同的呼叫我可以从一个应用程序资源可靠地获得一个可变的位图,而不需要第二个Bitmap对象(我可以创建一个可变的一个同样大小并绘制成帆布包裹它,但这需要两个大小相等的位图使用的内存是我预期的两倍)?
我想将我的位图图像大小减少到最大640px.例如,我有大小为1200 x 1200像素的位图图像.如何将其缩小为640像素.
我想Bitmap从ImageView.我使用了以下代码,但getDrawable()返回null.如何让整个Bitmap从ImageView.
Bitmap bitmap;
if (mImageViewer.getDrawable() instanceof BitmapDrawable) {
bitmap = ((BitmapDrawable) mImageViewer.getDrawable()).getBitmap();
} else {
Drawable d = mImageViewer.getDrawable();
bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
d.draw(canvas);
}
storeImage(bitmap,"final.jpeg");
Run Code Online (Sandbox Code Playgroud) API 26 添加了新选项 Bitmap.Config.HARDWARE:
特殊配置,当位图仅存储在图形内存中时.此配置中的位图始终是不可变的.对于具有位图的唯一操作是在屏幕上绘制它的情况,它是最佳的.
文档中未解释的问题:
Bitmap.Config.HARDWARE在
Bitmap.Config.RGB_565当速度是重中之重,质量和可变性都没有(如缩略图等)?OutOfMemoryException在处理图像时,这似乎最终会令人担忧.OutOfMemoryException:)?我有一堆图片网址.我必须下载这些图像并逐个显示在我的应用程序中.我正在使用SoftReferences和使用Sdcard 保存集合中的图像,以避免重新获取并改善用户体验.
问题是我对位图的大小一无所知.事实证明,当我使用BitmapFactory.decodeStream(InputStream)方法时,偶尔会出现OutOfMemoryExceptions .因此,我选择使用BitmapFactory Options(样本大小= 2)对图像进行下采样.这提供了更好的输出:没有OOM,但这会影响较小图像的质量.
我该如何处理这类案件?有没有办法选择性地仅对高分辨率图像进行下采样?
我有一个位图:
Bitmap bitmap = BitmapFactory.decodeFile("some/arbitrary/path/image.jpg");
Run Code Online (Sandbox Code Playgroud)
但我不打算向用户显示图像.我希望alpha为100(满分为255).如果这不可能,我可以设置不透明度Bitmap吗?
如果我尝试创建一个大于19000像素的位图,我会收到错误:参数无效.我该如何解决这个问题?
System.Drawing.Bitmap myimage= new System.Drawing.Bitmap(20000, 20000);
Run Code Online (Sandbox Code Playgroud) 嗨,我有一个Base64格式的字符串.我想将它转换为位图,然后将其显示到ImageView.这是代码:
ImageView user_image;
Person person_object;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_profile_screen);
// ImageViews
user_image = (ImageView) findViewById(R.id.userImageProfile);
Bundle data = getIntent().getExtras();
person_object = data.getParcelable("person_object");
// getPhoto() function returns a Base64 String
byte[] decodedString = Base64.decode(person_object.getPhoto(), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
user_image.setImageBitmap(decodedByte);
}
Run Code Online (Sandbox Code Playgroud)
此代码成功获取Base64字符串,我没有收到任何错误.但它不显示图像.可能是什么问题?谢谢
bitmap ×10
android ×9
java ×5
image ×2
imageview ×2
performance ×2
alpha ×1
c# ×1
compression ×1
drawable ×1
opacity ×1
parameters ×1
resize ×1
size ×1