标签: bitmap

来自png图像的GetPixel()中的RGB值错误

这是问题:
我保存在一个位图.png 颜色说ARGB(50,210,102,70)与尺寸1 x 1 pixel.

我再次检索相同的图像并使用该GetPixel(0,0)方法,我得到的是ARGB(50,209,102,70).

检索值略有变化,RGB值略有不同但A值保持不变.

然而,当我使用255的A价值,正确的RGB返回值.

因此,使用..不到值255用于A在上述问题的结果.

这是保存位图的代码.

Bitmap bmpPut = new Bitmap(1, 1); //Also tried with 'PixelFormat.Format32bppArgb'
bmpPut.SetPixel(0, 0, Color.FromArgb(254, 220, 210, 70)); 
bmpPut.Save("1.png"); //Also tried with using 'ImageFormat.Png'
Run Code Online (Sandbox Code Playgroud)

这是获取像素颜色的代码

Bitmap bit = new Bitmap(Image.FromFile("1.png"));
MessageBox.Show("R:" + bit.GetPixel(0, 0).R.ToString() +
    "| G: " + bit.GetPixel(0, 0).G.ToString() +
    "| B: " + bit.GetPixel(0, 0).B.ToString() …
Run Code Online (Sandbox Code Playgroud)

.net c# bitmap

3
推荐指数
1
解决办法
926
查看次数

位图的LockBits()作为C#中的不同格式?

我最近在一个答案中偶然发现了一个问题,该问题是关于在C#中将位图格式转换为24位RGB:更快地复制图像以更改其PixelFormat,其中选定的答案指出以下内容:

另一种方法是在没有alpha通道的情况下锁定位,然后将内存复制到新的位图

并提供以下代码作为示例(为简便起见,已简化):

public static Bitmap RemoveAlphaChannel(Bitmap bitmap) {
    Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
    Bitmap bitmapDest = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format24bppRgb);
    BitmapData data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    BitmapData dataDest = bitmapDest.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
    int bitmapSize = data.Stride * data.Height;
    Buffer.MemoryCopy(dataDest.Scan0, data.Scan0, bitmapSize, bitmapSize);
    bitmap.UnlockBits(data);
    bitmapDest.UnlockBits(dataDest);
    return bitmapDest;
}
Run Code Online (Sandbox Code Playgroud)

让我们使用此功能将32位ARGB图像转换为24位RGB。我有以下问题:

  1. 如何将32位位图锁定为24位,为什么允许?
  2. 现在,原始位图中每个像素的RGB分量如何邻接?Alpha组件去哪儿了?步幅怎么了?
  3. 将位图的位锁定为其他格式是否会导致在后台创建位图的副本?

c# format rgb bitmap

3
推荐指数
1
解决办法
570
查看次数

bitmap.compress破坏图片质量

我正在使用一个应用程序来获取gps位置,并在位图上将其绘制为圆圈,然后将其保存以继续进行操作,因此我需要重复阅读并保存文件。但是不幸的是,当我保存文件并读取文件时,经过多次迭代后文件已损坏...!
代码:

File output = new File(tmpDirectory, "map.jpg");
    try {
        OutputStream outputStream = new FileOutputStream(output);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
        outputStream.flush();
        outputStream.close();
    } catch (Exception ex) {
        Message("error!");
    }

    directory = tmpDirectory;//updating directory to load the manipulated image
    readFile(directory + "map.jpg", false);//setting the image view new image
Run Code Online (Sandbox Code Playgroud)

包含的图像:迭代后的 图片包含的图像: 主图像

android jpeg outputstream bitmap image-compression

3
推荐指数
1
解决办法
2597
查看次数

如何暂停一个帖子?

我想画一些东西.因为GUI冻结我想在一个线程中绘制.但有时我想暂停绘图(几分钟).

Delphi的文档说暂停/恢复已经过时,但没有说明哪些功能取代了它们.

不推荐使用Suspend和Resume.Sleep和SpinWait显然是不合适的.令人惊讶的是,德尔福没有提供这样的基本属性/功能.

那么,我如何暂停/恢复一个线程?

delphi multithreading bitmap delphi-xe7

3
推荐指数
1
解决办法
1016
查看次数

setImageBitmap()不起作用

我有和ImageView,它应该填充来自Gallery的图像与此代码:

Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
            getIntent.setType("image/*");
            Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            pickIntent.setType("image/*");

            Intent chooserIntent = Intent.createChooser(getIntent, "Pick an image.");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});

            startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);
Run Code Online (Sandbox Code Playgroud)

现在,在这部分代码中一切都很好,问题出在onActivityResult(),完全在setImageBitmap()中,因为imageView没有采用Gallery中的图像.这是来自onActivityResult()的代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == PICK_IMAGE_REQUEST || resultCode == PromoUpload.RESULT_OK){

        Uri selectedImage = data.getData();
        String[] filepathColumm = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filepathColumm, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filepathColumm[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
        imagePromo.setImageBitmap(bitmap);
        pictureFlag = 1;

    } …
Run Code Online (Sandbox Code Playgroud)

android bitmap imageview

3
推荐指数
1
解决办法
6397
查看次数

Android:如何在启动画面上对齐2个图像

我想使用包含2张图像的splah屏幕:

  • 主图像必须完全居中
  • 次要图像必须位于底部和主图像之间的中心

预期的渲染是这样的: 预期的飞溅

但我没有看到如何得到这个,我的第二个图像是底部对齐的: 实际飞溅

我的泼溅的XML是:

 <?xml version="1.0" encoding="utf-8" ?>
 <layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/ComplementColor" />
                <padding 
                    android:left="0dip" 
                    android:top="0dip"
                    android:right="0dip" 
                    android:bottom="0dip" />
            </shape>
        </item>
        <item>
            <bitmap android:src="@drawable/main_logo"
               android:gravity="center" />
        </item>
        <item>
            <bitmap android:src="@drawable/secondary_logo"
               android:gravity="bottom" />
        </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

android image splash-screen bitmap android-gravity

3
推荐指数
1
解决办法
2683
查看次数

如何在Firemonkey中拉伸图像?

我想将图像调整为64*64的预定义位图,无论其当前尺寸和宽高比如何.我尝试Bitmap.ReSize但保持纵横比.我试过TImage并设置WrapMode为iwStretch.这在某种程度上起作用,因为它确实按照我想要的方式重新缩放图像,但我找不到一种方法来获取图像TImage.该Bitmap属性TImage仍包含原始位图.

有人知道如何从TImage屏幕上显示的图像中获取图像吗?或者甚至更好:指向一个能够进行这种调整和拉伸的功能?如果有,我错过了.

谢谢你的时间.

delphi image bitmap delphi-xe5

3
推荐指数
1
解决办法
1647
查看次数

Android Studio:Bitmap到ImageView错误

将Bitmap附加到ImageView时出现问题.这是我得到的错误:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: accelerometer.example.com.accgame, PID: 25897
...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
Run Code Online (Sandbox Code Playgroud)

我知道它是一个空指针异常,但我不知道为什么getResources()返回null ...这是我的构造函数类:

public SimulationView(Context context) {
    super(context);
    mXOrigin = 50;
    mYOrigin = 50;

    mHorizontalBound = 100;
    mVerticalBound = 100;

    //Sensor Manager
    sensorManager = (SensorManager)context.getSystemService(SENSOR_SERVICE);

    Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
    iBall.setImageBitmap(ball);

    mBitmap = Bitmap.createScaledBitmap(ball, BALL_SIZE, BALL_SIZE, true);
    Bitmap basket = BitmapFactory.decodeResource(getResources(), R.drawable.basket);
    mBasket = Bitmap.createScaledBitmap(basket, BASKET_SIZE, BASKET_SIZE, true);
    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inDither = true; …
Run Code Online (Sandbox Code Playgroud)

android bitmap nullpointerexception drawable imageview

3
推荐指数
1
解决办法
693
查看次数

在Android camera2下将YUV_420_888转换为位图的图像不正确

我正在尝试将YUV_420_888图像转换为来自camera2预览的位图。但是输出图像的颜色不正确。

接下来是我正在运行的用于生成位图的测试代码。仅是测试代码,因此请不要对不相关的因素进行任何代码审查,例如,位图将被回收,或者将连续创建RenderScript。该代码仅用于测试从YUV到RGB的转换,仅此而已。

其他因素是,该代码应从API 22及更高版本运行,因此使用RenderScript特定的ScriptIntrinsicYuvToRGB应该足够,而不必使用旧的手动转换,由于缺乏适当的YUV_420_888支持,因此仅在以前的Android版本中才需要使用。

由于RenderScript已经提供了专用于处理所有类型的YUV转换的ScriptIntrinsicYuvToRGB,我认为问题可能出在如何从Image对象获取YUV字节数据,但我无法弄清楚问题出在哪里。

要在Android Studio中查看输出位图,请在bitmap.recycle()中放置一个断点,因此在回收之前,可以使用“查看位图”选项在“变量调试”窗口中对其进行查看。

请让我知道是否有人可以发现转换的问题:

@Override
public void onImageAvailable(ImageReader reader)
{
    RenderScript rs = RenderScript.create(this.mContext);

    final Image image = reader.acquireLatestImage();

    final Image.Plane[] planes = image.getPlanes();
    final ByteBuffer planeY = planes[0].getBuffer();
    final ByteBuffer planeU = planes[1].getBuffer();
    final ByteBuffer planeV = planes[2].getBuffer();

    // Get the YUV planes data

    final int Yb = planeY.rewind().remaining();
    final int Ub = planeU.rewind().remaining();
    final int Vb = planeV.rewind().remaining();

    final ByteBuffer yuvData = ByteBuffer.allocateDirect(Yb + Ub + Vb);

    planeY.get(yuvData.array(), 0, Yb);
    planeU.get(yuvData.array(), Yb, …
Run Code Online (Sandbox Code Playgroud)

android bitmap yuv android-camera2

3
推荐指数
1
解决办法
1692
查看次数

何时处置物体?C#

我写了一个for-loop,在其中我声明了一个新的Image,所以我Dispose应该每次都在内部for循环中,或者一旦它完成了,那有什么区别?

这是一个明确的例子,我应该使用它:

for (int i = 0; i < 10; i++)
{
    Image imgInput = new Image();

    for (int j = 0; j < 100; j++)
    {
        // Here is a code to use my image

        Image.Dispose();
    }
}
Run Code Online (Sandbox Code Playgroud)

要么:

for (int i = 0; i < 10; i++)
{
    Image imgInput = new Image();

    for (int j = 0; j < 100; j++)
    {
        // Here is a code to use …
Run Code Online (Sandbox Code Playgroud)

c# dispose for-loop image bitmap

3
推荐指数
1
解决办法
101
查看次数