我正在创建一个Android应用,您可以在其中将图像从一个位置复制到另一个x位置y.复制完成后,我希望看到图片中的图片ImageView.我知道图像的位置,但无论我尝试什么,我都无法创建bitmap它的对象.
造成我问题的那条线是这样的:
BitmapFactory.decodeFile(dir+s);
Run Code Online (Sandbox Code Playgroud)
dir = getCacheDir().getAbsolutePath()+"/images/";
s = file name (eg. 1275123123.jpg)
如果我创建一个File具有相同路径的对象,并调用f.isFile()它返回true.
在android或windows中打开图像都不是问题.
我想在Linux C中使用位图API.
我需要2 ^ 18位,所以它需要32KB内存.我会经常在位图中设置和取消设置位.
所以基本上我需要API,如:
set_bitmap(int i) // it sets the i-th bit to 1 in the bitmap
unset_bitmap(int i) // it sets the i-th bit to 0 in the bitmap
bitmap_t create_bitmap(int n) // it creates a bitmap of size n, like n=2^18
Run Code Online (Sandbox Code Playgroud)
有没有源代码或类似的源代码?
谢谢!
我的问题是如何在以下情况下实现位图?
如果图的顶点在最小生成树(MST)中,则标记相应的位; 稍后通过检查位来检查它是否在MST中.
一开始,我正在考虑使用
typedef struct bit_t{
char bit0:1;
} bit;
bit bitmap[num_of_vertex];
Run Code Online (Sandbox Code Playgroud)
并使用位图数组来记录该位;
但后来我发现sizeof(位图[num_of_vertex])是num_of_vertex字节,而不是num_of_vertex/8字节.所以它不像我想象的那样节省空间;
到目前为止我用了
long bit_record = 0;
...
bit_record |= 1<< u;//set vertex as in MST
...
Run Code Online (Sandbox Code Playgroud)
然后用以下方法检查顶点是否在MST中:
static bool is_in_MST(int v, int bit_record){
int mask = 1 << v;
if (mask & bit_record)
return true;
else
return false;
}
Run Code Online (Sandbox Code Playgroud)
尽管代码有效,但如果num_of_vertex大于32,它将无法工作.
一般情况下如何实现上述情况中的位图?
我想将图像添加到gridView.我从Parse.com上提取内容.我不会在资源文件夹中有它们,所以我找不到有用的教程.这是我到目前为止的代码;
progressDialog = ProgressDialog.show(manager.this, "", "Loading images...", true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("fightGallery");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> parseObjects, com.parse.ParseException e) {
if (e == null) {
int i = 0;
final int size = parseObjects.size();
while (i < size) {
ParseFile fileObject = parseObjects.get(i).getParseFile("image");
fileObject.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
Log.d("Data", "We have data successfully");
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
ImageView img = (ImageView) findViewById(R.id.imageView);
img.setImageBitmap(bmp);
Log.d("IMAGES", …Run Code Online (Sandbox Code Playgroud) 我正在Android上使用OpenCv进行图像处理.在作为教程3的OpenCv示例中,它们使用本机代码,并且它们将帧数据从java部分发送到jni部分作为字节数组.然后他们将字节数组转换为mat.最后,他们正在处理mat变量并将其返回给show.
像这样,我想把drawable发送到jni部分.首先,我将drawable转换为位图,并将位图转换为字节数组,如下所示;
private Bitmap my_bitmap;
private byte[] process_data;
-o-
Drawable myDrawable = getResources().getDrawable(R.drawable.test);
my_bitmap = ((BitmapDrawable) myDrawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mybitmap.compress(CompressFormat.PNG, 100, stream);
process_data = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
然后我将这个字节数组发送到jni部分然后我从jni给出int数组并创建位图;
int[] rgba = mRGBA;
Test(p_width, p_height, process_data, rgba); //This is jni function
Bitmap bmp = Bitmap.createBitmap(p_width, p_height, Bitmap.Config.ARGB_8888);
bmp.setPixels(rgba, 0, p_width, 0, 0, p_width, p_height);
Run Code Online (Sandbox Code Playgroud)
但是返回的位图就像噪声一样.
这是我的c ++代码;
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_Test(JNIEnv* env, jobject thiz,
jint width, jint height, jbyteArray p_data, jintArray bgra)
{
jbyte* _p_data= env->GetByteArrayElements(p_data, 0);
jint* _bgra = …Run Code Online (Sandbox Code Playgroud) 如何在Stretch模式下显示的pictureBox中裁剪图像?
我在pictureBox中绘制一个矩形:
void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
//pictureBox1.Image.Clone();
xUp = e.X;
yUp = e.Y;
Rectangle rec = new Rectangle(xDown, yDown, Math.Abs(xUp - xDown), Math.Abs(yUp - yDown));
using (Pen pen = new Pen(Color.YellowGreen, 3))
{
pictureBox1.CreateGraphics().DrawRectangle(pen, rec);
}
rectCropArea = rec;
}
void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.Invalidate();
xDown = e.X;
yDown = e.Y;
}
Run Code Online (Sandbox Code Playgroud)
并使用以下方法裁剪所选部分:
private void btnCrop_Click(object sender, EventArgs e)
{
try
{
pictureBox3.Refresh();
//Prepare a new Bitmap on which the cropped image will be drawn
Bitmap …Run Code Online (Sandbox Code Playgroud) 我想将字符串转换为位图或我可以在像素框中显示的内容.
我的字符串看起来像这样:
string rxstring = "010010010020020020030030030040040040050050050060060060070070070080080080090090090100100100110110110120120120130130130140140140150150150160160160“
Run Code Online (Sandbox Code Playgroud)
擦除字符串中的RGB代码没有问题
("01002003004005060070080090100110120130140150160");
Run Code Online (Sandbox Code Playgroud)
我只需要它来表明,这并不重要[原文如此]
IDE:VS2010 C#
我在我的android服务中创建了一个位图对象的hahsmap,使用int作为键.为此,我根据需要添加动态创建的不同位图.我可以通过这个散列图(包括位图的大小),使用某个工具或以编程方式找到添加到我的服务的RAM /堆内存占用.
如果以前有人在这个地区工作过,请帮忙!
我有一个9补丁drawable作为XML.当我尝试使用它BitmapFactory.decode来获取位图时,它会返回null.无论如何从这个资源获取位图?
nine_patch.xml:
<?xml version="1.0" encoding="utf-8"?>
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/empty_icon_video" >
</nine-patch>
Run Code Online (Sandbox Code Playgroud)
而代码是:
BitmapFactory.decodeResource(mResources, resId);
Run Code Online (Sandbox Code Playgroud) 我不知道如何打开保存的图像并将其显示在gridView中.
我打算拍照:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null && file != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
Run Code Online (Sandbox Code Playgroud)
并且文件保存在/ data/data/package/files/...但是当我尝试打开文件并创建位图时,它总是返回null.
try {
is = this.getContentResolver().openInputStream(Uri.fromFile(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(is);}
Run Code Online (Sandbox Code Playgroud)
即使我使用decodeFile方法()我仍然有一个空位图.文件存在于data/data/...我检查了它.
我的问题是:我怎样才能得到不同的图片?