我正在寻找一种从c#托管的GDI +库中检测 c#位图的边缘空白的解决方案.
图像可以是透明的或白色的,400x图像中的大多数是8000x8000px,边缘周围有大约2000px的空白.
找出边缘,x,y,高度和宽度坐标的最有效方法是什么?我尝试逐像素,但发现它很慢.
更新到解决方案 - 添加左/右/上/下边界
图像细节中心图像的问题现在裁剪任何透明(0%)或白色(#FFFFFF)像素.
var top = bitmap.Height;
var left = bitmap.Width;
var right = 0;
var bottom = 0;
Run Code Online (Sandbox Code Playgroud)
...
var pData = pData0 + (y * data.Stride) + (x * 4);
var xyAlpha = pData[3];
var xyBlue = pData[0];
var xyGreen = pData[1];
var xyRed = pData[2];
if ((xyAlpha > 0) || (xyRed != 255 && xyGreen != 255 && xyBlue != 255)) { …Run Code Online (Sandbox Code Playgroud) 在BlackBerry中,在内存使用和性能方面使用Bitmap类或EncodedImage会更好吗?有关使用这些课程的具体提示吗?
所有,
之后,我注意到有缓慢getPixel而setPixel有(不知道哪一个,都猜不涡轮增压)我赶紧编码的容器Bitmap,使用int[]阵列来处理位图操作.
已经 - 它明显更快,但这还不够.请问您如何进一步加快速度?
我的想法是跟踪setPixel函数"脏"的内容并仅更新调用Bitmap时的这一部分getBitmap()......不清楚如何设置setPixels参数(我猜测偏移和步幅的东西).
还 - 任何更快的食谱?
感谢您提前帮助!
import android.graphics.Bitmap;
public class DrawableBitmapContainer {
private Bitmap image;
private int width, height;
private int[] pixels;
public DrawableBitmapContainer(Bitmap _source ){
image = _source;
width = image.getWidth();
height = image.getHeight();
pixels = new int[width*height];
image.getPixels(pixels,0,width,0,0,width,height);
}
public int getPixel(int x,int y){
return pixels[x+y*width];
}
public void setPixel(int x,int y, int color){
pixels[x+y*width]=color;
}
public Bitmap …Run Code Online (Sandbox Code Playgroud) 我想在图像上显示一个点和一个文本.我已经尝试了几个关于覆盖位图的教程,但它似乎不起作用.这是显示背景图像的代码.
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.roomplan);
mIV = (ImageView)findViewById(R.id.ImageView01);
mIV.setImageBitmap(mBitmap);
mIV.invalidate();
btnDraw = (Button)findViewById(R.id.Button01);
btnDraw.setOnClickListener(this);
Run Code Online (Sandbox Code Playgroud)
然后在OnClickListener上,我定义另一个位图并绘制点和文本.
Bitmap bmOverlay = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(),
Bitmap.Config.ARGB_4444);
Canvas canvas = new Canvas(bmOverlay);
Paint paint = new Paint();
paint.setColor(Color.CYAN);
paint.setTextSize(20);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
canvas.drawText("You are here", 100, 100, paint);
canvas.drawPoint(30.0f, 50.0f, paint);
canvas.drawBitmap(bmOverlay, 0, 0, null);
Run Code Online (Sandbox Code Playgroud)
即使我删除图像,背景图像上也不会显示任何内容.有什么提示吗?
更新:工作代码
// get a reference to the background image
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.raumplan_isst);
mIV = (ImageView)findViewById(R.id.ImageView01);
// create a mutable bitmap with the same size as the background image
Bitmap bmOverlay …Run Code Online (Sandbox Code Playgroud) 我试图创建圆角矩形和背景作为重复位图.我这样写,但是在角落里得到位图.
任何人都可以帮忙吗?
background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<stroke
android:width="1dp"
android:color="#FFFFFF" />
<corners android:radius="50dp" />
</shape>
</item>
<item>
<bitmap
android:src="@drawable/carbon_4"
android:tileMode="repeat" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) **我在"thepic"变量中有位图类型的位图.
imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
String realpath=getRealPathFromURI(imageUri);
thepic = BitmapFactory.decodeFile(realpath);**
Run Code Online (Sandbox Code Playgroud) 我想改变图像某些部分的亮度.我知道如何使用ColorMatrix来改变图像的亮度(或色调).但它将应用于整个图像.
我有一个掩码文件(黑白图像).我想仅在该蒙版的白色部分应用亮度变化.如何在Android中执行此操作?
下面是一个掩码图像和我想得到的结果.

我有两个位图,我在onCreate()中创建它们.
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),id);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),id);
Run Code Online (Sandbox Code Playgroud)
bmp1和bmp2是一样的.我在我的应用程序中修改了bmp2.我的工作完成后,单击"清除"按钮.当我点击"清除"按钮时,我正在尝试将bmp1(清洁图像)复制到bmp2(已更改的图像).但我不想使用createBitmap()或copy()函数.因为这些是创建新的Bitmap对象.我只想使用我的两个位图(bmp1和bmp2).如何将bmp1复制到bmp2?我搜索谷歌,但无论如何使用createBitmap()或copy().
谢谢.
我正在使用Kinect传感器通过将视频输入设置为位图源来显示图像上的视频输入,如下所示.但我的问题是如何将图像添加到图像/位图,例如分数计数器,我在下面添加了一张图片来展示我想要实现的目标.
void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame == null) return;
byte[] colorData = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(colorData);
KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);
}
}
Run Code Online (Sandbox Code Playgroud)

我想要减少图像尺寸的功能.
该函数应该采用图像URL,检查图像是4MB大小还是更大,如果是,则将其调整为爱人然后4MB并返回字节.
我有下一个方法:
public byte[] ResizeImage(string url)
{
var uri = new Uri(url);
var c = new WebClient();
var oldImgStream = new MemoryStream(c.DownloadData(uri));
if (oldImgStream.Length <= 4194304)
{
return oldImgStream.ToArray();
}
using (var oldImage = new Bitmap(oldImgStream))
using (var newImageStream = new MemoryStream())
{
var format = oldImage.RawFormat;
float resizePercent = (float)4194304 / oldImgStream.Length;
var newImage = ResizeImageByPercent(oldImage, resizePercent);
newImage.Save(newImageStream, format);
return newImageStream.ToArray();
}
}
public static Bitmap ResizeImageByPercent(Bitmap image, float resizePercent)
{
//Set minimum resizePercentage to 80%
resizePercent = …Run Code Online (Sandbox Code Playgroud) bitmap ×10
android ×6
c# ×3
graphics ×3
image ×2
java ×2
algorithm ×1
asp.net-mvc ×1
background ×1
blackberry ×1
colorfilter ×1
colormatrix ×1
drawing ×1
imageview ×1
memorystream ×1
optimization ×1
overlay ×1
pdf ×1
performance ×1
repeat ×1
wpf ×1