标签: bitmap

使用底部对齐绘制平铺位图

我想用渐变背景绘制图像.我已经创建了一个可绘制的位图资源,如下所示

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/bg"
        android:tileMode="repeat"
        android:gravity="bottom"
        />
Run Code Online (Sandbox Code Playgroud)

如您所知,定义tileMode时会忽略重力.我尝试创建自己的类,它继承自BitmapDrawable,但我无法取得成功.请帮我应用这两个属性:tileMode和gravity.

user-interface android bitmap android-layout android-bitmap

5
推荐指数
1
解决办法
378
查看次数

在图像处理后获得错误的颜色

我试图用我的图像的RGB值对一些值进行异或,保存该图像并执行后退步骤,以获得原始图像.问题是,我不知道为什么我不清楚(有一些噪音)图像.这是我的代码,下面是一张图片:

Bitmap original = new Bitmap("D:\\img\\1.jpg");
Bitmap inp_bmp = new Bitmap("D:\\img\\1.jpg");

int width = inp_bmp.Width;
int height = inp_bmp.Height;
Color pixel;

for (int y = 0; y < height; y += 1)
{
    for (int x = 0; x < width; x += 1)
    {
        pixel = inp_bmp.GetPixel(x, y);

        int a = pixel.A;
        int r = (pixel.R ^ (1000))%256;
        int g = (pixel.G ^ (185675))%256;
        int b = (pixel.B ^ (78942))%256;
        inp_bmp.SetPixel(x, y, Color.FromArgb(a, r, g, b));


    }
}

pictureBox2.Image …
Run Code Online (Sandbox Code Playgroud)

c# colors bitmap xor

5
推荐指数
1
解决办法
579
查看次数

快速将图片网址转换为位图

我需要在列表页面中显示来自api的图像列表.为此,我使用了两种方法.

第一种方法:
通过将url转换为字节数组,然后将其转换为位图.请找到以下代码..

URL imageUrl = new URL(url);
URLConnection ucon = imageUrl.openConnection();

InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);

ByteArrayBuffer baf = new ByteArrayBuffer(500);
int current = 0;
while ((current = bis.read()) != -1) {
     /* This approach slowdown the process*/
     baf.append((byte) current);
}

byte[] img_ary= baf.toByteArray();
Run Code Online (Sandbox Code Playgroud)

将字节数组转换为位图:

ByteArrayInputStream imageStream = new ByteArrayInputStream(
                    imgUrl);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
Run Code Online (Sandbox Code Playgroud)

第二种方法:
基于高度和宽度的图像缩放

private static final String TAG_iamge = "Image";
private static final int IO_BUFFER_SIZE = 4 * 1024;

public static …
Run Code Online (Sandbox Code Playgroud)

android bitmap imageview imageurl imagehandler

5
推荐指数
1
解决办法
2万
查看次数

使用位图转换JSON对象

我有一个对象,其中包含一些字符串成员和一个位图成员.

该对象保存在一个带有String键和Object作为值的映射中.

我正在使用以下代码转换地图:

String json = new Gson().toJson(aMap);
Run Code Online (Sandbox Code Playgroud)

然后提取我使用的JSON映射(传递上面的JSON字符串):

Map<String, Object> aMap;
    Gson gson = new Gson();
    aMap = gson.fromJson(jsonString, new TypeToken<Map<String, Object>>() {}.getType());
Run Code Online (Sandbox Code Playgroud)

这部分有效,但存储在对象中的位图似乎已损坏?即当我尝试将位图应用于图像视图时,我得到一个例外.

我想我可能需要单独将位图转换为JSON的字符串,但希望有一个更简单的解决方案,任何想法?

谢谢.

android json bitmap

5
推荐指数
1
解决办法
8861
查看次数

RenderScript无法正确渲染ScriptIntrinsicBlur,导致ScriptIntrinsicBlur呈现彩虹色

使用滑动android库我将图像作为位图(参见滑动文档),然后我尝试使用renderscript和ScriptIntrinsicBlur模糊位图,这是一个高斯模糊.(取自此stackoverflow帖子)

 Glide.with(getApplicationContext())
    .load(ImageUrl)
    .asBitmap()
    .into(new SimpleTarget<Bitmap>(300,200) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {

            RenderScript rs = RenderScript.create(mContext); // context = this. this referring to the activity

            final Allocation input = Allocation.createFromBitmap( rs, resource, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT );
            final Allocation output = Allocation.createTyped( rs, input.getType() );
            final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create( rs, Element.U8_4( rs ) );
            script.setRadius(8f);
            script.setInput(input);
            script.forEach(output);
            output.copyTo(resource);

            mImageView.setImageBitmap(resource); 
        }
    });
Run Code Online (Sandbox Code Playgroud)

问题是这是输出,而不是模糊的图像: 在此输入图像描述

任何帮助将非常感谢谢谢.:)

android bitmap imageview renderscript

5
推荐指数
2
解决办法
1011
查看次数

如果我不调用dispose()会发生什么?

    public void screenShot(string path)
    {
        var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                        Screen.PrimaryScreen.Bounds.Height,
                                        PixelFormat.Format32bppArgb);

        var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
        gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                    Screen.PrimaryScreen.Bounds.Y,
                                    0,
                                    0,
                                    Screen.PrimaryScreen.Bounds.Size,
                                    CopyPixelOperation.SourceCopy);

        bmpScreenshot.Save(path, ImageFormat.Png);
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码捕获我的计算机屏幕.

但今天我发现有一个名为Bitmap.Dispose()的方法.

什么时候调用Dispose()有什么区别?代码运行至关重要吗?

c# dispose bitmap

5
推荐指数
2
解决办法
4400
查看次数

如何在android中组合叠加位图和捕获的图像?

我要求我需要创建一个自定义相机,并允许用户在捕获图像时放置徽标.徽标可以放大/缩小,并可在任何地方的摄像机视图中移动.我已经编写了以下代码来执行此操作,我能够成功放大/缩小并移动徽标图像,但是当我结合使用从相机拍摄的徽标和图片时,它没有正确组合.徽标图像放置在不同的位置,它的大小减少了.请有人帮助我,因为我已经卡在这里,无法找到问题所在.我还附上了手机中的截图供参考.请检查一下.

在点击捕获按钮之前,我已将徽标移动到左下角

在此输入图像描述

点击捕获按钮后,两个图像组合如下.

在此输入图像描述

public class CustomCamera extends Activity implements OnTouchListener,
    SurfaceHolder.Callback {

private Matrix matrix = new Matrix();
private Matrix savedMatrix = new Matrix();
private static final int NONE = 0;
private static final int DRAG = 1;
private static final int ZOOM = 2;
private int mode = NONE;
private PointF start = new PointF();
private PointF mid = new PointF();
private float oldDist = 1f;
private float d = 0f;
private float newRot = 0f;
private float[] lastEvent …
Run Code Online (Sandbox Code Playgroud)

android bitmap surfaceview android-camera android-bitmap

5
推荐指数
1
解决办法
3249
查看次数

为什么fresco选择不在android 5.0或更高版本上将位图放在ashmem中

正如Git中心上的Fresco项目所说:"在Android 4.x及更低版本中,Fresco将图像放在Android内存的特殊区域.这可以让您的应用程序运行得更快 - 并且更容易遭受可怕的OutOfMemoryError."

从这个答案,我知道它使用ashmem来放置位图.

而我的问题是:为什么壁画剂量不能在Android 5.0或更高版本的ashmem中放置位图?Android是否会更改某些系统功能并将其禁用?

android memory-management bitmap fresco

5
推荐指数
1
解决办法
604
查看次数

Android拍摄截图

嗨,我试着编写一个截图的功能.我找到了一个代码,通过按钮clicklistner完美地完成它,但当我删除按钮clicklistner并尝试在oncreate中截取我获得的位图是空的.为什么会这样?

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/LinearLayout01"
>
<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="munch"
    android:id="@+id/munchscreen"
    />
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="500dp"
    android:id="@+id/screenshots"

    />
Run Code Online (Sandbox Code Playgroud)

活动:

public class MainActivity extends Activity {
    LinearLayout L1;
    ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity);


        L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
        Button but = (Button) findViewById(R.id.munchscreen);
        but.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                View v1 = L1.getRootView();
                v1.setDrawingCacheEnabled(true);
                Bitmap bm = v1.getDrawingCache();
                BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
                image = (ImageView) findViewById(R.id.screenshots);
                image.setBackgroundDrawable(bitmapDrawable);
            }
        });

    }


}
Run Code Online (Sandbox Code Playgroud)

android screenshot bitmap

5
推荐指数
1
解决办法
319
查看次数

使用ENUM作为位图,如何在C中验证

我正在为具有内存限制的嵌入式应用程序开发固件.我有一组需要在收到时处理的命令.每个命令都属于不同的"桶",每个"桶"都有一系列有效的命令号.我创建了两个ENUM,如下所示,以实现此目的.

enum
{
  BUCKET_1 = 0x100, // Range of 0x100 to 0x1FF
  BUCKET_2 = 0x200, // Range of 0x200 to 0x2FF
  BUCKET_3 = 0x300, // Range of 0x300 to 0x3FF
  ...
  ...
  BUCKET_N = 0xN00 // Range of 0xN00 to 0xNFF
} cmd_buckets;

enum 
{
  //BUCKET_1 commands
  CMD_BUCKET_1_START = BUCKET_1,
  BUCKET_1_CMD_1,
  BUCKET_1_CMD_2,
  BUCKET_1_CMD_3,
  BUCKET_1_CMD_4,
  //Add new commands above this line
  BUCKET_1_CMD_MAX,

  //BUCKET_2 commands
  CMD_BUCKET_2_START = BUCKET_2,
  BUCKET_2_CMD_1,
  BUCKET_2_CMD_2,
  BUCKET_2_CMD_3,
  //Add new commands above this line
  BUCKET_2_CMD_MAX,

  //BUCKET_3 commands
  ...
  ... …
Run Code Online (Sandbox Code Playgroud)

c embedded enums bitmap c-preprocessor

5
推荐指数
1
解决办法
185
查看次数