如何从uchar缓冲区读取1位bmp到cv :: Mat

时间:2018-02-06 14:21:35

标签: c++ opencv mfc

这是一个代码,用于读取bmp文件并将其转换为ImplImage类。 而且我知道有简单的方法(ImplImage(" filepath"))。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_me_todolist);
    Intent intent = getIntent();
    student_id = intent.getStringExtra("student_id");
    student_name = intent.getStringExtra("student_name");
    createTop();
    createDetail();

}
private void createDetail() {
  final FirebaseDatabase database = FirebaseDatabase.getInstance();
  final DatabaseReference hom = database.getReference("Student").child(student_id).child("event");
  listview = findViewById(R.id.listview);
  final ArrayAdapter adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1,android.R.id.text1);
  listview.setAdapter(adapter);

  hom.addValueEventListener(new ValueEventListener() {
                                @Override
                                public void onDataChange(DataSnapshot dataSnapshot) {
                               for (DataSnapshot event : dataSnapshot.getChildren() ) {
                                        Event = event.getValue().toString();
                                        Log.e("Metodolist",Event);
                                        adapter.add(Event);
                                        adapter.notifyDataSetChanged();
                                    }

                                }
                                @Override
                                public void onCancelled(DatabaseError databaseError) {

                                }
                            });
  Log.e("MeTo list","Pass1");

  listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

       hom.addListenerForSingleValueEvent(new ValueEventListener() {
           @Override
           public void onDataChange(DataSnapshot dataSnapshot) {

Intent intent = new Intent(MeTodolist.this, MeTodolistModify.class);
               String title = dataSnapshot.child(String.valueOf(position)).getValue().toString();
               Bundle bundle = new Bundle();
               bundle.putString("title", title);
               bundle.putInt("position",position);
               bundle.putString("student_id",student_id);
               bundle.putString("student_name",student_name);
               intent.putExtras(bundle);
               startActivity(intent);
               Log.e("CHANGE",title);
           }

           @Override
           public void onCancelled(DatabaseError databaseError) {

           }
       });
      }
  });

Log.e("Metodolist","pass2");
listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
      @Override
      public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                                     final int position, long id) {
          hom.addListenerForSingleValueEvent(new ValueEventListener() {

              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
//                       String STR= event.getValue().toString();
                  adapter.getItem(position);
//                   Log.e("To do List", String.valueOf(position));
                  adapter.remove(position);
//               Log.e("GETUID",event.getUid());
                  for(position1 = position; position1<listview.getCount(); position1 ++) {
                      hom.child(Integer.toString(position1)).removeValue();
                      hom.child(Integer.toString(position1)).setValue(dataSnapshot.child(Integer.toString(position1 + 1)).getValue());
                      hom.child(Integer.toString(position1 + 1)).removeValue();
                      adapter.notifyDataSetChanged();
                  }
              }
              @Override
              public void onCancelled(DatabaseError databaseError) {
              }
          });
          return true;
      }
  });
}

我怎么能读取1位bmp图像?它适用于24位和8位。 请帮助:)

1 个答案:

答案 0 :(得分:0)

使用LR_CREATEDIBSECTION标志

打开位图文件
HBITMAP hbmp = (HBITMAP)LoadImageW(0, L"test.bmp", IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE | LR_CREATEDIBSECTION);

BITMAP bm;
GetObject(hbmp, sizeof(bm), &bm);

bm.bmBits将允许访问位。位的大小为bm.bmWidthBytes x bm.bmHeight