首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BitmapSource copyPixels正确的参数

BitmapSource copyPixels正确的参数
EN

Stack Overflow用户
提问于 2012-11-22 18:45:54
回答 1查看 2.1K关注 0票数 0

我使用stride会产生异常。输入图像为32位JPG格式。请告诉我我应该放入什么值(我尝试了很多东西,但它们在哪里产生异常或损坏的JPG):

代码语言:javascript
复制
array<System::Byte>^ pixels = gcnew array<System::Byte>(WHAT VALUE);        
bitmapSource->CopyPixels(pixels, WHAT VALUE, 0);

代码语言:javascript
复制
// Jpg.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#using <mscorlib.dll> //requires CLI
using namespace System;
using namespace System::IO;
using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Media;
using namespace System::Windows::Controls;
using namespace std;

[System::STAThread]
int _tmain(int argc, _TCHAR* argv[])
{
    // Open a Stream and decode a JPEG image
    Stream^ imageStreamSource = gcnew FileStream("C:/heart2.jpg",
        FileMode::Open, FileAccess::Read, FileShare::Read);

    JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(
        imageStreamSource, BitmapCreateOptions::PreservePixelFormat,
        BitmapCacheOption::Default);
    BitmapSource^ bitmapSource = decoder->Frames[0];//< --mamy bitmape
    // Draw the Image
    Image^ myImage = gcnew Image();

    myImage->Source = bitmapSource;
    myImage->Stretch = Stretch::None;
    myImage->Margin = System::Windows::Thickness(20);

    int width = bitmapSource->PixelWidth;
    int height = bitmapSource->PixelHeight;
    int stride = (width * bitmapSource->Format.BitsPerPixel + 31) / 32;
    array<System::Byte>^ pixels
        = gcnew array<System::Byte>(height * width * stride);
    bitmapSource->CopyPixels(pixels, stride, 0);

    int x;
    cin >> x;
    return 0;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-22 18:49:15

谷歌

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.stride.aspx

步幅是单行像素(扫描线)的宽度,向上舍入为四个字节的边界。

因此,正确的值取决于图像中每个像素的位数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13511016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档