我尝试从Bitmap(System.Drawing.Bitmap)获取所有字节值.因此我锁定字节并复制它们:
public static byte[] GetPixels(Bitmap bitmap){
if(bitmap-PixelFormat.Equals(PixelFormat.Format32.bppArgb)){
var argbData = new byte[bitmap.Width*bitmap.Height*4];
var bd = bitmap.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(bd.Scan0, argbData, 0, bitmap.Width * bitmap.Height * 4);
bitmap.UnlockBits(bd);
}
}
Run Code Online (Sandbox Code Playgroud)
我用一个非常简单的2x2 PNG图像测试了这个图像,这个图像是我在Photoshop中创建的像素(红色,绿色,蓝色,白色).由于格式,我期望argbData中的以下值:
255 255 0 0 255 0 255 0
255 0 0 255 255 255 255 255
Run Code Online (Sandbox Code Playgroud)
但我得到了:
0 0 255 255 0 255 0 255
255 0 0 255 255 255 255 255
Run Code Online (Sandbox Code Playgroud)
但这是一种BGRA格式.有人知道为什么字节似乎被交换了吗?顺便说一句,当我直接将图像用于Image.Source时,如下所示,图像显示正确.那我的错是什么?
<Image Source="D:/tmp/test2.png"/>
Run Code Online (Sandbox Code Playgroud) 每次我使用这个代码都没有画出来.我需要在指定的矩形内绘制一个位图.
canvas.drawBitmap(MyBitmap, null, rectangle, null)
Run Code Online (Sandbox Code Playgroud)
我看过网上但找不到多少帮助.
在BitmapFactory中获取异常.不确定是什么问题.(我可以猜到这个问题,但不确定为什么会发生这种情况)
ERROR/AndroidRuntime(7906): java.lang.OutOfMemoryError: bitmap size exceeds VM budget ERROR/AndroidRuntime(7906): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:295)
我的代码很简单.我定义了一个带有默认图像的XML布局.我尝试在SD卡上加载一个bm(如果存在 - 它是).如果不是,则显示默认图像.无论如何..这是代码:
public class showpicture extends Activity {
public void onCreate(Bundle savedInstanceState) {
/** Remove menu/status bar **/
requestWindowFeature(Window.FEATURE_NO_TITLE);
final Window win = getWindow();
win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Bitmap bm;
super.onCreate(savedInstanceState);
setContentView(R.layout.showpicture);
try {
ImageView mImageButton = (ImageView)findViewById(R.id.displayPicture);
bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile("/sdcard/dcim/Camera/20091018203339743.jpg"),100, 100, true);
parkImageButton.setImageBitmap(bm);
}
catch (IllegalArgumentException ex) {
Log.d("MYAPP",ex.getMessage());
}
catch (IllegalStateException ex) {
Run Code Online (Sandbox Code Playgroud)
它没有bm=Bitmap.createScaledBitmap任何想法?我在论坛上做了一些研究,它指出了这篇文章,
我只是不知道为什么它不起作用.任何帮助都会很棒!谢谢,
克里斯.
我正在编写一个应用程序,要求我采用专有的位图格式(MVTec Halcon HImage)并将其转换为C#中的System.Drawing.Bitmap.
给我的唯一专有功能是帮助我这样做,这涉及到我写入文件,除了使用"获取指针"功能.
这个功能很棒,它给了我一个指向像素数据,宽度,高度和图像类型的指针.
我的问题是,当我使用构造函数创建System.Drawing.Bitmap时:
new System.Drawing.Bitmap(width, height, stride, format, scan)
Run Code Online (Sandbox Code Playgroud)
我需要指定一个4的倍数的"步幅".这可能是一个问题,因为我不确定我的函数将被命中的大小位图.假设我最终得到一个111x111像素的位图,除了在我的图像中添加一个伪列或减去3列之外,我无法运行此功能.
有没有办法可以绕过这个限制?
如何使用PDFsharp .NET库将PDF页面导出为图像,用于像素级操作?
例如,System.Drawing.BitMap.GetPixel()之类的东西
我试图在PDF文档中找出空白区域(全白或任何颜色),以编写一些图形/图像.
2010年6月9日:
我试过这个,但它没有用.
为什么以下代码没有按预期工作?
Bitmap.GetPixel始终返回0.
//
// PdfSharp.Pdf.PdfDocument
// PdfSharp.Pdf.PdfPage
// PdfSharp.Drawing.XGraphics
// System.Drawing.Bitmap
//
string srcPDF = @"C:\hcr\test\tmp\file1.pdf";
PdfDocument pdfd = PdfReader.Open(srcPDF);
XGraphics xgfx = XGraphics.FromPdfPage(pdfd.Pages[0]);
Bitmap b = new Bitmap((int) pdfp.Width.Point, (int) pdfp.Height.Point, xgfx.Graphics);
int rgb = b.GetPixel(0, 0).ToArgb();
Run Code Online (Sandbox Code Playgroud) 编译我的应用程序时遇到问题,这是受位图等离子的启发.我在打电话
if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
return;
}
if (info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
LOGE("Bitmap format is not RGB_565 !");
return;
}
if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {
LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
}
/*****code here***********/
AndroidBitmap_unlockPixels(env, bitmap);
Run Code Online (Sandbox Code Playgroud)
我在源文件中包含了android/bitmap.h.我在ubuntu 10.10上使用android-ndk-r5b和sdk-9.
我收到了一个错误
/home/user5432/workspace/bitmapproj/obj/local/armeabi/objs-debug/mybitmap.o : In function Java_com_example_plasma_PlasmaView_renderPlasma
"undefined reference to AndroidBitmap_getInfo"
"undefined reference to AndroidBitmap_lockPixels"
"undefined reference to AndroidBitmap_unlockPixels"
Run Code Online (Sandbox Code Playgroud)
问题出在调试代码上.但是问题是什么?任何人都有答案吗?
我正在使用以下代码在C#中制作图像蒙版:
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
bmp.SetPixel(x,y,Color.White);
}
}
for(int x = left; x < width; x++)
{
for(int y = top; y < height; y++)
{
bmp.SetPixel(x,y,Color.Transparent);
}
}
Run Code Online (Sandbox Code Playgroud)
但这太慢了......与此相比,不安全的是什么?它会分配得更快吗?
最后我用PNG格式做了一个bmp.Save().
更新:
按照MusiGenesis的建议阅读http://www.bobpowell.net/lockingbits.htm后,我使用以下代码(适用于需要它的任何人)使其工作:
Bitmap bmp = new Bitmap(1000,1000,PixelFormat.Format32bppArgb);
BitmapData bmd = bmp.LockBits(new Rectangle(0, 0, bmp.Width,bmp.Height),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
int PixelSize=4;
unsafe
{
for(int y=0; y<bmd.Height; y++)
{
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<bmd.Width; x++)
{ …Run Code Online (Sandbox Code Playgroud) 我想将一个位图文件读入一个结构和manuplate它就像制作一个镜像效果等但我无法理解我应该创建哪种结构以便读入它.
谢谢您的帮助
我正在制作一个应用程序,允许用户使用android意图共享图像,但如何获取该URI
一个位图,无需将其保存到SD卡
我使用这个代码工作正常,但我不需要将此位图保存到SD卡
private Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "title", null);
return Uri.parse(path);
}
Run Code Online (Sandbox Code Playgroud)
我需要获取该URI而不将该位图保存到SD卡
更新到Studio 2.3后,当我尝试创建一个带有矢量drawable的图层列表时,它会提示使用app:srcCompat而不是android:srcin bitmap.
任何人都可以帮我添加vector drawable to layer list?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorWhite" />
<item>
<bitmap
android:gravity="center"
app:srcCompat="@drawable/login">
</bitmap>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
已经加入
vectorDrawables.useSupportLibrary = true
Run Code Online (Sandbox Code Playgroud) bitmap ×10
android ×5
c# ×3
.net ×2
android-ndk ×1
bitmapdata ×1
bitmapimage ×1
c ×1
constructor ×1
dalvik ×1
exception ×1
graphics ×1
image ×1
pdf ×1
pdfsharp ×1
structure ×1
unsafe ×1
uri ×1