我正在研究用WPF编写的SEM图像处理应用程序.我有一个从Canvas派生的图像显示控件,它使用DrawingVisuals显示图像和叠加(每个"图层"一个).它还使用缩放和平移变换实现缩放和平移,应用于DrawingVisuals.
当我放大图像以查看单个像素时,它们显示为平滑,显然使用双线性过滤来拉伸位图(毫不奇怪,因为WPF是通过Direct3D渲染的).但是,对于我的用例,我宁愿将单个像素视为锐利的盒子,就像在任何像Photoshop这样的图像编辑器中一样.这就是为什么我的应用程序的用户缩放图像 - >能够在像素级别上操作.
在WPF中是否有这样的选项(除了在显示位图之前手动拉伸位图)?我找不到任何东西.
在此先感谢Zbynek Vrastil捷克共和国
我目前正在寻找一种方法来使用黑白位图来掩盖另一个位图的alpha通道或Android上的Drawable.我很好奇最好的办法是什么.我当然对如何做到这一点有几点想法,但它们并不是最优的.
我需要能够经常对图像应用新的遮罩(黑白位图每隔几秒就会改变一次).
任何有关如何实现这一目标的反馈将不胜感激.
我发现的人转换的负载BitmapSource为Bitmap约,但什么ImageSource来Bitmap?我正在制作一个成像程序,我需要从Image元素中显示的图像中提取位图.有谁知道如何做到这一点?
编辑1:
这是用于转换功能BitmapImage的Bitmap.请记住在编译器首选项中设置"unsafe"选项.
public static System.Drawing.Bitmap BitmapSourceToBitmap(BitmapSource srs)
{
System.Drawing.Bitmap btm = null;
int width = srs.PixelWidth;
int height = srs.PixelHeight;
int stride = width * ((srs.Format.BitsPerPixel + 7) / 8);
byte[] bits = new byte[height * stride];
srs.CopyPixels(bits, stride, 0);
unsafe
{
fixed (byte* pB = bits)
{
IntPtr ptr = new IntPtr(pB);
btm = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format1bppIndexed, ptr);
}
}
return btm; …Run Code Online (Sandbox Code Playgroud) 我试图修改一个Paint变量,但是不成功 - 我怎样才能使位图显示为"半透明"?
我试图将位图图像旋转90度,将其从横向格式更改为纵向格式.例:
[a,b,c,d]
[e,f,g,h]
[i,j,k,l]
顺时针旋转90度变为
[i,e,a]
[j,f,b]
[k,g,c]
[l,h,d]
使用下面的代码(来自在线示例),图像旋转90度,但保留横向纵横比,因此您最终得到一个垂直压扁的图像.难道我做错了什么?我需要使用另一种方法吗?我也愿意旋转我用来创建位图的jpeg文件,如果这更容易的话.
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(90);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOriginal, 0, 0, widthOriginal, heightOriginal, matrix, true);
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
哪个将成功在Android上启动消息应用程序.
但是,如何在启动意图时附加Bitmap对象?
我已经阅读了http://developer.android.com/reference/Android/content/Intent.html,我需要的东西就是EXTRA_STREAM,就像这样:
intent2.putExtra(Intent.EXTRA_STREAM,_uri);
但我的情况是,我有一个Bitmap对象的引用,而不是Bitmap的URI.
请告诉我如何附加Bitmap对象?
借助MediaProjectionAndroid L中提供的API,可以实现
将主屏幕的内容(默认显示)捕获到Surface对象中,然后您的应用可以通过网络发送该对象
我已经设法让VirtualDisplay工作,我SurfaceView正确显示屏幕的内容.
我想要做的是捕获显示在其中的框架Surface,并将其打印到文件.我尝试过以下内容,但我得到的只是一个黑色文件:
Bitmap bitmap = Bitmap.createBitmap
(surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
surfaceView.draw(canvas);
printBitmapToFile(bitmap);
Run Code Online (Sandbox Code Playgroud)
有关如何从中检索显示数据的任何想法Surface?
因此,作为@j__m建议,现在我的设置VirtualDisplay使用Surface的ImageReader:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
displayWidth = size.x;
displayHeight = size.y;
imageReader = ImageReader.newInstance(displayWidth, displayHeight, ImageFormat.JPEG, 5);
Run Code Online (Sandbox Code Playgroud)
然后我创建虚拟显示传递Surface到MediaProjection:
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
DisplayMetrics metrics = getResources().getDisplayMetrics();
int density = metrics.densityDpi;
mediaProjection.createVirtualDisplay("test", …Run Code Online (Sandbox Code Playgroud) 我用下面的代码用相机拍照.而不是保存我想编码它,Base64然后将其作为输入传递给另一个API.我看不到方法,如何修改代码来Base64代替常规文件拍照.
public class CameraDemoActivity extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count = 0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
File newdir = new File(dir);
newdir.mkdirs();
Button capture = (Button) findViewById(R.id.btnCapture);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
count++;
String file = dir+count+".jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
}
catch (IOException e)
{
}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent …Run Code Online (Sandbox Code Playgroud) 在android API 28中view.getDrawingCache()已被弃用.有没有更新的解决方案来生成Android中的特定视图的位图.