我在TCP Client中收到了一个byte []数组.该数组包含一个24位RGB位图文件.如何创建具有给定宽度,高度和数据的位图文件?
在C++中我使用它
int WriteBitmapFile(const char *filename, int width, int height, unsigned char *imageData)
{
FILE *filePtr; // file pointer
BITMAPFILEHEADER bitmapFileHeader; // bitmap file header
BITMAPINFOHEADER bitmapInfoHeader; // bitmap info header
DWORD imageIdx; // used for swapping RGB->BGR
unsigned char tempRGB; // used for swapping
// open file for writing binary mode
filePtr = fopen(filename, "wb");
if (!filePtr)
return 0;
// define the bitmap file header
bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER);
bitmapFileHeader.bfType = 0x4D42;
bitmapFileHeader.bfReserved1 = 0;
bitmapFileHeader.bfReserved2 = 0; …Run Code Online (Sandbox Code Playgroud) 在Android中至少有两种缩放位图的方法,一种是在解码位图源时在"BitmapFactory.Options"中使用"inScaled,inDensity,inTargetDensity".另一种是在"Bitmap.createBitmap"中使用"Matrix".
我很好奇的是这两种方法的区别是什么?生成的位图的质量如何?内存使用情况怎么样?等等...
我正在从事计算生物学项目,我需要存储许多序列之间不同的基因座索引.现在,我正在使用B +树来实现这个目的,但我想使用位图索引对于这样一个用例会更快:两个序列之间只有少数基因座不同,平均为1%,而且它们是沿序列分布几乎相等; 所以似乎有很大的位图索引压缩空间.我的问题是我无法找到一种可以高效的压缩方法:
请提前获取您的建议.
这是我的自定义选择器(StateListDrawable)
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/common_cell_background" />
<item
android:state_pressed="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_focused="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_selected="true"
android:drawable="@drawable/common_cell_background_highlight" />
</selector>
Run Code Online (Sandbox Code Playgroud)
common_cell_background和common_cell_background_highlight都是XML.代码如下:
common_cell_background.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap"
android:tileMode="repeat"
android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)
common_cell_background_highlight.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap_highlight"
android:tileMode="repeat"
android:dither="true">
</bitmap>
Run Code Online (Sandbox Code Playgroud)
位图也完全相同.亮点只是稍微轻一点,没有其他差异.两个位图都是PNG文件.
现在我开始了
convertView.setBackgroundResource(R.drawable.list_item_background);
Run Code Online (Sandbox Code Playgroud)
这是问题所在.我的common_cell_background没有重复,它已经拉长了.但是,当我触摸列表背景的单元格时,令人惊讶的是变为common_cell_background_highlight并猜测是什么?一切都很好,它应该像它应该重复.我不知道问题出在哪里,为什么我的背景不会重复突出显示.有什么想法吗?
嗨我正在创建一个关于交通标志的应用程序 交通标志是.png格式.其中一些我在horizontalscrollview中展示.但是当试图打开活动时,我从android市场错误报告中得到了这个错误.这是我的错误报告:
<java.lang.RuntimeException: Unable to start activity ComponentInfo{com.besalti.svenskavagmarken/com.besalti.svenskavagmarken.varningsmarken}: android.view.InflateException: Binary XML file line #645: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #645: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227) …Run Code Online (Sandbox Code Playgroud) 我如何将两个不同的图像合并为一个.此外,我需要在第一个图像上的特定点合并第二个图像.它在android中是否可行?
我在这个文件中有内存泄漏,我找不到确切的位置,但我认为是周围的图像 - > (Bitmap bm = BitmapFactory.decodeFile(filename)),我尝试了很多不同的方法,但我无法让它工作.
package prod.vegs;
//All imports here but not need to write them all now :-)
public class ProductForm extends Activity {
private static int TAKE_PICTURE = 1;
private static int SELECT_PICTURE = 2;
//JSON Response node names
private static String KEY_SUCCESS = "success";
private static String ERROR_MSG = "error_msg";
private static String KEY_TYPES = "subtypes";
private static String TYPE_NAME = "name";
private static String TYPE_ID = "id_type";
private static String PRODUCT_ID = "id_product"; …Run Code Online (Sandbox Code Playgroud) 我正在开发一款游戏,用户需要点击ImageView中的图像来旋转它.在每个拍子图像上顺时针旋转90度.但是图像需要时间从旧位置旋转到新位置.这妨碍了游戏体验.我使用了以下内容:
protected void onCreate(Bundle savedInstanceState)
{
...
...
imgview = (ImageView)findViewById(R.id.imageView1);
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap myImg = getBitmapFromDrawable(imgview.getDrawable());
Bitmap rotated = Bitmap.createBitmap(myImg,0,0,myImg.getWidth(),myImg.getHeight(),matrix,true);
imgview.setImageBitmap(rotated);
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道有没有其他方法旋转图像 而不会产生任何旋转延迟.
我想在裁剪和重新调整位图大小后使用Glide将位图加载到ImageView.
我不想使用,ImageView.setImageBitmap(bitmap);因为我正在加载大量图像,它可能会占用一些内存,虽然图像尺寸很小,我只需要使用Glide,因为我知道它可以优化图像缓存.
我读了这篇文章,但是当我尝试实现它时,我并不完全理解他的解决方案.所以也许某人有一个更清洁,更容易理解的解决方案.
这是我的代码,它拾取图像并从中创建一个位图.
我需要使用滑行代替ImageView.setImageBitmap(bitmap);.
new AsyncTask<String, Void, Void>() {
Bitmap theBitmap = null;
Bitmap bm = null;
@Override
protected Void doInBackground(String... params) {
String TAG = "Error Message: ";
try {
//Load the image into bitmap
theBitmap = Glide.
with(mContext).
load("http://example.com/imageurl").
asBitmap().
into(-1, -1).
get();
//resizes the image to a smaller dimension out of the main image.
bm = Bitmap.createBitmap(theBitmap, 0, 0, 210, 80);
} catch (final ExecutionException e) {
Log.e(TAG, e.getMessage());
} …Run Code Online (Sandbox Code Playgroud) 我需要将Bitmap设置为ImageView以保持16:9的比例.你有什么建议吗?主要解决方案可能是在自定义ImageView上的覆盖方法onMeasure,但是如何?
bitmap ×10
android ×8
java ×2
matrix ×2
24-bit ×1
aspect-ratio ×1
byte ×1
c ×1
c# ×1
compression ×1
drawbitmap ×1
imageview ×1
indexing ×1
memory-leaks ×1
repeat ×1
rgb ×1
rotation ×1
scale ×1
statelist ×1
xml ×1